Draft: Remove redundant foreign key on members namespace_id
What does this MR do and why?
Remove redundant foreign key on members namespace_id
Related to #377433 (closed)
Reason: check_508774aac0
actually bans NULL
on member_namespace_id
and fk_aa82dcc1c6
wants to set it null in contrary.
fk_aa82dcc1c6
was there and in late Sept'22 !93240 (merged) has been merged with check_508774aac0
and fk_2f85abf8f1
which deletes the row. fk_2f85abf8f1
came later, and it deletes the row before fk_aa82dcc1c6
can attempt to set it to null
.
\d+ members
Check constraints:
"check_508774aac0" CHECK (member_namespace_id IS NOT NULL) NOT VALID
Foreign-key constraints:
"fk_2f85abf8f1" FOREIGN KEY (member_namespace_id) REFERENCES namespaces(id) ON DELETE CASCADE NOT VALID
"fk_aa82dcc1c6" FOREIGN KEY (member_namespace_id) REFERENCES namespaces(id) ON DELETE SET NULL
Output
bin/rails db:migrate:up:main VERSION=20221011162354
main: == 20221011162354 MembersRemoveMemberNamespaceIdForeignKey: migrating =========
main: -- transaction_open?()
main: -> 0.0000s
main: -- execute("LOCK TABLE namespaces, members IN ACCESS EXCLUSIVE MODE")
main: -> 0.0004s
main: -- foreign_keys(:members)
main: -> 0.0027s
main: -- remove_foreign_key(:members, :namespaces, {:column=>:member_namespace_id, :name=>"fk_aa82dcc1c6"})
main: -> 0.0041s
main: == 20221011162354 MembersRemoveMemberNamespaceIdForeignKey: migrated (0.0120s)
aakgun@sayglubu:~/aakgun/1/gdk/gitlab$ bin/rails db:migrate:down:main VERSION=20221011162354
main: == 20221011162354 MembersRemoveMemberNamespaceIdForeignKey: reverting =========
main: -- transaction_open?()
main: -> 0.0000s
main: -- foreign_keys(:members)
main: -> 0.0033s
main: -- transaction_open?()
main: -> 0.0000s
main: -- execute("LOCK TABLE namespaces, members IN SHARE ROW EXCLUSIVE MODE")
main: -> 0.0004s
main: -- execute("ALTER TABLE members\nADD CONSTRAINT fk_aa82dcc1c6\nFOREIGN KEY (member_namespace_id)\nREFERENCES namespaces (id)\nON DELETE SET NULL\nNOT VALID;\n")
main: -> 0.0016s
main: -- execute("SET statement_timeout TO 0")
main: -> 0.0003s
main: -- execute("ALTER TABLE members VALIDATE CONSTRAINT fk_aa82dcc1c6;")
main: -> 0.0015s
main: -- execute("RESET statement_timeout")
main: -> 0.0003s
main: == 20221011162354 MembersRemoveMemberNamespaceIdForeignKey: reverted (0.0118s)
How to set up and validate locally
bin/rails db:migrate:up:main VERSION=20221011162354
bin/rails db:migrate:down:main VERSION=20221011162354
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.
Edited by Alper Akgun