Skip to content

Convert ci_sources_pipelines.source_job_id to bigint - Step 1: Add new columns and sync data

The ci_sources_pipelines 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_sources_pipelines
                                  Table "public.ci_sources_pipelines"
       Column       |  Type   | Collation | Nullable |                     Default
--------------------+---------+-----------+----------+--------------------------------------------------
... ... ...
 source_job_id      | integer |           |          |
... ... ...
Indexes:
    "index_ci_sources_pipelines_on_source_job_id" btree (source_job_id)
Foreign-key constraints:
    "fk_be5624bf37" FOREIGN KEY (source_job_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 source_job_id column to it and keep them in sync with a trigger.

The overall process for the ci_sources_pipelines table will be as follows:

  • Create a new column ci_sources_pipelines.source_job_id_convert_to_bigint for the Foreign Key that references ci_builds
  • 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 source_job_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