Create partitioned table p_ci_build_needs

What does this MR do and why?

This MR converts the ci_build_needs table to a list-partitioned table as part of the CI data partitioning initiative. It creates the parent partitioned table p_ci_build_needs and attaches the existing ci_build_needs table as its first partition (covering partition_id values 100–111).

Key changes:

  • Model update: Sets sequence_name on Ci::BuildNeed to explicitly use ci_build_needs_id_seq, ensuring correct sequence ownership after the parent table takes over.
  • Post-migration: Sync constraint (20260326000459): Validates the existing partitioning_constraint check constraint on ci_build_needs before the conversion.
  • Post-migration: Drop old unique index (20260326000462): Removes the legacy index_ci_build_needs_on_build_id_and_name index (non-partition-aware) from ci_build_needs, replaced by the partition-aware index_ci_build_needs_on_build_id_and_name_partitioning.
  • Post-migration: Convert to list partition (20260326000464): Calls convert_table_to_first_list_partition to create p_ci_build_needs as the partitioned parent and attach ci_build_needs as the first partition for values 100–111.
  • Schema updates: Reflects the new parent table p_ci_build_needs with PARTITION BY LIST (partition_id), updated primary key, indexes, and foreign key constraints.
  • Bump sequences fix: Adds .uniq to sequences_by_gitlab_schema to avoid duplicate sequence entries that could arise when both the parent and child tables reference the same sequence.
  • Spec/sharding key updates: Registers p_ci_build_needs in the schema spec and sharding key spec, noting that the LFK is already covered via cascade delete from p_ci_builds.
  • DB docs: Adds db/docs/p_ci_build_needs.yml documenting the new table with its sharding key, feature category, and schema.

Changelog: added

References

Related to #583639 (closed)

Screenshots or screen recordings

N/A – database migration only

How to set up and validate locally

  1. Run the post-migrations in order:
    bundle exec rails db:migrate:up VERSION=20260326000459
    bundle exec rails db:migrate:up VERSION=20260326000462
    bundle exec rails db:migrate:up VERSION=20260326000464
  2. Verify the parent table exists and the partition is attached:
    \d+ p_ci_build_needs
  3. Confirm ci_build_needs is listed as a partition of p_ci_build_needs for values 100–111.
  4. Run rollback to verify down migrations work correctly.

MR acceptance checklist

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

Edited by Marius Bobin

Merge request reports

Loading
Loading