# Self-Healing CI: Recovering a Database Failover During Migration

> A migration step that fails because the database failed over to a new primary is a transient infrastructure event, not a bad migration. See the manual fix and how self-healing CI reconnects and retries.

Source: https://latchkey.dev/learn/self-healing-ci/self-healing-db-failover-during-migration  
Updated: 2026-06-26

A migration that drops its connection because the database failed over is an infrastructure event, not a bad migration -- reconnecting to the new primary and retrying an idempotent migration completes it.

## What makes a failure safely retryable

Automatic retry is only correct for failures that are genuinely transient. Retrying a deterministic failure wastes minutes and hides a real defect, so the classification matters more than the retry mechanism.

- Safe to retry: network timeouts, registry 5xx, transient DNS failures, a service container that was not ready, a spot instance reclaimed mid-run.
- Not safe to retry: assertion failures, compile errors, lint violations, anything that fails identically on every attempt.
- Ambiguous, and worth investigating rather than retrying: out-of-memory kills, disk exhaustion, and flaky tests. These repeat under load and a retry only hides the trend.
- Always record that a retry happened. A pipeline that silently retries is a pipeline whose real failure rate you do not know.

## FAQ

### What causes Self-Healing CI: recovering a database failover during migration?

A migration step fails because the managed database failed over to a new primary mid-run, dropping the connection or briefly going read-only. The migration itself is valid; a failover event interrupted it. A human re-runs after the new primary is promoted and an idempotent migration completes unchanged.

### How do I fix Self-Healing CI: recovering a database failover during migration manually?

[object Object]

### Can Self-Healing CI: recovering a database failover during migration be fixed automatically?

A failover during migration has a recognizable transient signature -- a dropped connection or a momentary read-only state during a promotion, not a SQL/logic error in the migration -- and the safe response is to reconnect to the new primary and retry an idempotent migration.

---

Latchkey runs CI/CD that repairs its own failures. Agent entry points: https://latchkey.dev/agent.txt, https://latchkey.dev/openapi.json, https://latchkey.dev/llms.txt
