Add namespace_id reference to routes
What does this MR do and why?
This reference will serve as a replacement of the existing source polymorphic reference (eventually we want to use only namespace routes).
Related to #349598 (closed)
Related discussion also in &7184 (comment 776564877)
DB Migration
$ rake db:migrate
== 20220105121325 AddRouteNamespaceReference: migrating =======================
-- column_exists?(:routes, :namespace_id)
-> 0.0018s
-- add_column(:routes, :namespace_id, :bigint)
-> 0.0008s
== 20220105121325 AddRouteNamespaceReference: migrated (0.0026s) ==============
== 20220107091629 AddRouteNamespaceIndex: migrating ===========================
-- transaction_open?()
-> 0.0000s
-- index_exists?(:routes, :namespace_id, {:unique=>true, :name=>"index_routes_on_namespace_id", :algorithm=>:concurrently})
-> 0.0026s
-- execute("SET statement_timeout TO 0")
-> 0.0004s
-- add_index(:routes, :namespace_id, {:unique=>true, :name=>"index_routes_on_namespace_id", :algorithm=>:concurrently})
-> 0.0072s
-- execute("RESET statement_timeout")
-> 0.0004s
-- transaction_open?()
-> 0.0000s
-- foreign_keys(:routes)
-> 0.0019s
-- transaction_open?()
-> 0.0000s
-- execute("LOCK TABLE namespaces, routes IN SHARE ROW EXCLUSIVE MODE")
-> 0.0004s
-- execute("ALTER TABLE routes\nADD CONSTRAINT fk_679ff8213d\nFOREIGN KEY (namespace_id)\nREFERENCES namespaces (id)\nON DELETE SET NULL\nNOT VALID;\n")
-> 0.0016s
-- execute("ALTER TABLE routes VALIDATE CONSTRAINT fk_679ff8213d;")
-> 0.0027s
== 20220107091629 AddRouteNamespaceIndex: migrated (0.0230s) ==================
$ rake db:rollback
== 20220107091629 AddRouteNamespaceIndex: reverting ===========================
-- transaction_open?()
-> 0.0000s
-- remove_foreign_key(:routes, {:column=>:namespace_id})
-> 0.0030s
-- transaction_open?()
-> 0.0000s
-- indexes(:routes)
-> 0.0024s
-- execute("SET statement_timeout TO 0")
-> 0.0004s
-- remove_index(:routes, {:algorithm=>:concurrently, :name=>"index_routes_on_namespace_id"})
-> 0.0038s
-- execute("RESET statement_timeout")
-> 0.0003s
== 20220107091629 AddRouteNamespaceIndex: reverted (0.0189s) ==================
== 20220105121325 AddRouteNamespaceReference: reverting =======================
-- column_exists?(:routes, :namespace_id)
-> 0.0008s
-- remove_column(:routes, :namespace_id)
-> 0.0006s
== 20220105121325 AddRouteNamespaceReference: reverted (0.0015s) ==============
Screenshots or screen recordings
These are strongly recommended to assist reviewers and reduce the time to merge your change.
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.
-
I have evaluated the MR acceptance checklist for this MR.
Edited by Jan Provaznik