Validate check_organization_id_nullness constraint checks
NOTE: This MR is set to only merge after %18.5 is released, but I want to start reviews since I'll be on PTO for a large portion of %18.6.
What does this MR do and why?
This MR validates the check_organization_id_nullness constraint checks that were previously added as NOT VALID constraints. This is a follow-up to the work done in #523851 (closed), completing the multi-step process of adding organization_id constraints to CI runner-related tables.
The validation step ensures that all existing data complies with the constraint rules before enforcing them on new data. This is done in milestone 18.6, one milestone after the initial constraint addition. The validation for each of the project/group partitions take at most 5 seconds, which is still under the limit of 10 minutes for PDMs.
Tables affected:
-
instance_type_ci_runners/group_type_ci_runners/project_type_ci_runners -
instance_type_ci_runner_machines/group_type_ci_runner_machines/project_type_ci_runner_machines -
ci_runner_taggings_instance_type/ci_runner_taggings_group_type/ci_runner_taggings_project_type
Constraint rules:
- Instance-type tables:
organization_id IS NULL - Group-type and project-type tables:
organization_id IS NOT NULL
Closes #523852 (closed)
Changelog: other
Database migrations
This MR includes three post-deployment migrations that validate the constraints:
-
ValidateCiRunnersOrganizationIdNullConstraint- validates constraints on runner tables -
ValidateCiRunnerMachinesOrganizationIdNullConstraint- validates constraints on runner machine tables -
ValidateCiRunnerTaggingsOrganizationIdNullConstraint- validates constraints on runner tagging tables
Each migration uses with_lock_retries to minimize lock contention and validates the constraint for all three runner types (instance, group, project).
How to set up and validate locally
- Ensure the previous migration from #523851 (closed) has been applied
- Run the post-deployment migrations:
bundle exec rails db:migrate RAILS_ENV=test - Verify the constraints are now validated in the database:
All constraints should show
gdk psql -d gitlabhq_test_ci -c "SELECT conname, convalidated FROM pg_constraint WHERE conname = 'check_organization_id_nullness';"convalidated = true
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.