Skip to content

Remove foreign key constraint on `project_pages_metadata.ci_job_artifacts` to use loose foreign key

What does this MR do and why?

We want to remove the whole column per #348929 (closed), however, the constraint is the only thing we need to do for ci-decomposition and we've already turned this into a loose foreign key so we can safely just drop the constraint.

According to https://docs.gitlab.com/ee/development/avoiding_downtime_in_migrations.html#removing-foreign-keys we can remove a foreign key in 1 step.

Screenshots or screen recordings

Database migrations

Up

== 20211217050753 RemoveArtifactsArchiveIdForeignKeyFromProjectPagesMetadata: migrating 
-- transaction_open?()
   -> 0.0000s
-- execute("lock table ci_job_artifacts, project_pages_metadata in access exclusive mode")
   -> 0.0008s
-- remove_foreign_key(:project_pages_metadata, {:to_table=>:ci_job_artifacts, :column=>:artifacts_archive_id, :on_delete=>:nullify, :name=>"fk_69366a119e"})
   -> 0.0049s
== 20211217050753 RemoveArtifactsArchiveIdForeignKeyFromProjectPagesMetadata: migrated (0.0123s)  

Down

== 20211217050753 RemoveArtifactsArchiveIdForeignKeyFromProjectPagesMetadata: reverting 
-- transaction_open?()
   -> 0.0000s
-- foreign_keys(:project_pages_metadata)
   -> 0.0030s
-- transaction_open?()
   -> 0.0000s
-- execute("ALTER TABLE project_pages_metadata\nADD CONSTRAINT fk_69366a119e\nFOREIGN KEY (artifacts_archive_id)\nREFERENCES ci_job_artifacts (id)\nON DELETE SET NULL\nNOT VALID;\n")
   -> 0.0020s
-- execute("ALTER TABLE project_pages_metadata VALIDATE CONSTRAINT fk_69366a119e;")
   -> 0.0044s
== 20211217050753 RemoveArtifactsArchiveIdForeignKeyFromProjectPagesMetadata: reverted (0.0164s) 

How to set up and validate locally

Numbered steps to set up and validate the change are strongly suggested.

MR acceptance checklist

This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.

Closes #348273 (closed)

Edited by Dylan Griffith

Merge request reports