Migration to swap ci_builds.stage_id column
What does this MR do?
Related issue: #325619 (closed)
Add migration to swap the int8 version of the ci_builds.stage_id
column with the int4 version.
Migration up
$ rails db:migrate:up VERSION=20210701141346
== 20210701141346 FinalizeCiBuildsStageIdBigintConversion: migrating ==========
-- transaction_open?()
-> 0.0001s
-- index_exists?("ci_builds", :stage_id_convert_to_bigint, {:name=>:index_ci_builds_on_converted_stage_id, :algorithm=>:concurrently})
-> 0.0093s
-- execute("SET statement_timeout TO 0")
-> 0.0005s
-- add_index("ci_builds", :stage_id_convert_to_bigint, {:name=>:index_ci_builds_on_converted_stage_id, :algorithm=>:concurrently})
-> 0.0034s
-- execute("RESET statement_timeout")
-> 0.0005s
-- transaction_open?()
-> 0.0000s
-- foreign_keys("ci_builds")
-> 0.0029s
-- execute("LOCK TABLE ci_stages, ci_builds IN SHARE ROW EXCLUSIVE MODE")
-> 0.0005s
-- execute("ALTER TABLE ci_builds\nADD CONSTRAINT fk_c050b39299\nFOREIGN KEY (stage_id_convert_to_bigint)\nREFERENCES ci_stages (id)\nON DELETE CASCADE\nNOT VALID;\n")
-> 0.0015s
-- execute("ALTER TABLE ci_builds VALIDATE CONSTRAINT fk_c050b39299;")
-> 0.0044s
-- quote_table_name("ci_builds")
-> 0.0000s
-- quote_table_name(:ci_stages)
-> 0.0000s
-- execute("LOCK TABLE \"ci_stages\", \"ci_builds\" IN ACCESS EXCLUSIVE MODE")
-> 0.0005s
-- quote_column_name(:stage_id)
-> 0.0000s
-- quote_column_name("stage_id_tmp")
-> 0.0000s
-- execute("ALTER TABLE \"ci_builds\" RENAME COLUMN \"stage_id\" TO \"stage_id_tmp\"")
-> 0.0006s
-- quote_column_name(:stage_id_convert_to_bigint)
-> 0.0000s
-- quote_column_name(:stage_id)
-> 0.0000s
-- execute("ALTER TABLE \"ci_builds\" RENAME COLUMN \"stage_id_convert_to_bigint\" TO \"stage_id\"")
-> 0.0006s
-- quote_column_name("stage_id_tmp")
-> 0.0000s
-- quote_column_name(:stage_id_convert_to_bigint)
-> 0.0000s
-- execute("ALTER TABLE \"ci_builds\" RENAME COLUMN \"stage_id_tmp\" TO \"stage_id_convert_to_bigint\"")
-> 0.0005s
-- quote_table_name("trigger_3f6129be01d2")
-> 0.0000s
-- execute("ALTER FUNCTION \"trigger_3f6129be01d2\" RESET ALL")
-> 0.0006s
-- execute("DROP INDEX index_ci_builds_on_stage_id")
-> 0.0008s
-- rename_index("ci_builds", :index_ci_builds_on_converted_stage_id, :index_ci_builds_on_stage_id)
-> 0.0005s
-- remove_foreign_key("ci_builds", {:name=>"fk_3a9eaa254d"})
-> 0.0032s
-- quote_table_name("ci_builds")
-> 0.0000s
-- quote_column_name("fk_c050b39299")
-> 0.0000s
-- quote_column_name("fk_3a9eaa254d")
-> 0.0000s
-- execute("ALTER TABLE \"ci_builds\"\nRENAME CONSTRAINT \"fk_c050b39299\" TO \"fk_3a9eaa254d\"\n")
-> 0.0005s
== 20210701141346 FinalizeCiBuildsStageIdBigintConversion: migrated (0.0638s) =
Migration Down
$ rails db:migrate:down VERSION=20210701141346
== 20210701141346 FinalizeCiBuildsStageIdBigintConversion: reverting ==========
-- transaction_open?()
-> 0.0000s
-- index_exists?("ci_builds", :stage_id_convert_to_bigint, {:name=>:index_ci_builds_on_converted_stage_id, :algorithm=>:concurrently})
-> 0.0099s
-- execute("SET statement_timeout TO 0")
-> 0.0005s
-- add_index("ci_builds", :stage_id_convert_to_bigint, {:name=>:index_ci_builds_on_converted_stage_id, :algorithm=>:concurrently})
-> 0.0035s
-- execute("RESET statement_timeout")
-> 0.0005s
-- transaction_open?()
-> 0.0000s
-- foreign_keys("ci_builds")
-> 0.0030s
-- execute("LOCK TABLE ci_stages, ci_builds IN SHARE ROW EXCLUSIVE MODE")
-> 0.0007s
-- execute("ALTER TABLE ci_builds\nADD CONSTRAINT fk_c050b39299\nFOREIGN KEY (stage_id_convert_to_bigint)\nREFERENCES ci_stages (id)\nON DELETE CASCADE\nNOT VALID;\n")
-> 0.0016s
-- execute("ALTER TABLE ci_builds VALIDATE CONSTRAINT fk_c050b39299;")
-> 0.0045s
-- quote_table_name("ci_builds")
-> 0.0000s
-- quote_table_name(:ci_stages)
-> 0.0000s
-- execute("LOCK TABLE \"ci_stages\", \"ci_builds\" IN ACCESS EXCLUSIVE MODE")
-> 0.0006s
-- quote_column_name(:stage_id)
-> 0.0000s
-- quote_column_name("stage_id_tmp")
-> 0.0000s
-- execute("ALTER TABLE \"ci_builds\" RENAME COLUMN \"stage_id\" TO \"stage_id_tmp\"")
-> 0.0007s
-- quote_column_name(:stage_id_convert_to_bigint)
-> 0.0000s
-- quote_column_name(:stage_id)
-> 0.0000s
-- execute("ALTER TABLE \"ci_builds\" RENAME COLUMN \"stage_id_convert_to_bigint\" TO \"stage_id\"")
-> 0.0006s
-- quote_column_name("stage_id_tmp")
-> 0.0000s
-- quote_column_name(:stage_id_convert_to_bigint)
-> 0.0000s
-- execute("ALTER TABLE \"ci_builds\" RENAME COLUMN \"stage_id_tmp\" TO \"stage_id_convert_to_bigint\"")
-> 0.0007s
-- quote_table_name("trigger_3f6129be01d2")
-> 0.0000s
-- execute("ALTER FUNCTION \"trigger_3f6129be01d2\" RESET ALL")
-> 0.0007s
-- execute("DROP INDEX index_ci_builds_on_stage_id")
-> 0.0009s
-- rename_index("ci_builds", :index_ci_builds_on_converted_stage_id, :index_ci_builds_on_stage_id)
-> 0.0007s
-- remove_foreign_key("ci_builds", {:name=>"fk_3a9eaa254d"})
-> 0.0035s
-- quote_table_name("ci_builds")
-> 0.0000s
-- quote_column_name("fk_c050b39299")
-> 0.0000s
-- quote_column_name("fk_3a9eaa254d")
-> 0.0000s
-- execute("ALTER TABLE \"ci_builds\"\nRENAME CONSTRAINT \"fk_c050b39299\" TO \"fk_3a9eaa254d\"\n")
-> 0.0007s
== 20210701141346 FinalizeCiBuildsStageIdBigintConversion: reverted (0.0589s) =
Screenshots or Screencasts (strongly suggested)
Does this MR meet the acceptance criteria?
Conformity
-
I have included changelog trailers, or none are needed. (Does this MR need a changelog?) -
I have added/updated documentation, or it's not needed. (Is documentation required?) -
I have properly separated EE content from FOSS, or this MR is FOSS only. (Where should EE code go?) -
I have added information for database reviewers in the MR description, or it's not needed. (Does this MR have database related changes?) -
I have self-reviewed this MR per code review guidelines. -
This MR does not harm performance, or I have asked a reviewer to help assess the performance impact. (Merge request performance guidelines) -
I have followed the style guides. -
This change is backwards compatible across updates, or this does not apply.
Availability and Testing
-
I have added/updated tests following the Testing Guide, or it's not needed. (Consider all test levels. See the Test Planning Process.) -
I have tested this MR in all supported browsers, or it's not needed. -
I have informed the Infrastructure department of a default or new setting change per definition of done, or it's not needed.
Edited by Patrick Bair