Skip to content

Validate foreign key on GroupHooks

What does this MR do?

In %13.11, we added a NOT VALID foreign key constraint to the column to ensure GitLab doesn’t create inconsistent records !57735 (merged).

We also added a data migration, to fix or clean up existing records !57863 (merged).

We can now validate the foreign key.

Reference https://docs.gitlab.com/ee/development/database/add_foreign_key_to_existing_column.html

Migration script

$ rails db:migrate
== 20210426091650 ValidateForeignKeyOnGroupHooks: migrating ===================
-- foreign_keys(:web_hooks)
   -> 0.0065s
-- execute("SET statement_timeout TO 0")
   -> 0.0007s
-- execute("ALTER TABLE web_hooks VALIDATE CONSTRAINT fk_rails_d35697648e;")
   -> 0.0258s
-- execute("RESET ALL")
   -> 0.0007s
== 20210426091650 ValidateForeignKeyOnGroupHooks: migrated (0.0350s) ==========
$ rails db:migrate:down VERSION=20210426091650
== 20210426091650 ValidateForeignKeyOnGroupHooks: reverting ===================
== 20210426091650 ValidateForeignKeyOnGroupHooks: reverted (0.0000s) ==========

Related to #202423 (closed)

Merge request reports