Problem with upgrading to 17.1 due to epics.issue_id constraint
We got reports from support and also in an issue omnibus-gitlab#8596 that upgrading to 17.1 failed. They all have one thing in common:
ActiveRecord::StatementInvalid: PG::CheckViolation: ERROR: check constraint "check_450724d1bb" of relation "epics" is violated by some row
This is a constrained introduced in 17.1 to ensure that every epic has a work item, which was added in !154956 (merged).
Current status
Problem identified and fix prepared for the next patch of 17.1: !157608 (merged).
Problem
As described in #468875 (comment 1966101718) finalizing the job in 17.1 had a bug. The upgrade to 17.1 therefore stops when introducing the constraint. This affects instances where the background migration didn't run through in 17.0. E.g. when upgrading directly from 16.x to 17.1.
Temporary fix
The following finalizes the migration manually and can either be run in 17.0 or while upgrading to 17.1. It allows to continue moving forward with the upgrade of 17.1 as the constraint can be set.
Rake task
sudo gitlab-rake gitlab:background_migrations:finalize[BackfillEpicBasicFieldsToWorkItemRecord,epics,id,'[null]']
Rails console
load 'db/post_migrate/20240503103337_queue_backfill_epic_basic_fields_to_work_item_record.rb'
QueueBackfillEpicBasicFieldsToWorkItemRecord.new.ensure_batched_background_migration_is_finished(job_class_name: 'BackfillEpicBasicFieldsToWorkItemRecord', table_name: 'epics', column_name: 'id', job_arguments: [nil], finalize: true)