Convert ci_builds_runner_session.build_id to bigint - Step 1: Add new columns and sync data
The ci_builds_runner_session
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_builds_runner_session
Table "public.ci_builds_runner_session"
Column | Type | Collation | Nullable | Default
---------------+-------------------+-----------+----------+------------------------------------------------------
...
build_id | integer | | not null |
...
Indexes:
"index_ci_builds_runner_session_on_build_id" UNIQUE, btree (build_id)
Foreign-key constraints:
"fk_rails_70707857d3" 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_builds_runner_session
table will be as follows:
- Create a new column
ci_builds_runner_session.build_id_convert_to_bigint
for 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_id
values 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