Skip to content

Finalize data migration and add FK on `Project#creator_id`

What does this MR do and why?

Related to #390641 (closed)

This MR

  • Finalizes the data migration that we have already added in !110485 (merged), that was merged 2 weeks ago.
  • After this data migration is finalized, a second post_deploy migration adds a foreign key relation on Project#creator_id to User#id, which is NOT VALID

Migrations

UP migration

$ rake db:migrate

main: == 20230223065753 FinalizeNullifyCreatorIdOfOrphanedProjects: migrating =======
main: == 20230223065753 FinalizeNullifyCreatorIdOfOrphanedProjects: migrated (0.0237s)

main: == 20230223093704 AddForeignKeyOnCreatorIdOnProjects: migrating ===============
main: -- transaction_open?()
main:    -> 0.0000s
main: -- transaction_open?()
main:    -> 0.0000s
main: -- execute("ALTER TABLE projects\nADD CONSTRAINT fk_03ec10b0d3\nFOREIGN KEY (creator_id)\nREFERENCES users (id)\n\nON DELETE SET NULL\nNOT VALID;\n")
main:    -> 0.0015s
main: == 20230223093704 AddForeignKeyOnCreatorIdOnProjects: migrated (0.0170s) ======

ci: == 20230223065753 FinalizeNullifyCreatorIdOfOrphanedProjects: migrating =======
ci: -- The migration is skipped since it modifies the schemas: [:gitlab_main].
ci: -- This database can only apply migrations in one of the following schemas: [:gitlab_ci, :gitlab_shared, :gitlab_internal].
ci: == 20230223065753 FinalizeNullifyCreatorIdOfOrphanedProjects: migrated (0.0064s)

ci: == 20230223093704 AddForeignKeyOnCreatorIdOnProjects: migrating ===============
ci: -- transaction_open?()
ci:    -> 0.0000s
ci: -- transaction_open?()
ci:    -> 0.0000s
ci: -- execute("ALTER TABLE projects\nADD CONSTRAINT fk_03ec10b0d3\nFOREIGN KEY (creator_id)\nREFERENCES users (id)\n\nON DELETE SET NULL\nNOT VALID;\n")
ci:    -> 0.0016s
ci: == 20230223093704 AddForeignKeyOnCreatorIdOnProjects: migrated (0.0152s) ======

DOWN Migrations

$ rake db:migrate:down:main VERSION=20230223093704

main: == 20230223093704 AddForeignKeyOnCreatorIdOnProjects: reverting ===============
main: -- transaction_open?()
main:    -> 0.0001s
main: -- remove_foreign_key(:projects, {:column=>:creator_id})
main:    -> 0.0071s
main: == 20230223093704 AddForeignKeyOnCreatorIdOnProjects: reverted (0.3172s) ======

$ rake db:migrate:down:ci VERSION=20230223093704

ci: == 20230223093704 AddForeignKeyOnCreatorIdOnProjects: reverting ===============
ci: -- transaction_open?()
ci:    -> 0.0000s
ci: -- remove_foreign_key(:projects, {:column=>:creator_id})
ci:    -> 0.0031s
ci: == 20230223093704 AddForeignKeyOnCreatorIdOnProjects: reverted (0.1310s) ======

$ rake db:migrate:down:main VERSION=20230223065753

main: == 20230223065753 FinalizeNullifyCreatorIdOfOrphanedProjects: reverting =======
main: == 20230223065753 FinalizeNullifyCreatorIdOfOrphanedProjects: reverted (0.0040s)

$ rake db:migrate:down:ci VERSION=20230223065753

ci: == 20230223065753 FinalizeNullifyCreatorIdOfOrphanedProjects: reverting =======
ci: -- The migration is skipped since it modifies the schemas: [:gitlab_main].
ci: -- This database can only apply migrations in one of the following schemas: [:gitlab_ci, :gitlab_shared, :gitlab_internal].
ci: == 20230223065753 FinalizeNullifyCreatorIdOfOrphanedProjects: reverted (0.0267s)

Screenshots or screen recordings

Screenshots are required for UI changes, and strongly recommended for all other merge requests.

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.

Related to #390641 (closed)

Edited by Manoj M J

Merge request reports