Skip to content

Sync create indexes and prepare FK for p_ci_builds auto_canceled_by_id

Tianwen Chen requested to merge 422835-sync-index-creation1 into master

What does this MR do and why?

Sync create indexes and prepare FK for p_ci_builds

This is the second step to synchronously create indexes and prepare foreign keys for p_ci_builds

See https://docs.gitlab.com/ee/development/database/adding_database_indexes.html#add-a-migration-to-create-the-index-synchronously

The corresponding indexes are created asynchronously from MR !142476 (merged)

  • For gitlab_partitions_dynamic.ci_builds_101:

    • "index_be05aa07e1" btree (auto_canceled_by_id_convert_to_bigint) WHERE auto_canceled_by_id_convert_to_bigint IS NOT NULL
    • "index_277b4d8f5f" btree (commit_id_convert_to_bigint, status, type)
    • "index_3f8c3dace0" btree (commit_id_convert_to_bigint, type, name, ref)
  • For ci_builds:

    • "index_ffe1233676" btree (auto_canceled_by_id_convert_to_bigint) WHERE auto_canceled_by_id_convert_to_bigint IS NOT NULL
    • "index_8c07a79c70" btree (commit_id_convert_to_bigint, status, type)
    • "index_feafb4d370" btree (commit_id_convert_to_bigint, type, name, ref)

MR acceptance checklist

Please evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.

Screenshots or screen recordings

Screenshots are required for UI changes, and strongly recommended for all other merge requests.

Before After

How to set up and validate locally

  1. Run the following commands:

    ./scripts/regenerate-schema
    RAILS_ENV=test bin/rails runner 'Feature.enable :database_async_foreign_key_validation'
    RAILS_ENV=test bin/rails runner 'Feature.enable :ci_current_partition_value_101'
    RAILS_ENV=test bin/rake gitlab:db:validate_async_constraints:all
  2. Confirm the following foreign keys are created and validated in TEST environment

    psql gitlabhq_test -h $PATH_TO_POSTGRESQL/gitlab-development-kit/postgresql
    \d ci_builds
    "fk_dd3c83bdee" FOREIGN KEY (auto_canceled_by_id_convert_to_bigint) REFERENCES ci_pipelines(id) ON DELETE SET NULL
    \d gitlab_partitions_dynamic.ci_builds_101
    "fk_dd3c83bdee" FOREIGN KEY (auto_canceled_by_id_convert_to_bigint) REFERENCES ci_pipelines(id) ON DELETE SET NULL
  3. Run the following commands to restore the feature flag:

    RAILS_ENV=test bin/rails runner 'Feature.disable :ci_current_partition_value_101'
    RAILS_ENV=test bin/rails runner 'Feature.disable :database_async_foreign_key_validation'

Related to #422835 (closed) #422836 (closed)

Edited by Tianwen Chen

Merge request reports