Finalize conversion to bigint for ci_sources_pipelines
What does this MR do?
This MR finalize the conversion to bigint
for ci_sources_pipelines
table.
At a high level, the operation takes the following steps:
- Ensure the migration of
source_job_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.
Related to #328436 (closed).
Database migrations
Timings
From DB Lab:
-
CREATE INDEX CONCURRENTLY "index_ci_sources_pipelines_on_source_job_id_convert_to_bigint" ON "ci_sources_pipelines" ("source_job_id_convert_to_bigint")
Duration: 14.110 s - https://console.postgres.ai/gitlab/gitlab-production-tunnel-pg12/sessions/5170/commands/18260
-
ALTER TABLE ci_sources_pipelines VALIDATE CONSTRAINT fk_be5624bf37_tmp
Duration: 29.194 min - https://console.postgres.ai/gitlab/gitlab-production-tunnel-pg12/sessions/5170/commands/18262
Output
⬆ Up
$ bundle exec rails db:migrate:up VERSION=20210713042153
== 20210713042153 FinalizeCiSourcesPipelinesBigintConversion: migrating =======
-- transaction_open?()
-> 0.0000s
-- index_exists?("ci_sources_pipelines", :source_job_id_convert_to_bigint, {:name=>"index_ci_sources_pipelines_on_source_job_id_convert_to_bigint", :algorithm=>:concurrently})
-> 0.0036s
-- execute("SET statement_timeout TO 0")
-> 0.0006s
-- add_index("ci_sources_pipelines", :source_job_id_convert_to_bigint, {:name=>"index_ci_sources_pipelines_on_source_job_id_convert_to_bigint", :algorithm=>:concurrently})
-> 0.0086s
-- execute("RESET ALL")
-> 0.0008s
-- transaction_open?()
-> 0.0000s
-- foreign_keys("ci_sources_pipelines")
-> 0.0042s
-- execute("LOCK TABLE ci_builds, ci_sources_pipelines IN SHARE ROW EXCLUSIVE MODE")
-> 0.0009s
-- execute("ALTER TABLE ci_sources_pipelines\nADD CONSTRAINT fk_be5624bf37_tmp\nFOREIGN KEY (source_job_id_convert_to_bigint)\nREFERENCES ci_builds (id)\nON DELETE CASCADE\nNOT VALID;\n")
-> 0.0021s
-- execute("ALTER TABLE ci_sources_pipelines VALIDATE CONSTRAINT fk_be5624bf37_tmp;")
-> 0.0144s
-- execute("LOCK TABLE ci_builds, ci_sources_pipelines IN ACCESS EXCLUSIVE MODE")
-> 0.0007s
-- quote_table_name("ci_sources_pipelines")
-> 0.0000s
-- quote_column_name(:source_job_id)
-> 0.0000s
-- quote_column_name("source_job_id_tmp")
-> 0.0000s
-- execute("ALTER TABLE \"ci_sources_pipelines\" RENAME COLUMN \"source_job_id\" TO \"source_job_id_tmp\"")
-> 0.0008s
-- quote_table_name("ci_sources_pipelines")
-> 0.0000s
-- quote_column_name(:source_job_id_convert_to_bigint)
-> 0.0000s
-- quote_column_name(:source_job_id)
-> 0.0000s
-- execute("ALTER TABLE \"ci_sources_pipelines\" RENAME COLUMN \"source_job_id_convert_to_bigint\" TO \"source_job_id\"")
-> 0.0008s
-- quote_table_name("ci_sources_pipelines")
-> 0.0000s
-- quote_column_name("source_job_id_tmp")
-> 0.0000s
-- quote_column_name(:source_job_id_convert_to_bigint)
-> 0.0000s
-- execute("ALTER TABLE \"ci_sources_pipelines\" RENAME COLUMN \"source_job_id_tmp\" TO \"source_job_id_convert_to_bigint\"")
-> 0.0008s
-- quote_table_name("trigger_8485e97c00e3")
-> 0.0000s
-- execute("ALTER FUNCTION \"trigger_8485e97c00e3\" RESET ALL")
-> 0.0009s
-- execute("DROP INDEX index_ci_sources_pipelines_on_source_job_id")
-> 0.0010s
-- rename_index("ci_sources_pipelines", "index_ci_sources_pipelines_on_source_job_id_convert_to_bigint", "index_ci_sources_pipelines_on_source_job_id")
-> 0.0008s
-- remove_foreign_key("ci_sources_pipelines", {:name=>"fk_be5624bf37"})
-> 0.0040s
-- quote_table_name("ci_sources_pipelines")
-> 0.0000s
-- quote_column_name("fk_be5624bf37_tmp")
-> 0.0000s
-- quote_column_name("fk_be5624bf37")
-> 0.0000s
-- execute("ALTER TABLE \"ci_sources_pipelines\"\nRENAME CONSTRAINT \"fk_be5624bf37_tmp\" TO \"fk_be5624bf37\"\n")
-> 0.0007s
== 20210713042153 FinalizeCiSourcesPipelinesBigintConversion: migrated (0.0829s)
⬇ Down
$ bundle exec rails db:migrate:down VERSION=20210713042153
== 20210713042153 FinalizeCiSourcesPipelinesBigintConversion: reverting =======
-- transaction_open?()
-> 0.0000s
-- index_exists?("ci_sources_pipelines", :source_job_id_convert_to_bigint, {:name=>"index_ci_sources_pipelines_on_source_job_id_convert_to_bigint", :algorithm=>:concurrently})
-> 0.0043s
-- execute("SET statement_timeout TO 0")
-> 0.0006s
-- add_index("ci_sources_pipelines", :source_job_id_convert_to_bigint, {:name=>"index_ci_sources_pipelines_on_source_job_id_convert_to_bigint", :algorithm=>:concurrently})
-> 0.0039s
-- execute("RESET ALL")
-> 0.0007s
-- transaction_open?()
-> 0.0000s
-- foreign_keys("ci_sources_pipelines")
-> 0.0043s
-- execute("LOCK TABLE ci_builds, ci_sources_pipelines IN SHARE ROW EXCLUSIVE MODE")
-> 0.0008s
-- execute("ALTER TABLE ci_sources_pipelines\nADD CONSTRAINT fk_be5624bf37_tmp\nFOREIGN KEY (source_job_id_convert_to_bigint)\nREFERENCES ci_builds (id)\nON DELETE CASCADE\nNOT VALID;\n")
-> 0.0019s
-- execute("ALTER TABLE ci_sources_pipelines VALIDATE CONSTRAINT fk_be5624bf37_tmp;")
-> 0.0069s
-- execute("LOCK TABLE ci_builds, ci_sources_pipelines IN ACCESS EXCLUSIVE MODE")
-> 0.0009s
-- quote_table_name("ci_sources_pipelines")
-> 0.0000s
-- quote_column_name(:source_job_id)
-> 0.0000s
-- quote_column_name("source_job_id_tmp")
-> 0.0000s
-- execute("ALTER TABLE \"ci_sources_pipelines\" RENAME COLUMN \"source_job_id\" TO \"source_job_id_tmp\"")
-> 0.0009s
-- quote_table_name("ci_sources_pipelines")
-> 0.0000s
-- quote_column_name(:source_job_id_convert_to_bigint)
-> 0.0000s
-- quote_column_name(:source_job_id)
-> 0.0000s
-- execute("ALTER TABLE \"ci_sources_pipelines\" RENAME COLUMN \"source_job_id_convert_to_bigint\" TO \"source_job_id\"")
-> 0.0008s
-- quote_table_name("ci_sources_pipelines")
-> 0.0000s
-- quote_column_name("source_job_id_tmp")
-> 0.0000s
-- quote_column_name(:source_job_id_convert_to_bigint)
-> 0.0000s
-- execute("ALTER TABLE \"ci_sources_pipelines\" RENAME COLUMN \"source_job_id_tmp\" TO \"source_job_id_convert_to_bigint\"")
-> 0.0009s
-- quote_table_name("trigger_8485e97c00e3")
-> 0.0000s
-- execute("ALTER FUNCTION \"trigger_8485e97c00e3\" RESET ALL")
-> 0.0009s
-- execute("DROP INDEX index_ci_sources_pipelines_on_source_job_id")
-> 0.0010s
-- rename_index("ci_sources_pipelines", "index_ci_sources_pipelines_on_source_job_id_convert_to_bigint", "index_ci_sources_pipelines_on_source_job_id")
-> 0.0008s
-- remove_foreign_key("ci_sources_pipelines", {:name=>"fk_be5624bf37"})
-> 0.0044s
-- quote_table_name("ci_sources_pipelines")
-> 0.0000s
-- quote_column_name("fk_be5624bf37_tmp")
-> 0.0000s
-- quote_column_name("fk_be5624bf37")
-> 0.0000s
-- execute("ALTER TABLE \"ci_sources_pipelines\"\nRENAME CONSTRAINT \"fk_be5624bf37_tmp\" TO \"fk_be5624bf37\"\n")
-> 0.0007s
== 20210713042153 FinalizeCiSourcesPipelinesBigintConversion: reverted (0.0547s)
[
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