BigW Consortium Gitlab
Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
gitlab-ce
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Forest Godfrey
gitlab-ce
Commits
c9fcae8e
Commit
c9fcae8e
authored
Feb 21, 2017
by
Rémy Coutable
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'hash-concurrent-foreign-key-names' into 'master'
Hash concurrent foreign key names similar to Rails See merge request !9415
parents
2d2ed828
79696f5b
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
20 additions
and
1 deletion
+20
-1
migration_helpers.rb
lib/gitlab/database/migration_helpers.rb
+10
-1
migration_helpers_spec.rb
spec/lib/gitlab/database/migration_helpers_spec.rb
+10
-0
No files found.
lib/gitlab/database/migration_helpers.rb
View file @
c9fcae8e
...
@@ -54,7 +54,7 @@ module Gitlab
...
@@ -54,7 +54,7 @@ module Gitlab
disable_statement_timeout
disable_statement_timeout
key_name
=
"fk_
#{
source
}
_
#{
target
}
_
#{
column
}
"
key_name
=
concurrent_foreign_key_name
(
source
,
column
)
# Using NOT VALID allows us to create a key without immediately
# Using NOT VALID allows us to create a key without immediately
# validating it. This means we keep the ALTER TABLE lock only for a
# validating it. This means we keep the ALTER TABLE lock only for a
...
@@ -74,6 +74,15 @@ module Gitlab
...
@@ -74,6 +74,15 @@ module Gitlab
execute
(
"ALTER TABLE
#{
source
}
VALIDATE CONSTRAINT
#{
key_name
}
;"
)
execute
(
"ALTER TABLE
#{
source
}
VALIDATE CONSTRAINT
#{
key_name
}
;"
)
end
end
# Returns the name for a concurrent foreign key.
#
# PostgreSQL constraint names have a limit of 63 bytes. The logic used
# here is based on Rails' foreign_key_name() method, which unfortunately
# is private so we can't rely on it directly.
def
concurrent_foreign_key_name
(
table
,
column
)
"fk_
#{
Digest
::
SHA256
.
hexdigest
(
"
#{
table
}
_
#{
column
}
_fk"
).
first
(
10
)
}
"
end
# Long-running migrations may take more than the timeout allowed by
# Long-running migrations may take more than the timeout allowed by
# the database. Disable the session's statement timeout to ensure
# the database. Disable the session's statement timeout to ensure
# migrations don't get killed prematurely. (PostgreSQL only)
# migrations don't get killed prematurely. (PostgreSQL only)
...
...
spec/lib/gitlab/database/migration_helpers_spec.rb
View file @
c9fcae8e
...
@@ -101,6 +101,16 @@ describe Gitlab::Database::MigrationHelpers, lib: true do
...
@@ -101,6 +101,16 @@ describe Gitlab::Database::MigrationHelpers, lib: true do
end
end
end
end
describe
'#concurrent_foreign_key_name'
do
it
'returns the name for a foreign key'
do
name
=
model
.
concurrent_foreign_key_name
(
:this_is_a_very_long_table_name
,
:with_a_very_long_column_name
)
expect
(
name
).
to
be_an_instance_of
(
String
)
expect
(
name
.
length
).
to
eq
(
13
)
end
end
describe
'#disable_statement_timeout'
do
describe
'#disable_statement_timeout'
do
context
'using PostgreSQL'
do
context
'using PostgreSQL'
do
it
'disables statement timeouts'
do
it
'disables statement timeouts'
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