Database Migration failing from 17.11.2 to 18.0.1 due to PG::CheckViolation check_4fab85ecdc
Summary
In some cases, environments upgraded from 17.11.X to 18.0.Y may encounter this migration error.
PG::CheckViolation: ERROR: check constraint "check_4fab85ecdc" of relation "ci_build_needs" is violated by some row
Steps to reproduce
- We haven't been able to re-create this on demand yet.
Example Project
What is the current bug behavior?
Migration fails to proceed.
What is the expected correct behavior?
Migration should not fail.
Relevant logs and/or screenshots
Output of checks
Results of GitLab environment info
Expand for output related to GitLab environment info
(For installations with omnibus-gitlab package run and paste the output of: `sudo gitlab-rake gitlab:env:info`) (For installations from source run and paste the output of: `sudo -u git -H bundle exec rake gitlab:env:info RAILS_ENV=production`)
Results of GitLab application Check
Expand for output related to the GitLab application check
(For installations with omnibus-gitlab package run and paste the output of:
sudo gitlab-rake gitlab:check SANITIZE=true)(For installations from source run and paste the output of:
sudo -u git -H bundle exec rake gitlab:check RAILS_ENV=production SANITIZE=true)(we will only investigate if the tests are passing)
Workaround
- Check if there are rows violating this constraint.
select count(*) from ci_build_needs where project_id is null;
select * from ci_build_needs where project_id is null limit 1;
- If one or more rows are affected, we can backfill them manually using this.
UPDATE ci_build_needs
SET project_id = ci_builds.project_id
FROM ci_builds
WHERE ci_build_needs.build_id = ci_builds.id
AND ci_build_needs.project_id IS NULL;
- Validate that there are no more rows affected.
select count(*) from ci_build_needs where project_id is null;
- Re-attempt the migration by running
gitlab-rake db:migrate.
Patch release information for backports
If the bug fix needs to be backported in a patch release to a version under the maintenance policy, please follow the steps on the patch release runbook for GitLab engineers.
Refer to the internal "Release Information" dashboard for information about the next patch release, including the targeted versions, expected release date, and current status.
High-severity bug remediation
To remediate high-severity issues requiring an internal release for single-tenant SaaS instances, refer to the internal release process for engineers.