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
4946aa8c
Commit
4946aa8c
authored
Jan 04, 2022
by
Dylan Griffith
Committed by
Achilleas Pipinellis
Jan 04, 2022
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add migration docs about removing a foreign key
parent
424b9fe6
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
26 additions
and
0 deletions
+26
-0
doc/development/migration_style_guide.md
doc/development/migration_style_guide.md
+26
-0
No files found.
doc/development/migration_style_guide.md
View file @
4946aa8c
...
...
@@ -772,6 +772,32 @@ to run on a large table, as long as it is only updating a small subset of the
rows in the table, but do not ignore that without validating on the GitLab.com
staging environment - or asking someone else to do so for you - beforehand.
## Removing a foreign key constraint
When removing a foreign key constraint, we need to acquire a lock on both tables
that are related to the foreign key. For tables with heavy write patterns, it's a good
idea to use
`with_lock_retries`
, otherwise you might fail to acquire a lock in time.
You might also run into deadlocks when acquiring a lock, because ordinarily
the application writes in
`parent,child`
order. However, removing a foreign
key acquires the lock in
`child,parent`
order. To resolve this, you can
explicitly acquire the lock in
`parent,child`
, for example:
```
ruby
disable_ddl_transaction!
def
up
with_lock_retries
do
execute
(
'lock table ci_pipelines, ci_builds in access exclusive mode'
)
remove_foreign_key
:ci_builds
,
to_table: :ci_pipelines
,
column: :pipeline_id
,
on_delete: :cascade
,
name:
'the_fk_name'
end
end
def
down
add_concurrent_foreign_key
:ci_builds
,
:ci_pipelines
,
column: :pipeline_id
,
on_delete: :cascade
,
name:
'the_fk_name'
end
```
## Dropping a database table
Dropping a database table is uncommon, and the
`drop_table`
method
...
...
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