Database migrations failed for upgrade from 18.1.2 to 18.2.0
Summary
Database migrations failed for upgrade from 18.1.2 to 18.2.0.
Logs show the following migrations started:
- AddBulkImportConfigurationsOrganizationIdNotNull
- AddForeignKeyToAiActiveContextCodeEnabledNamespaces
- AddIncidentManagementPendingAlertEscalationsProjectIdNotNull
- AddIssuableResourceLinksNamespaceIdNotNull
- AddSentryIssuesNamespaceIdNotNull
- CreateAiActiveContextCodeEnabledNamespaces
- FinalizeBackfillIssueCustomerRelationsContactsNamespaceId
and the following completed:
- AddBulkImportConfigurationsOrganizationIdNotNull
- AddIncidentManagementPendingAlertEscalationsProjectIdNotNull
- AddIssuableResourceLinksNamespaceIdNotNull
- AddSentryIssuesNamespaceIdNotNull
- CreateAiActiveContextCodeEnabledNamespaces
- FinalizeBackfillIssueCustomerRelationsContactsNamespaceId
suggesting that AddForeignKeyToAiActiveContextCodeEnabledNamespaces did not complete.
Using gitlab-rails dbconsole I got the further information
command:
select state, state_change, wait_event_type, query from pg_stat_activity where pid = (SELECT pid FROM pg_locks WHERE locktype = 'advisory');
result:
active | 2025-07-21 10:35:00.354397+00 | Lock | /application:web,db_config_database:gitlabhq_production,db_config_name:main/ C REATE INDEX CONCURRENTLY "index_dts_on_expiring_at_seven_days_notification_sent_at" ON "deploy_tokens" ("expires_at", "id") WHERE revoked = false AND seven_days_notification_sent_at IS NULL
This suggests a different migration from the above.
The related migrations are:
- https://gitlab.com/gitlab-org/gitlab/-/blob/master/db/migrate/20250530110142_add_foreign_key_to_ai_active_context_code_enabled_namespaces.rb
- https://gitlab.com/gitlab-org/gitlab/-/blob/master/db/migrate/20250531094235_add_indices_for_deploy_token_expiry_columns.rb
Steps to reproduce
Unable to reproduce in a development environment.
What is the current bug behavior?
Migrations job fails.
What is the expected correct behavior?
Migration job should finish within minutes.