Skip to content

Fix CI schema diverging from main schema in test

Stan Hu requested to merge sh-fix-ci-test-schema-leaking into master

What does this MR do and why?

We ran into an order-dependent test failure when update_ci_pipeline_artifacts_unknown_locked_status_spec.rb were run after change_public_projects_cost_factor_spec.rb.

Previously when spec/migrations/change_public_projects_cost_factor_spec.rb ran, the call to schema_migrate_down! would alter the schema of the CI database without altering the schema of the main database due to the migration: :gitlab_ci tag. This happens because inspec/support/database/multiple_databases.rb, the ActiveRecord::Base is reconfigured to point to the CI config.

As a result, schema_migrate_down! causes the main and CI databases to diverge, with the latter being in an older state (20220610140605).

This caused the ci_pipeline_artifacts.locked column to be missing, causing the test in https://gitlab.com/gitlab-org/gitlab/-/jobs/3126090535 to fail.

Calling schema_migrate_up! in another migration had no effect because the main database would be in the latest state, and no migrations would appear to be be needed.

However, calling schema_migrate_up! in a spec that had migration: :gitlab_ci eliminates the discrepancy between main and CI databases.

How to set up and validate locally

bundle exec rspec spec/migrations/change_public_projects_cost_factor_spec.rb spec/lib/gitlab/background_migration/update_ci_pipeline_artifacts_unknown_locked_status_spec.rb

MR acceptance checklist

This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.

Edited by Stan Hu

Merge request reports