Convert ci_build_trace_chunks.build_id to bigint - Step 1: Add new columns and sync data
The ci_build_trace_chunks table is one of the CI tables that reference ci_builds, which we want to convert as it's Primary Key is at risk of overflowing.
gitlabhq_production=> \d ci_build_trace_chunks
Table "public.ci_build_trace_chunks"
Column | Type | Collation | Nullable | Default
--------------+---------+-----------+----------+---------------------------------------------------
...
build_id | integer | | not null |
...
Indexes:
...
"index_ci_build_trace_chunks_on_build_id_and_chunk_index" UNIQUE, btree (build_id, chunk_index)
Foreign-key constraints:
"fk_rails_1013b761f2" FOREIGN KEY (build_id) REFERENCES ci_builds(id) ON DELETE CASCADE
The first step to address the problem is to create a new column of type bigint, load all the data by using background jobs from the current build_id column to it and keep them in sync with a trigger.
The overall process for the ci_build_trace_chunks table will be as follows:
- Create a new column
ci_build_trace_chunks.build_id_convert_to_bigintfor the Foreign Key that referencesci_builds, withbigint NOT NULL DEFAULT 0 - Install sync triggers to keep the new columns updated while new records are inserted or existing ones are updated or deleted.
- Start background jobs that will batch through the whole table and copy the
build_idvalues to the new column.
We'll follow with a cleanup migration in the next milestone than the one that the aforementioned migrations are deployed, which will add the necessary indexes, swap the PK (and its sequence) and the FKs and finally drop the old columns.
Edited by Yannis Roussos