Commit 82f6db8b authored by Adam Hegyi's avatar Adam Hegyi

Merge branch 'clarify-loose-foreign-key-post-deployment' into 'master'

Clarify post-deployment migration for loose foreign key process

See merge request gitlab-org/gitlab!77542
parents f1845fb0 82dcb0a8
...@@ -89,9 +89,10 @@ ci_pipelines: ...@@ -89,9 +89,10 @@ ci_pipelines:
### Track record changes ### Track record changes
To know about deletions in the `projects` table, configure a `DELETE` trigger using a database To know about deletions in the `projects` table, configure a `DELETE` trigger
migration (post-migration). The trigger needs to be configured only once. If the model already has using a [post-deployment migration](../post_deployment_migrations.md). The
at least one `loose_foreign_key` definition, then this step can be skipped: trigger needs to be configured only once. If the model already has at least one
`loose_foreign_key` definition, then this step can be skipped:
```ruby ```ruby
class TrackProjectRecordChanges < Gitlab::Database::Migration[1.0] class TrackProjectRecordChanges < Gitlab::Database::Migration[1.0]
...@@ -122,15 +123,20 @@ REFERENCES projects(id) ...@@ -122,15 +123,20 @@ REFERENCES projects(id)
ON DELETE CASCADE; ON DELETE CASCADE;
``` ```
The migration should run after the `DELETE` trigger is installed. If the foreign key is deleted The migration must run after the `DELETE` trigger is installed and the loose
earlier, there is a good chance of introducing data inconsistency which needs manual cleanup: foreign key definition is deployed. As such, it must be a [post-deployment
migration](../post_deployment_migrations.md) dated after the migration for the
trigger. If the foreign key is deleted earlier, there is a good chance of
introducing data inconsistency which needs manual cleanup:
```ruby ```ruby
class RemoveProjectsCiPipelineFk < Gitlab::Database::Migration[1.0] class RemoveProjectsCiPipelineFk < Gitlab::Database::Migration[1.0]
enable_lock_retries! disable_ddl_transaction!
def up def up
remove_foreign_key_if_exists(:ci_pipelines, :projects, name: "fk_86635dbd80") with_lock_retries do
remove_foreign_key_if_exists(:ci_pipelines, :projects, name: "fk_86635dbd80")
end
end end
def down def down
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment