Skip to content

Update foreign key constraint for personal access tokens

Stan Hu requested to merge sh-update-foreign-key-personal-access-tokens into master

Previously the foreign key constraint for user_id on the personal_access_tokens table did not have the ON DELETE CASCADE option enabled, which made deleting users that had generated a PAT impossible.

This migration adds a new foreign key constraint with this option and drops the old one.

Migration log

== 20191227140254 UpdatePersonalAccessTokensUserIdForeignKey: migrating =======
-- transaction_open?()
   -> 0.0000s
-- foreign_keys(:personal_access_tokens)
   -> 0.0036s
-- execute("ALTER TABLE personal_access_tokens\nADD CONSTRAINT fk_personal_access_tokens_user_id\nFOREIGN KEY (user_id)\nREFERENCES users (id)\nON DELETE CASCADE\nNOT VALID;\n")
   -> 0.0020s
-- execute("SET statement_timeout TO 0")
   -> 0.0003s
-- execute("ALTER TABLE personal_access_tokens VALIDATE CONSTRAINT fk_personal_access_tokens_user_id;")
   -> 0.0022s
-- execute("RESET ALL")
   -> 0.0003s
-- foreign_keys(:personal_access_tokens)
   -> 0.0019s
-- remove_foreign_key(:personal_access_tokens, {:column=>:user_id, :on_delete=>nil})
   -> 0.0024s
== 20191227140254 UpdatePersonalAccessTokensUserIdForeignKey: migrated (0.0131s)

Closes #191262 (closed)

Edited by Stan Hu

Merge request reports

Loading