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
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
gitlab-ce
Commits
92642031
Commit
92642031
authored
Jun 06, 2016
by
Felipe Artur
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
change add_concurrent_index function arguments
parent
8450fe30
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
13 additions
and
10 deletions
+13
-10
lib/gitlab/database/migration_helpers.rb
lib/gitlab/database/migration_helpers.rb
+3
-7
spec/lib/gitlab/database/migration_helpers_spec.rb
spec/lib/gitlab/database/migration_helpers_spec.rb
+10
-3
No files found.
lib/gitlab/database/migration_helpers.rb
View file @
92642031
...
@@ -11,7 +11,7 @@ module Gitlab
...
@@ -11,7 +11,7 @@ module Gitlab
# add_concurrent_index :users, :some_column
# add_concurrent_index :users, :some_column
#
#
# See Rails' `add_index` for more info on the available arguments.
# See Rails' `add_index` for more info on the available arguments.
def
add_concurrent_index
(
*
args
)
def
add_concurrent_index
(
table_name
,
column_name
,
options
=
{}
)
if
transaction_open?
if
transaction_open?
raise
'add_concurrent_index can not be run inside a transaction, '
\
raise
'add_concurrent_index can not be run inside a transaction, '
\
'you can disable transactions by calling disable_ddl_transaction! '
\
'you can disable transactions by calling disable_ddl_transaction! '
\
...
@@ -19,14 +19,10 @@ module Gitlab
...
@@ -19,14 +19,10 @@ module Gitlab
end
end
if
Database
.
postgresql?
if
Database
.
postgresql?
if
args
[
2
].
present?
options
=
options
.
merge
({
algorithm: :concurrently
})
args
[
2
].
merge!
({
algorithm: :concurrently
})
else
args
<<
{
algorithm: :concurrently
}
end
end
end
add_index
(
*
arg
s
)
add_index
(
table_name
,
column_name
,
option
s
)
end
end
# Updates the value of a column in batches.
# Updates the value of a column in batches.
...
...
spec/lib/gitlab/database/migration_helpers_spec.rb
View file @
92642031
...
@@ -16,14 +16,21 @@ describe Gitlab::Database::MigrationHelpers, lib: true do
...
@@ -16,14 +16,21 @@ describe Gitlab::Database::MigrationHelpers, lib: true do
end
end
context
'using PostgreSQL'
do
context
'using PostgreSQL'
do
it
'creates the index concurrently'
do
before
{
expect
(
Gitlab
::
Database
).
to
receive
(
:postgresql?
).
and_return
(
true
)
}
expect
(
Gitlab
::
Database
).
to
receive
(
:postgresql?
).
and_return
(
true
)
it
'creates the index concurrently'
do
expect
(
model
).
to
receive
(
:add_index
).
expect
(
model
).
to
receive
(
:add_index
).
with
(
:users
,
:foo
,
algorithm: :concurrently
)
with
(
:users
,
:foo
,
algorithm: :concurrently
)
model
.
add_concurrent_index
(
:users
,
:foo
)
model
.
add_concurrent_index
(
:users
,
:foo
)
end
end
it
'creates unique index concurrently'
do
expect
(
model
).
to
receive
(
:add_index
).
with
(
:users
,
:foo
,
{
algorithm: :concurrently
,
unique:
true
})
model
.
add_concurrent_index
(
:users
,
:foo
,
unique:
true
)
end
end
end
context
'using MySQL'
do
context
'using MySQL'
do
...
@@ -31,7 +38,7 @@ describe Gitlab::Database::MigrationHelpers, lib: true do
...
@@ -31,7 +38,7 @@ describe Gitlab::Database::MigrationHelpers, lib: true do
expect
(
Gitlab
::
Database
).
to
receive
(
:postgresql?
).
and_return
(
false
)
expect
(
Gitlab
::
Database
).
to
receive
(
:postgresql?
).
and_return
(
false
)
expect
(
model
).
to
receive
(
:add_index
).
expect
(
model
).
to
receive
(
:add_index
).
with
(
:users
,
:foo
)
with
(
:users
,
:foo
,
{}
)
model
.
add_concurrent_index
(
:users
,
:foo
)
model
.
add_concurrent_index
(
:users
,
:foo
)
end
end
...
...
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