Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Jérome Perrin
gitlab-ce
Commits
eb21f932
Commit
eb21f932
authored
May 25, 2017
by
Nick Thomas
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Only use DROP INDEX CONCURRENTLY on postgreql 9.2+
parent
6ece9792
Changes
6
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
49 additions
and
17 deletions
+49
-17
.gitlab-ci.yml
.gitlab-ci.yml
+1
-1
db/migrate/20170317203554_index_routes_path_for_like.rb
db/migrate/20170317203554_index_routes_path_for_like.rb
+2
-3
db/migrate/20170402231018_remove_index_for_users_current_sign_in_at.rb
...170402231018_remove_index_for_users_current_sign_in_at.rb
+1
-7
db/migrate/20170503185032_index_redirect_routes_path_for_like.rb
...ate/20170503185032_index_redirect_routes_path_for_like.rb
+2
-3
lib/gitlab/database/migration_helpers.rb
lib/gitlab/database/migration_helpers.rb
+34
-1
spec/lib/gitlab/database/migration_helpers_spec.rb
spec/lib/gitlab/database/migration_helpers_spec.rb
+9
-2
No files found.
.gitlab-ci.yml
View file @
eb21f932
...
...
@@ -52,7 +52,7 @@ stages:
.use-pg
:
&use-pg
services
:
-
postgres:9.
2
-
postgres:9.
1
-
redis:alpine
.use-mysql
:
&use-mysql
...
...
db/migrate/20170317203554_index_routes_path_for_like.rb
View file @
eb21f932
...
...
@@ -21,9 +21,8 @@ class IndexRoutesPathForLike < ActiveRecord::Migration
def
down
return
unless
Gitlab
::
Database
.
postgresql?
return
unless
index_exists?
(
:routes
,
:path
,
name:
INDEX_NAME
)
if
index_exists?
(
:routes
,
:path
,
name:
INDEX_NAME
)
execute
(
"DROP INDEX CONCURRENTLY
#{
INDEX_NAME
}
;"
)
end
remove_concurrent_index_by_name
(
:routes
,
INDEX_NAME
)
end
end
db/migrate/20170402231018_remove_index_for_users_current_sign_in_at.rb
View file @
eb21f932
...
...
@@ -11,14 +11,8 @@ class RemoveIndexForUsersCurrentSignInAt < ActiveRecord::Migration
disable_ddl_transaction!
def
up
if
index_exists?
:users
,
:current_sign_in_at
if
Gitlab
::
Database
.
postgresql?
execute
'DROP INDEX CONCURRENTLY index_users_on_current_sign_in_at;'
else
remove_concurrent_index
:users
,
:current_sign_in_at
end
end
end
def
down
add_concurrent_index
:users
,
:current_sign_in_at
...
...
db/migrate/20170503185032_index_redirect_routes_path_for_like.rb
View file @
eb21f932
...
...
@@ -21,9 +21,8 @@ class IndexRedirectRoutesPathForLike < ActiveRecord::Migration
def
down
return
unless
Gitlab
::
Database
.
postgresql?
return
unless
index_exists?
(
:redirect_routes
,
:path
,
name:
INDEX_NAME
)
if
index_exists?
(
:redirect_routes
,
:path
,
name:
INDEX_NAME
)
execute
(
"DROP INDEX CONCURRENTLY
#{
INDEX_NAME
}
;"
)
end
remove_concurrent_index_by_name
(
:redirect_routes
,
INDEX_NAME
)
end
end
lib/gitlab/database/migration_helpers.rb
View file @
eb21f932
...
...
@@ -42,7 +42,7 @@ module Gitlab
'in the body of your migration class'
end
if
Database
.
postgresql
?
if
supports_drop_index_concurrently
?
options
=
options
.
merge
({
algorithm: :concurrently
})
disable_statement_timeout
end
...
...
@@ -50,6 +50,39 @@ module Gitlab
remove_index
(
table_name
,
options
.
merge
({
column:
column_name
}))
end
# Removes an existing index, concurrently when supported
#
# On PostgreSQL this method removes an index concurrently.
#
# Example:
#
# remove_concurrent_index :users, "index_X_by_Y"
#
# See Rails' `remove_index` for more info on the available arguments.
def
remove_concurrent_index_by_name
(
table_name
,
index_name
,
options
=
{})
if
transaction_open?
raise
'remove_concurrent_index_by_name can not be run inside a transaction, '
\
'you can disable transactions by calling disable_ddl_transaction! '
\
'in the body of your migration class'
end
if
supports_drop_index_concurrently?
options
=
options
.
merge
({
algorithm: :concurrently
})
disable_statement_timeout
end
remove_index
(
table_name
,
options
.
merge
({
name:
index_name
}))
end
# Only available on Postgresql >= 9.2
def
supports_drop_index_concurrently?
return
false
unless
Database
.
postgresql?
version
=
select_one
(
"SELECT current_setting('server_version_num') AS v"
)[
'v'
].
to_i
version
>=
90200
end
# Adds a foreign key with only minimal locking on the tables involved.
#
# This method only requires minimal locking when using PostgreSQL. When
...
...
spec/lib/gitlab/database/migration_helpers_spec.rb
View file @
eb21f932
...
...
@@ -66,16 +66,23 @@ describe Gitlab::Database::MigrationHelpers, lib: true do
context
'using PostgreSQL'
do
before
do
allow
(
Gitlab
::
Database
).
to
receive
(
:postgresql
?
).
and_return
(
true
)
allow
(
model
).
to
receive
(
:supports_drop_index_concurrently
?
).
and_return
(
true
)
allow
(
model
).
to
receive
(
:disable_statement_timeout
)
end
it
'removes the index concurrently'
do
it
'removes the index concurrently
by column name
'
do
expect
(
model
).
to
receive
(
:remove_index
).
with
(
:users
,
{
algorithm: :concurrently
,
column: :foo
})
model
.
remove_concurrent_index
(
:users
,
:foo
)
end
it
'removes the index concurrently by index name'
do
expect
(
model
).
to
receive
(
:remove_index
).
with
(
:users
,
{
algorithm: :concurrently
,
name:
"index_x_by_y"
})
model
.
remove_concurrent_index_by_name
(
:users
,
"index_x_by_y"
)
end
end
context
'using MySQL'
do
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment