← LeaderboardThe Skill Leaderboard
rust-sqlx-migration-checksums
Repair SQLx migration checksum mismatches. Recover the applied SQL text, add a new migration, and verify both upgrade and fresh SQLite databases.
Try your first task
A source-grounded starter task has not been verified for this skill yet.
SKILL.md
name: rust-sqlx-migration-checksumsdescription: Repair SQLx migration checksum mismatches. Recover the applied SQL text, add a new migration, and verify both upgrade and fresh SQLite databases.category: databaserisk: criticalsource: selfsource_type: selfdate_added: "2026-12-02"author: ShianMiketags: [rust, sqlx, sqlite, migrations, checksums]Rust SQLx Migration Checksums
When to Use
- SQLx reports a migration version mismatch after a previously applied file was edited.
- A migration set succeeds on a fresh database but fails on an existing installation.
- A schema change must preserve existing data and keep migration history consistent.
Prerequisites
- The application or CLI version running SQLx, its effective migration directory or embedded source, and the database backend.
- The deployed copy of the affected migration or the release revision containing it.
- A disposable database or restored test copy and a representative existing row.
1. Resolve the source history
- Record the error variant and version.
VersionMismatch(version)means SQLx found the applied version with a different checksum. - Identify the source the failing process actually sees. A binary using
sqlx::migrate!can carry migrations from an earlier build. - Compare the existing history with deployed source text. Comments and whitespace edits can change the checksum even when they have no schema effect.
- Use read-only inspection of migration history when available. The migration table can confirm a stored checksum but cannot recover the original SQL.
2. Restore the applied version and move forward
- Restore the exact SQL that was applied from a known release or backup.
- Write the intended change as a new migration with a version ordered after the existing migrations. Use the repository's naming and transaction conventions.
- Verify the intended schema transition against the previously deployed shape and data.
- If the deployed version cannot be recovered, or environments already have different checksums for that version, gather their histories and establish a recovery plan before running changes.
3. Verify the replay paths
- Apply the original migration and insert a known row in a disposable database.
- Run the repaired set against that database and assert existing rows survive with the expected new schema.
- Apply the repaired set to a fresh database and compare coverage. Run it again on the upgraded database to confirm already-applied versions are skipped.
- Check the resulting migration records, application-visible data, and any pending migrations before deploying the repaired set.
Example
Run Restore migration history and add a version. It verifies a checksum mismatch for a comment-only edit, then checks a forward migration on upgrade and fresh-install paths.
Limitations
- The fixture runs SQLx with an in-memory SQLite database. Locking and transaction behavior for other backends require separate validation.
- Restoration depends on a trustworthy copy of the original migration. Divergent deployed histories need reconciliation matched to those databases.
Safety and Side Effects
- Run the example in a scratch Cargo project. It creates temporary migration files and writes only to in-memory databases.
- A real migration can change data or schema. Validate against a test copy and the actual backup and deployment procedure. Preserve applied migration history while diagnosing.