Skip to content

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:

  1. Ensure the migration of source_job_id to bigint is completed.
  2. Copy index and FK
  3. 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:

  1. 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

  2. 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

Availability and Testing

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
Edited by Krasimir Angelov

Merge request reports

Loading