M Add sharding key YAML config to p_ci_pipeline_variables (1 table)
What we need to do
The p_ci_pipeline_variables
table has a pipeline_id
column so we could look into the project_id
from a Ci::Pipeline
to identify the correct sharding key here and backfill the data accordingly.
How to do it
-
Read https://docs.gitlab.com/ee/development/cells/#define-a-desired_sharding_key-to-automatically-backfill-a-sharding_key -
Modify https://gitlab.com/gitlab-org/gitlab/-/blob/master/db/docs/ci_pipeline_variables.yml -
Create all necessary migrations as we did in daed28a6 -
Mark the migration as finalize -
Validate the constraint -
Set sharding key in dictionary
# db/post_migrate/...
class FinalizeBackfillPCiPipelineVariablesProjectId < Gitlab::Database::Migration[2.2]
milestone '17.6'
MIGRATION = 'BackfillPCiPipelineVariablesProjectId'
disable_ddl_transaction!
restrict_gitlab_migration gitlab_schema: :gitlab_ci
def up
ensure_batched_background_migration_is_finished(
job_class_name: MIGRATION,
table_name: :p_ci_pipeline_variables,
column_name: :id,
job_arguments: [
:project_id,
:p_ci_pipelines,
:project_id,
:pipeline_id,
:partition_id
],
finalize: true
)
end
def down
# no-op
end
end
# db/post_migrate/...
# frozen_string_literal: true
class ValidatePCiPipelineVariablesProjectIdNullConstraint < Gitlab::Database::Migration[2.2]
milestone '17.6'
disable_ddl_transaction!
TABLE_NAME = :p_ci_pipeline_variables
COLUMN_NAME = :project_id
CONSTRAINT_NAME = :check_6e932dbabf
def up
add_not_null_constraint(TABLE_NAME, COLUMN_NAME, constraint_name: CONSTRAINT_NAME)
end
def down
remove_not_null_constraint(TABLE_NAME, COLUMN_NAME, constraint_name: CONSTRAINT_NAME)
add_not_null_constraint(TABLE_NAME, COLUMN_NAME, constraint_name: CONSTRAINT_NAME, validate: false)
end
end
Edited by Max Orefice