Resolve "Convert ci_builds_runner_session.build_id to bigint - Step 2: Finalize background migrations and swap columns"
What does this MR do?
This MR finalize the conversion to bigint
for ci_builds_runner_session
table.
At a high level, the operation takes the following steps:
- Ensure the migration of
build_id
tobigint
is completed. - Copy index and FK
- Swap columns
Cleanup (removing the old int
columns and the triggers) will be done in later MR.
Migration Output
Up
== 20210720091902 FinalizeCiBuildsRunnerSessionBigintConversion: migrating ==== -- transaction_open?() -> 0.0000s -- index_exists?("ci_builds_runner_session", :build_id_convert_to_bigint, {:unique=>true, :name=>"index_ci_builds_runner_session_on_build_id_convert_to_bigint", :algorithm=>:concurrently}) -> 0.0019s -- execute("SET statement_timeout TO 0") -> 0.0005s -- add_index("ci_builds_runner_session", :build_id_convert_to_bigint, {:unique=>true, :name=>"index_ci_builds_runner_session_on_build_id_convert_to_bigint", :algorithm=>:concurrently}) -> 0.0028s -- execute("RESET ALL") -> 0.0005s -- transaction_open?() -> 0.0000s -- foreign_keys("ci_builds_runner_session") -> 0.0030s -- execute("ALTER TABLE ci_builds_runner_session\nADD CONSTRAINT fk_rails_70707857d3_tmp\nFOREIGN KEY (build_id_convert_to_bigint)\nREFERENCES ci_builds (id)\nON DELETE CASCADE\nNOT VALID;\n") -> 0.0016s -- execute("ALTER TABLE ci_builds_runner_session VALIDATE CONSTRAINT fk_rails_70707857d3_tmp;") -> 0.0042s -- execute("LOCK TABLE ci_builds_runner_session, ci_builds IN ACCESS EXCLUSIVE MODE") -> 0.0006s -- quote_table_name("ci_builds_runner_session") -> 0.0000s -- quote_column_name(:build_id) -> 0.0000s -- quote_column_name("build_id_tmp") -> 0.0000s -- execute("ALTER TABLE \"ci_builds_runner_session\" RENAME COLUMN \"build_id\" TO \"build_id_tmp\"") -> 0.0006s -- quote_table_name("ci_builds_runner_session") -> 0.0000s -- quote_column_name(:build_id_convert_to_bigint) -> 0.0000s -- quote_column_name(:build_id) -> 0.0000s -- execute("ALTER TABLE \"ci_builds_runner_session\" RENAME COLUMN \"build_id_convert_to_bigint\" TO \"build_id\"") -> 0.0006s -- quote_table_name("ci_builds_runner_session") -> 0.0000s -- quote_column_name("build_id_tmp") -> 0.0000s -- quote_column_name(:build_id_convert_to_bigint) -> 0.0000s -- execute("ALTER TABLE \"ci_builds_runner_session\" RENAME COLUMN \"build_id_tmp\" TO \"build_id_convert_to_bigint\"") -> 0.0005s -- quote_table_name("trigger_51ab7cef8934") -> 0.0000s -- execute("ALTER FUNCTION \"trigger_51ab7cef8934\" RESET ALL") -> 0.0006s -- change_column_default("ci_builds_runner_session", :build_id, nil) -> 0.0020s -- change_column_default("ci_builds_runner_session", :build_id_convert_to_bigint, 0) -> 0.0017s -- execute("DROP INDEX index_ci_builds_runner_session_on_build_id") -> 0.0006s -- rename_index("ci_builds_runner_session", "index_ci_builds_runner_session_on_build_id_convert_to_bigint", "index_ci_builds_runner_session_on_build_id") -> 0.0005s -- remove_foreign_key("ci_builds_runner_session", {:name=>"fk_rails_70707857d3"}) -> 0.0029s -- quote_table_name("ci_builds_runner_session") -> 0.0000s -- quote_column_name("fk_rails_70707857d3_tmp") -> 0.0000s -- quote_column_name("fk_rails_70707857d3") -> 0.0000s -- execute("ALTER TABLE \"ci_builds_runner_session\"\nRENAME CONSTRAINT \"fk_rails_70707857d3_tmp\" TO \"fk_rails_70707857d3\"\n") -> 0.0005s == 20210720091902 FinalizeCiBuildsRunnerSessionBigintConversion: migrated (0.0647s)
Down
== 20210720091902 FinalizeCiBuildsRunnerSessionBigintConversion: reverting ==== -- transaction_open?() -> 0.0000s -- index_exists?("ci_builds_runner_session", :build_id_convert_to_bigint, {:unique=>true, :name=>"index_ci_builds_runner_session_on_build_id_convert_to_bigint", :algorithm=>:concurrently}) -> 0.0026s -- execute("SET statement_timeout TO 0") -> 0.0005s -- add_index("ci_builds_runner_session", :build_id_convert_to_bigint, {:unique=>true, :name=>"index_ci_builds_runner_session_on_build_id_convert_to_bigint", :algorithm=>:concurrently}) -> 0.0030s -- execute("RESET ALL") -> 0.0005s -- transaction_open?() -> 0.0000s -- foreign_keys("ci_builds_runner_session") -> 0.0028s -- execute("ALTER TABLE ci_builds_runner_session\nADD CONSTRAINT fk_rails_70707857d3_tmp\nFOREIGN KEY (build_id_convert_to_bigint)\nREFERENCES ci_builds (id)\nON DELETE CASCADE\nNOT VALID;\n") -> 0.0016s -- execute("ALTER TABLE ci_builds_runner_session VALIDATE CONSTRAINT fk_rails_70707857d3_tmp;") -> 0.0043s -- execute("LOCK TABLE ci_builds_runner_session, ci_builds IN ACCESS EXCLUSIVE MODE") -> 0.0005s -- quote_table_name("ci_builds_runner_session") -> 0.0000s -- quote_column_name(:build_id) -> 0.0000s -- quote_column_name("build_id_tmp") -> 0.0000s -- execute("ALTER TABLE \"ci_builds_runner_session\" RENAME COLUMN \"build_id\" TO \"build_id_tmp\"") -> 0.0006s -- quote_table_name("ci_builds_runner_session") -> 0.0000s -- quote_column_name(:build_id_convert_to_bigint) -> 0.0000s -- quote_column_name(:build_id) -> 0.0000s -- execute("ALTER TABLE \"ci_builds_runner_session\" RENAME COLUMN \"build_id_convert_to_bigint\" TO \"build_id\"") -> 0.0005s -- quote_table_name("ci_builds_runner_session") -> 0.0000s -- quote_column_name("build_id_tmp") -> 0.0000s -- quote_column_name(:build_id_convert_to_bigint) -> 0.0000s -- execute("ALTER TABLE \"ci_builds_runner_session\" RENAME COLUMN \"build_id_tmp\" TO \"build_id_convert_to_bigint\"") -> 0.0005s -- quote_table_name("trigger_51ab7cef8934") -> 0.0000s -- execute("ALTER FUNCTION \"trigger_51ab7cef8934\" RESET ALL") -> 0.0006s -- change_column_default("ci_builds_runner_session", :build_id, nil) -> 0.0017s -- change_column_default("ci_builds_runner_session", :build_id_convert_to_bigint, 0) -> 0.0016s -- execute("DROP INDEX index_ci_builds_runner_session_on_build_id") -> 0.0006s -- rename_index("ci_builds_runner_session", "index_ci_builds_runner_session_on_build_id_convert_to_bigint", "index_ci_builds_runner_session_on_build_id") -> 0.0006s -- remove_foreign_key("ci_builds_runner_session", {:name=>"fk_rails_70707857d3"}) -> 0.0029s -- quote_table_name("ci_builds_runner_session") -> 0.0000s -- quote_column_name("fk_rails_70707857d3_tmp") -> 0.0000s -- quote_column_name("fk_rails_70707857d3") -> 0.0000s -- execute("ALTER TABLE \"ci_builds_runner_session\"\nRENAME CONSTRAINT \"fk_rails_70707857d3_tmp\" TO \"fk_rails_70707857d3\"\n") -> 0.0005s == 20210720091902 FinalizeCiBuildsRunnerSessionBigintConversion: reverted (0.0377s)
Database migrations
Timings
From DB Lab:
-
CREATE UNIQUE INDEX CONCURRENTLY "index_ci_builds_runner_session_on_build_id_convert_to_bigint" ON "ci_builds_runner_session" ("build_id_convert_to_bigint");
Duration: 284.506 ms - https://console.postgres.ai/gitlab/gitlab-production-tunnel-pg12/sessions/5268/commands/18590
-
ALTER TABLE ci_builds_runner_session VALIDATE CONSTRAINT fk_rails_70707857d3_tmp;
Duration: 3.273 s - https://console.postgres.ai/gitlab/gitlab-production-tunnel-pg12/sessions/5268/commands/18592
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.
Security
Does this MR contain changes to processing or storing of credentials or tokens, authorization and authentication methods or other items described in the security review guidelines? If not, then delete this Security section.
-
Label as security and @ mention @gitlab-com/gl-security/appsec
-
The MR includes necessary changes to maintain consistency between UI, API, email, or other methods -
Security reports checked/validated by a reviewer from the AppSec team
Related to #328445 (closed)