Remove pipeline foreign keys from package tables
🌻 What does this MR do and why?
In the effort to separate the ci_* database, we are removing all foreign keys that between ci_* tables and non ci_* tables. #338861 (closed) focuses on these efforts as related to the package stage.
In this MR we remove two foreign keys from packages_build_infos
and packages_package_file_build_infos
. We add a dependent: :nullify
constraint to the Ci::Pipeline
to preserve the behavior of the foreign keys being deleted.
:disk Database
== 20210917153645 RemovePipelineFkFromPackagesBuildInfos: migrating ===========
-- transaction_open?()
-> 0.0000s
-- foreign_keys(:packages_build_infos)
-> 0.0060s
-- remove_foreign_key(:packages_build_infos, :ci_pipelines)
-> 0.0078s
== 20210917153645 RemovePipelineFkFromPackagesBuildInfos: migrated (0.0500s) ==
== 20210917153905 RemovePipelineFkFromPackagesPackageFileBuildInfos: migrating
-- transaction_open?()
-> 0.0000s
-- foreign_keys(:packages_package_file_build_infos)
-> 0.0031s
-- remove_foreign_key(:packages_package_file_build_infos, :ci_pipelines)
-> 0.0054s
== 20210917153905 RemovePipelineFkFromPackagesPackageFileBuildInfos: migrated (0.0156s)
== 20210917153905 RemovePipelineFkFromPackagesPackageFileBuildInfos: reverting
-- transaction_open?()
-> 0.0000s
-- foreign_keys(:packages_package_file_build_infos)
-> 0.0057s
-- transaction_open?()
-> 0.0000s
-- execute("ALTER TABLE packages_package_file_build_infos\nADD CONSTRAINT fk_3e3f630188\nFOREIGN KEY (pipeline_id)\nREFERENCES ci_pipelines (id)\nON DELETE SET NULL\nNOT VALID;\n")
-> 0.0026s
-- execute("SET statement_timeout TO 0")
-> 0.0010s
-- execute("ALTER TABLE packages_package_file_build_infos VALIDATE CONSTRAINT fk_3e3f630188;")
-> 0.0070s
-- execute("RESET statement_timeout")
-> 0.0007s
== 20210917153905 RemovePipelineFkFromPackagesPackageFileBuildInfos: reverted (0.0502s)
== 20210917153645 RemovePipelineFkFromPackagesBuildInfos: reverting ===========
-- transaction_open?()
-> 0.0000s
-- foreign_keys(:packages_build_infos)
-> 0.0030s
-- transaction_open?()
-> 0.0000s
-- execute("ALTER TABLE packages_build_infos\nADD CONSTRAINT fk_17a9a0dffc\nFOREIGN KEY (pipeline_id)\nREFERENCES ci_pipelines (id)\nON DELETE SET NULL\nNOT VALID;\n")
-> 0.0013s
-- execute("ALTER TABLE packages_build_infos VALIDATE CONSTRAINT fk_17a9a0dffc;")
-> 0.0023s
== 20210917153645 RemovePipelineFkFromPackagesBuildInfos: reverted (0.0119s) ==
🎞 Screenshots or screen recordings
See section below (these commands are directly from my rails console).
✏ How to set up and validate locally
-
Run the migrations
-
Create a package build info object:
Packages::BuildInfo.create(package: Packages::Package.first, pipeline: Ci::Pipeline.first)
-
Find the Pipeline from the build info and destroy it:
Packages::BuildInfo.first => #<Packages::BuildInfo:0x00007fd3c9f286f0 id: 4, package_id: 1, pipeline_id: 1> Ci::Pipeline.find(1).destroy
-
The build info should now have a
nil
pipeline_id
:Packages::BuildInfo.first => #<Packages::BuildInfo:0x00007fd36f16dec0 id: 4, package_id: 1, pipeline_id: nil>
-
Repeat for package file build infos:
[59] pry(main)> Packages::PackageFileBuildInfo.create(package_file: Packages::PackageFile.first, pipeline: Ci::Pipeline.first) => #<Packages::PackageFileBuildInfo:0x00007fd36eca68b0 id: 4, package_file_id: 4, pipeline_id: 2> [60] pry(main)> Ci::Pipeline.find(2).destroy ... [62] pry(main)> Packages::PackageFileBuildInfo.last => #<Packages::PackageFileBuildInfo:0x00007fd33ffaee10 id: 4, package_file_id: 4, pipeline_id: nil>
🐧 MR acceptance checklist
This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.
-
I have evaluated the MR acceptance checklist for this MR.
Related to #338861 (closed)