Rename user_id to author_id for Versions
What does this MR do?
This MR renames design_management_versions.user_id
column, index and foreign key constraint to author_id
.
!17316 (merged) introduced the user_id
column, and there is currently no data in the existing user_id
column, as there has been no application code merged that adds data to it.
Migration output
== 20191014025629 RenameDesignManagementVersionUserToAuthor: migrating ========
-- transaction_open?()
-> 0.0000s
-- columns(:design_management_versions)
-> 0.0012s
-- add_column(:design_management_versions, :author_id, :integer, {:limit=>4, :precision=>nil, :scale=>nil})
-> 0.0015s
-- transaction_open?()
-> 0.0000s
-- exec_query("SELECT COUNT(*) AS count FROM \"design_management_versions\"")
-> 0.0007s
-- exec_query("SELECT \"design_management_versions\".\"id\" FROM \"design_management_versions\" ORDER BY \"design_management_versions\".\"id\" ASC LIMIT 1")
-> 0.0004s
-- exec_query("SELECT \"design_management_versions\".\"id\" FROM \"design_management_versions\" WHERE \"design_management_versions\".\"id\" >= 1 ORDER BY \"design_management_versions\".\"id\" ASC LIMIT 1 OFFSET 2")
-> 0.0004s
-- execute("UPDATE \"design_management_versions\" SET \"author_id\" = \"design_management_versions\".\"user_id\" WHERE \"design_management_versions\".\"id\" >= 1 AND \"design_management_versions\".\"id\" < 3")
-> 0.0006s
-- exec_query("SELECT \"design_management_versions\".\"id\" FROM \"design_management_versions\" WHERE \"design_management_versions\".\"id\" >= 3 ORDER BY \"design_management_versions\".\"id\" ASC LIMIT 1 OFFSET 2")
-> 0.0003s
-- execute("UPDATE \"design_management_versions\" SET \"author_id\" = \"design_management_versions\".\"user_id\" WHERE \"design_management_versions\".\"id\" >= 3 AND \"design_management_versions\".\"id\" < 5")
-> 0.0007s
-- exec_query("SELECT \"design_management_versions\".\"id\" FROM \"design_management_versions\" WHERE \"design_management_versions\".\"id\" >= 5 ORDER BY \"design_management_versions\".\"id\" ASC LIMIT 1 OFFSET 2")
-> 0.0004s
-- execute("UPDATE \"design_management_versions\" SET \"author_id\" = \"design_management_versions\".\"user_id\" WHERE \"design_management_versions\".\"id\" >= 5 AND \"design_management_versions\".\"id\" < 7")
-> 0.0005s
-- exec_query("SELECT \"design_management_versions\".\"id\" FROM \"design_management_versions\" WHERE \"design_management_versions\".\"id\" >= 7 ORDER BY \"design_management_versions\".\"id\" ASC LIMIT 1 OFFSET 2")
-> 0.0003s
-- execute("UPDATE \"design_management_versions\" SET \"author_id\" = \"design_management_versions\".\"user_id\" WHERE \"design_management_versions\".\"id\" >= 7 AND \"design_management_versions\".\"id\" < 9")
-> 0.0005s
-- exec_query("SELECT \"design_management_versions\".\"id\" FROM \"design_management_versions\" WHERE \"design_management_versions\".\"id\" >= 9 ORDER BY \"design_management_versions\".\"id\" ASC LIMIT 1 OFFSET 2")
-> 0.0003s
-- execute("UPDATE \"design_management_versions\" SET \"author_id\" = \"design_management_versions\".\"user_id\" WHERE \"design_management_versions\".\"id\" >= 9 AND \"design_management_versions\".\"id\" < 11")
-> 0.0005s
-- exec_query("SELECT \"design_management_versions\".\"id\" FROM \"design_management_versions\" WHERE \"design_management_versions\".\"id\" >= 11 ORDER BY \"design_management_versions\".\"id\" ASC LIMIT 1 OFFSET 2")
-> 0.0003s
-- execute("UPDATE \"design_management_versions\" SET \"author_id\" = \"design_management_versions\".\"user_id\" WHERE \"design_management_versions\".\"id\" >= 11 AND \"design_management_versions\".\"id\" < 13")
-> 0.0005s
-- exec_query("SELECT \"design_management_versions\".\"id\" FROM \"design_management_versions\" WHERE \"design_management_versions\".\"id\" >= 13 ORDER BY \"design_management_versions\".\"id\" ASC LIMIT 1 OFFSET 2")
-> 0.0003s
-- execute("UPDATE \"design_management_versions\" SET \"author_id\" = \"design_management_versions\".\"user_id\" WHERE \"design_management_versions\".\"id\" >= 13 AND \"design_management_versions\".\"id\" < 15")
-> 0.0005s
-- exec_query("SELECT \"design_management_versions\".\"id\" FROM \"design_management_versions\" WHERE \"design_management_versions\".\"id\" >= 15 ORDER BY \"design_management_versions\".\"id\" ASC LIMIT 1 OFFSET 2")
-> 0.0003s
-- execute("UPDATE \"design_management_versions\" SET \"author_id\" = \"design_management_versions\".\"user_id\" WHERE \"design_management_versions\".\"id\" >= 15 AND \"design_management_versions\".\"id\" < 17")
-> 0.0005s
-- exec_query("SELECT \"design_management_versions\".\"id\" FROM \"design_management_versions\" WHERE \"design_management_versions\".\"id\" >= 17 ORDER BY \"design_management_versions\".\"id\" ASC LIMIT 1 OFFSET 2")
-> 0.0003s
-- execute("UPDATE \"design_management_versions\" SET \"author_id\" = \"design_management_versions\".\"user_id\" WHERE \"design_management_versions\".\"id\" >= 17 AND \"design_management_versions\".\"id\" < 19")
-> 0.0004s
-- exec_query("SELECT \"design_management_versions\".\"id\" FROM \"design_management_versions\" WHERE \"design_management_versions\".\"id\" >= 19 ORDER BY \"design_management_versions\".\"id\" ASC LIMIT 1 OFFSET 2")
-> 0.0003s
-- execute("UPDATE \"design_management_versions\" SET \"author_id\" = \"design_management_versions\".\"user_id\" WHERE \"design_management_versions\".\"id\" >= 19 AND \"design_management_versions\".\"id\" < 22")
-> 0.0014s
-- exec_query("SELECT \"design_management_versions\".\"id\" FROM \"design_management_versions\" WHERE \"design_management_versions\".\"id\" >= 22 ORDER BY \"design_management_versions\".\"id\" ASC LIMIT 1 OFFSET 2")
-> 0.0005s
-- execute("UPDATE \"design_management_versions\" SET \"author_id\" = \"design_management_versions\".\"user_id\" WHERE \"design_management_versions\".\"id\" >= 22 AND \"design_management_versions\".\"id\" < 25")
-> 0.0006s
-- exec_query("SELECT \"design_management_versions\".\"id\" FROM \"design_management_versions\" WHERE \"design_management_versions\".\"id\" >= 25 ORDER BY \"design_management_versions\".\"id\" ASC LIMIT 1 OFFSET 2")
-> 0.0004s
-- execute("UPDATE \"design_management_versions\" SET \"author_id\" = \"design_management_versions\".\"user_id\" WHERE \"design_management_versions\".\"id\" >= 25 AND \"design_management_versions\".\"id\" < 27")
-> 0.0005s
-- exec_query("SELECT \"design_management_versions\".\"id\" FROM \"design_management_versions\" WHERE \"design_management_versions\".\"id\" >= 27 ORDER BY \"design_management_versions\".\"id\" ASC LIMIT 1 OFFSET 2")
-> 0.0006s
-- execute("UPDATE \"design_management_versions\" SET \"author_id\" = \"design_management_versions\".\"user_id\" WHERE \"design_management_versions\".\"id\" >= 27 AND \"design_management_versions\".\"id\" < 29")
-> 0.0004s
-- exec_query("SELECT \"design_management_versions\".\"id\" FROM \"design_management_versions\" WHERE \"design_management_versions\".\"id\" >= 29 ORDER BY \"design_management_versions\".\"id\" ASC LIMIT 1 OFFSET 2")
-> 0.0003s
-- execute("UPDATE \"design_management_versions\" SET \"author_id\" = \"design_management_versions\".\"user_id\" WHERE \"design_management_versions\".\"id\" >= 29")
-> 0.0005s
-- indexes(:design_management_versions)
-> 0.0019s
-- foreign_keys(:design_management_versions)
-> 0.0021s
-- transaction_open?()
-> 0.0000s
-- foreign_keys("design_management_versions")
-> 0.0016s
-- execute("ALTER TABLE design_management_versions\nADD CONSTRAINT fk_c1440b4896\nFOREIGN KEY (author_id)\nREFERENCES users (id)\nON DELETE SET NULL\nNOT VALID;\n")
-> 0.0015s
-- execute("SET statement_timeout TO 0")
-> 0.0002s
-- execute("ALTER TABLE design_management_versions VALIDATE CONSTRAINT fk_c1440b4896;")
-> 0.0018s
-- execute("RESET ALL")
-> 0.0002s
-- quote_table_name(:design_management_versions)
-> 0.0000s
-- quote_column_name(:user_id)
-> 0.0000s
-- quote_column_name(:author_id)
-> 0.0000s
-- execute("CREATE OR REPLACE FUNCTION trigger_97893debd1d4()\nRETURNS trigger AS\n$BODY$\nBEGIN\n NEW.\"author_id\" := NEW.\"user_id\";\n RETURN NEW;\nEND;\n$BODY$\nLANGUAGE 'plpgsql'\nVOLATILE\n")
-> 0.0056s
-- execute("DROP TRIGGER IF EXISTS trigger_97893debd1d4\nON \"design_management_versions\"\n")
NOTICE: trigger "trigger_97893debd1d4" for relation "design_management_versions" does not exist, skipping
-> 0.0003s
-- execute("CREATE TRIGGER trigger_97893debd1d4\nBEFORE INSERT OR UPDATE\nON \"design_management_versions\"\nFOR EACH ROW\nEXECUTE PROCEDURE trigger_97893debd1d4()\n")
-> 0.0004s
== 20191014025629 RenameDesignManagementVersionUserToAuthor: migrated (0.0684s)
== 20191014030134 CleanupDesignManagementVersionUserToAuthorRename: migrating =
-- execute("DROP TRIGGER IF EXISTS trigger_97893debd1d4 ON design_management_versions")
-> 0.0006s
-- execute("DROP FUNCTION IF EXISTS trigger_97893debd1d4()")
-> 0.0004s
-- remove_column(:design_management_versions, :user_id)
-> 0.0007s
== 20191014030134 CleanupDesignManagementVersionUserToAuthorRename: migrated (0.0166s)
== 20191014030730 AddAuthorIndexToDesignManagementVersions: migrating =========
-- transaction_open?()
-> 0.0000s
-- index_exists?(:design_management_versions, :author_id, {:where=>"author_id IS NOT NULL", :algorithm=>:concurrently})
-> 0.0013s
-- execute("SET statement_timeout TO 0")
-> 0.0002s
-- add_index(:design_management_versions, :author_id, {:where=>"author_id IS NOT NULL", :algorithm=>:concurrently})
-> 0.0035s
-- execute("RESET ALL")
-> 0.0003s
== 20191014030730 AddAuthorIndexToDesignManagementVersions: migrated (0.0055s)
Rollback procedure
The migrations have down
methods which rollback the changes.
Database checklist
-
Conforms to the database guides
When adding migrations:
-
Updated db/schema.rb
-
Added a down
method so the migration can be reverted -
Added the output of the migration(s) to the MR body - [-] Added tests for the migration in
spec/migrations
if necessary (e.g. when migrating data) -
Added rollback procedure. Include either a rollback procedure or description how to rollback changes
When removing columns, tables, indexes or other structures:
-
Removed these in a post-deployment migration - [-] Made sure the application no longer uses (or ignores) these structures
Edited by 🤖 GitLab Bot 🤖