Skip to content

Finalize conversion to bigint for ci_build_trace_chunks

What does this MR do?

This MR finalize the conversion to bigint for ci_build_trace_chunks table.

At a high level, the operation takes the following steps:

  1. Ensure the migration of build_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 #328443 (closed).

Database migrations

Timings

From DB Lab:

  1. CREATE UNIQUE INDEX CONCURRENTLY "i_ci_build_trace_chunks_build_id_convert_to_bigint_chunk_index" ON "ci_build_trace_chunks" ("build_id_convert_to_bigint", "chunk_index")

    Duration: 1.017 s - https://console.postgres.ai/gitlab/gitlab-production-tunnel-pg12/sessions/5170/commands/18264

  2. ALTER TABLE ci_build_trace_chunks VALIDATE CONSTRAINT ....

    Duration: 5.609 s - https://console.postgres.ai/gitlab/gitlab-production-tunnel-pg12/sessions/5170/commands/18268

Output

Up
$ bundle exec rails db:migrate:up VERSION=20210714015537
== 20210714015537 FinalizeCiBuildTraceChunksBigintConversion: migrating =======
-- transaction_open?()
   -> 0.0000s
-- index_exists?("ci_build_trace_chunks", [:build_id_convert_to_bigint, :chunk_index], {:unique=>true, :name=>"i_ci_build_trace_chunks_build_id_convert_to_bigint_chunk_index", :algorithm=>:concurrently})
   -> 0.0020s
-- execute("SET statement_timeout TO 0")
   -> 0.0005s
-- add_index("ci_build_trace_chunks", [:build_id_convert_to_bigint, :chunk_index], {:unique=>true, :name=>"i_ci_build_trace_chunks_build_id_convert_to_bigint_chunk_index", :algorithm=>:concurrently})
   -> 0.0056s
-- execute("RESET ALL")
   -> 0.0005s
-- transaction_open?()
   -> 0.0000s
-- foreign_keys("ci_build_trace_chunks")
   -> 0.0032s
-- execute("ALTER TABLE ci_build_trace_chunks\nADD CONSTRAINT fk_rails_1013b761f2_tmp\nFOREIGN KEY (build_id_convert_to_bigint)\nREFERENCES ci_builds (id)\nON DELETE CASCADE\nNOT VALID;\n")
   -> 0.0020s
-- execute("ALTER TABLE ci_build_trace_chunks VALIDATE CONSTRAINT fk_rails_1013b761f2_tmp;")
   -> 0.0073s
-- execute("LOCK TABLE ci_build_trace_chunks, ci_builds IN ACCESS EXCLUSIVE MODE")
   -> 0.0005s
-- quote_table_name("ci_build_trace_chunks")
   -> 0.0000s
-- quote_column_name(:build_id)
   -> 0.0000s
-- quote_column_name("build_id_tmp")
   -> 0.0000s
-- execute("ALTER TABLE \"ci_build_trace_chunks\" RENAME COLUMN \"build_id\" TO \"build_id_tmp\"")
   -> 0.0006s
-- quote_table_name("ci_build_trace_chunks")
   -> 0.0000s
-- quote_column_name(:build_id_convert_to_bigint)
   -> 0.0000s
-- quote_column_name(:build_id)
   -> 0.0000s
-- execute("ALTER TABLE \"ci_build_trace_chunks\" RENAME COLUMN \"build_id_convert_to_bigint\" TO \"build_id\"")
   -> 0.0006s
-- quote_table_name("ci_build_trace_chunks")
   -> 0.0000s
-- quote_column_name("build_id_tmp")
   -> 0.0000s
-- quote_column_name(:build_id_convert_to_bigint)
   -> 0.0000s
-- execute("ALTER TABLE \"ci_build_trace_chunks\" RENAME COLUMN \"build_id_tmp\" TO \"build_id_convert_to_bigint\"")
   -> 0.0006s
-- quote_table_name("trigger_cf2f9e35f002")
   -> 0.0000s
-- execute("ALTER FUNCTION \"trigger_cf2f9e35f002\" RESET ALL")
   -> 0.0006s
-- change_column_default("ci_build_trace_chunks", :build_id, nil)
   -> 0.0032s
-- change_column_default("ci_build_trace_chunks", :build_id_convert_to_bigint, 0)
   -> 0.0026s
-- execute("DROP INDEX index_ci_build_trace_chunks_on_build_id_and_chunk_index")
   -> 0.0008s
-- rename_index("ci_build_trace_chunks", "i_ci_build_trace_chunks_build_id_convert_to_bigint_chunk_index", "index_ci_build_trace_chunks_on_build_id_and_chunk_index")
   -> 0.0007s
-- remove_foreign_key("ci_build_trace_chunks", {:name=>"fk_rails_1013b761f2"})
   -> 0.0053s
-- quote_table_name("ci_build_trace_chunks")
   -> 0.0000s
-- quote_column_name("fk_rails_1013b761f2_tmp")
   -> 0.0000s
-- quote_column_name("fk_rails_1013b761f2")
   -> 0.0000s
-- execute("ALTER TABLE \"ci_build_trace_chunks\"\nRENAME CONSTRAINT \"fk_rails_1013b761f2_tmp\" TO \"fk_rails_1013b761f2\"\n")
   -> 0.0006s
== 20210714015537 FinalizeCiBuildTraceChunksBigintConversion: migrated (0.0645s) 
Down
$ bundle exec rails db:migrate:down VERSION=20210714015537
== 20210714015537 FinalizeCiBuildTraceChunksBigintConversion: reverting =======
-- transaction_open?()
   -> 0.0000s
-- index_exists?("ci_build_trace_chunks", [:build_id_convert_to_bigint, :chunk_index], {:unique=>true, :name=>"i_ci_build_trace_chunks_build_id_convert_to_bigint_chunk_index", :algorithm=>:concurrently})
   -> 0.0025s
-- execute("SET statement_timeout TO 0")
   -> 0.0006s
-- add_index("ci_build_trace_chunks", [:build_id_convert_to_bigint, :chunk_index], {:unique=>true, :name=>"i_ci_build_trace_chunks_build_id_convert_to_bigint_chunk_index", :algorithm=>:concurrently})
   -> 0.0034s
-- execute("RESET ALL")
   -> 0.0006s
-- transaction_open?()
   -> 0.0000s
-- foreign_keys("ci_build_trace_chunks")
   -> 0.0028s
-- execute("ALTER TABLE ci_build_trace_chunks\nADD CONSTRAINT fk_rails_1013b761f2_tmp\nFOREIGN KEY (build_id_convert_to_bigint)\nREFERENCES ci_builds (id)\nON DELETE CASCADE\nNOT VALID;\n")
   -> 0.0020s
-- execute("ALTER TABLE ci_build_trace_chunks VALIDATE CONSTRAINT fk_rails_1013b761f2_tmp;")
   -> 0.0040s
-- execute("LOCK TABLE ci_build_trace_chunks, ci_builds IN ACCESS EXCLUSIVE MODE")
   -> 0.0005s
-- quote_table_name("ci_build_trace_chunks")
   -> 0.0000s
-- quote_column_name(:build_id)
   -> 0.0000s
-- quote_column_name("build_id_tmp")
   -> 0.0000s
-- execute("ALTER TABLE \"ci_build_trace_chunks\" RENAME COLUMN \"build_id\" TO \"build_id_tmp\"")
   -> 0.0008s
-- quote_table_name("ci_build_trace_chunks")
   -> 0.0000s
-- quote_column_name(:build_id_convert_to_bigint)
   -> 0.0000s
-- quote_column_name(:build_id)
   -> 0.0000s
-- execute("ALTER TABLE \"ci_build_trace_chunks\" RENAME COLUMN \"build_id_convert_to_bigint\" TO \"build_id\"")
   -> 0.0007s
-- quote_table_name("ci_build_trace_chunks")
   -> 0.0000s
-- quote_column_name("build_id_tmp")
   -> 0.0000s
-- quote_column_name(:build_id_convert_to_bigint)
   -> 0.0000s
-- execute("ALTER TABLE \"ci_build_trace_chunks\" RENAME COLUMN \"build_id_tmp\" TO \"build_id_convert_to_bigint\"")
   -> 0.0006s
-- quote_table_name("trigger_cf2f9e35f002")
   -> 0.0000s
-- execute("ALTER FUNCTION \"trigger_cf2f9e35f002\" RESET ALL")
   -> 0.0007s
-- change_column_default("ci_build_trace_chunks", :build_id, nil)
   -> 0.0021s
-- change_column_default("ci_build_trace_chunks", :build_id_convert_to_bigint, 0)
   -> 0.0018s
-- execute("DROP INDEX index_ci_build_trace_chunks_on_build_id_and_chunk_index")
   -> 0.0008s
-- rename_index("ci_build_trace_chunks", "i_ci_build_trace_chunks_build_id_convert_to_bigint_chunk_index", "index_ci_build_trace_chunks_on_build_id_and_chunk_index")
   -> 0.0007s
-- remove_foreign_key("ci_build_trace_chunks", {:name=>"fk_rails_1013b761f2"})
   -> 0.0032s
-- quote_table_name("ci_build_trace_chunks")
   -> 0.0000s
-- quote_column_name("fk_rails_1013b761f2_tmp")
   -> 0.0000s
-- quote_column_name("fk_rails_1013b761f2")
   -> 0.0000s
-- execute("ALTER TABLE \"ci_build_trace_chunks\"\nRENAME CONSTRAINT \"fk_rails_1013b761f2_tmp\" TO \"fk_rails_1013b761f2\"\n")
   -> 0.0006s
== 20210714015537 FinalizeCiBuildTraceChunksBigintConversion: reverted (0.0415s) 

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

Related to #328443 (closed)

Edited by Krasimir Angelov

Merge request reports

Loading