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
1
Merge Requests
1
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
nexedi
gitlab-ce
Commits
d1dc96a6
Commit
d1dc96a6
authored
Sep 08, 2021
by
Andreas Brandl
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Assert no transaction when removing constraints
parent
bf4c2242
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
11 additions
and
5 deletions
+11
-5
lib/gitlab/database/migration_helpers.rb
lib/gitlab/database/migration_helpers.rb
+7
-5
spec/lib/gitlab/database/migration_helpers_spec.rb
spec/lib/gitlab/database/migration_helpers_spec.rb
+4
-0
No files found.
lib/gitlab/database/migration_helpers.rb
View file @
d1dc96a6
...
...
@@ -1379,13 +1379,11 @@ into similar problems in the future (e.g. when new tables are created).
# validate - Whether to validate the constraint in this call
#
def
add_check_constraint
(
table
,
check
,
constraint_name
,
validate:
true
)
validate_check_constraint_name!
(
constraint_name
)
# Transactions would result in ALTER TABLE locks being held for the
# duration of the transaction, defeating the purpose of this method.
if
transaction_open?
raise
'add_check_constraint can not be run inside a transaction'
end
validate_not_in_transaction!
(
:add_check_constraint
)
validate_check_constraint_name!
(
constraint_name
)
if
check_constraint_exists?
(
table
,
constraint_name
)
warning_message
=
<<~
MESSAGE
...
...
@@ -1430,6 +1428,10 @@ into similar problems in the future (e.g. when new tables are created).
end
def
remove_check_constraint
(
table
,
constraint_name
)
# This is technically not necessary, but aligned with add_check_constraint
# and allows us to continue use with_lock_retries here
validate_not_in_transaction!
(
:remove_check_constraint
)
validate_check_constraint_name!
(
constraint_name
)
# DROP CONSTRAINT requires an EXCLUSIVE lock
...
...
spec/lib/gitlab/database/migration_helpers_spec.rb
View file @
d1dc96a6
...
...
@@ -2692,6 +2692,10 @@ RSpec.describe Gitlab::Database::MigrationHelpers do
end
describe
'#remove_check_constraint'
do
before
do
allow
(
model
).
to
receive
(
:transaction_open?
).
and_return
(
false
)
end
it
'removes the constraint'
do
drop_sql
=
/ALTER TABLE test_table\s+DROP CONSTRAINT IF EXISTS check_name/
...
...
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