zakariaf/flutter-skills/run-migration
Claude Code and agent skill by zakariaf/flutter-skills
- community
Checking that the SKILL.md file is still in the repository.
Runs the forward-only Drift/SQLite schema-migration ritual — the most dangerous deterministic operation in an offline-first app: a bad migration silently destroys on-device rows that exist nowhere else. Enforces the exact ordered sequence: take a pre-migration file snapshot before the database is opened, bump schemaVersion by exactly one, write an append-only stepByStep forward step (never edit a shipped step, never write a down migration), commit the drift_dev make-migrations schema snapshot, regenerate, then prove it with tests covering every from→to path (incl. multi-version jumps), a write-at-v(n)/read-at-v(n+1) content test, PRAGMA integrity_check + foreign_key_check, and a forced mid-migration throw that restores the snapshot. Manual, side-effecting workflow. Use when adding or altering a Drift table, column, index, or CHECK; bumping schemaVersion; editing onUpgrade/stepByStep; or writing migration tests.
Install
npx vskill@latest install zakariaf/flutter-skills/run-migrationSKILL.md
The same SKILL.md was published earlier as zakariaf/flutter-skills/run-migration.
Run migration (forward-only Drift schema migration)
Apply a schema change to a local Drift/SQLite database by following the exact ordered ritual below. In an offline-first app there is no server and no re-sync path, so the on-device DB is the single source of truth: a migration that drops or corrupts a column permanently destroys hand-entered records that exist nowhere else, and with no telemetry nobody ever reports it — the user just uninstalls. This is a manual, low-freedom, human-run workflow. Execute the steps in order; do not improvise, reorder, or skip.
Non-negotiable rules
- Take the pre-migration snapshot FIRST — before the database is opened.
Do it at the composition boundary that opens AppDatabase, never inside onUpgrade: PRAGMA wal_checkpoint(TRUNCATE) any live handle so the -wal is folded into the main file, then copy the DB file and its `-wal`/`-shm` sidecars while nothing holds the file open. Opening the database is what triggers the migration. Never copy or overwrite bytes under a live connection. The snapshot is the only "rollback" SQLite has; restore it on any failure.
- Forward-only. Never write a down migration. SQLite has no true down
migration and you must not pretend to. "Rollback" means restore the snapshot, nothing else.
- Steps are append-only — NEVER edit a shipped step. Editing a released
step corrupts data for every user who skips versions. To fix a bug in a prior step, add a new step and bump schemaVersion — never back-edit history.
- Bump `schemaVersion` by exactly one per shipped schema change, and add the
matching fromNToM branch. A schema changed without a version bump means no migration runs at all on the user's device — a CI gate must catch it.
- Commit the versioned schema snapshot. Run
drift_dev make-migrations
(or schema dump), commit the exported snapshot under drift_schemas/, and commit schema_versions.dart. The delta becomes a reviewable diff and the test suite diffs live schema against it.
- The open is wrapped in try/restore, entirely outside any connection. If
opening the database throws, the migration failed and that connection is dead: close it, restore the snapshot file(s) taken before the open, and rethrow. All file operations happen while nothing has the DB open — never overwrite the live file from inside onUpgrade.
- A green shape check is necessary, never sufficient.
migrateAndValidate
compares CREATE statements only — it never reads a row. A migration that rebuilds a table perfectly and copies zero rows passes it, green. The content test is the deliverable, not the shape test.
- No migration merges without the full test suite green — every
from → to
path (including multi-version jumps), a content test per new pair, PRAGMA integrity_check == ok, PRAGMA foreign_key_check empty, and a forced mid-migration throw that restores the snapshot.
- Store canonical values only in any new column (integer minor units for
money keyed to the ISO-4217 exponent, SI integers for quantities, UTC epoch millis for instants, a local serial-day integer for a calendar date). Never add a float-money, display-string, or localized-numeral column.
The ordered workflow
Run commands from the package that owns the database (single-package apps: the app root; see the multi-package note at the end).
- Design the change against your data-layer conventions (see
persistence-drift). Edit the table class.
- Bump `schemaVersion` by one in the database class.
- Scaffold the snapshot + step stub and commit the generated snapshot:
``bash dart run drift_dev make-migrations ` On pinned versions where make-migrations` is not confirmed working, use the three explicit commands instead (see "Snapshot commands" below).
- Write the append-only forward step — add one new
fromNToMbranch. Never
modify an existing branch. Create only the objects this version adds; never reference a column added in a later version.
- Regenerate codegen so the generated database picks up the new version
(invoke the run-codegen skill): ``bash dart run build_runner build --delete-conflicting-outputs ``
- Run the migration test suite (see Verification). All paths, the content
test, both PRAGMAs, and the forced-throw restore must pass.
- Analyze, format, and commit the table change, the bumped
schemaVersion,
the new step, the committed snapshot, and the tests together in one change.
The migration guard
The snapshot/restore lives at the composition boundary, entirely outside any open connection; onUpgrade only runs the steps and checks foreign keys. Keep this exact shape.
Snapshot commands (explicit form)
When not using make-migrations, re-run all three on every schemaVersion bump and commit the results:
Verification (blocking — must pass before commit)
The suite must prove all of the following.
Every from→to path, including the skips. A user who ignored updates upgrades v1 → v3 directly — a code path nobody ran. A nested loop covers every pair forever, so a new bump cannot forget a skip path:
The content test — the one that matters. Write rows at v(n) with era-correct classes, run the real migration, read back at v(n+1), assert the rows are still there, still correct, and still in place. Use a hostile fixture — apostrophes, non-ASCII, em dashes, emoji, quotes, backslashes, whitespace-only — exactly where a columnTransformer or hand-rolled INSERT ... SELECT mangles a value. 'test1' survives everything and proves nothing. Put a reason: on every expect — the failure message is the whole debugging session when no crash report is coming.
The forced mid-migration throw restores the snapshot. Inject a step that throws partway, open the database through the boundary opener so the migration runs, assert the open rethrows and that the pre-open snapshot was restored — prior schema and rows left byte-identical. The restore path is the last line of defense and the one that is never exercised in production until it is.
Never mark a migration done on a green analyzer alone. It is safe only once the content test, both PRAGMAs, the all-paths loop, and the snapshot-restore test are green.
Migration mechanics that fail silently
PRAGMA foreign_keysis ignored once a transaction is open — toggle FKs
OFF at the top of onUpgrade, before the transaction() that wraps the steps, and re-enable them unconditionally in `beforeOpen` (the pragma is per-connection, not persisted in the file).
- Run
PRAGMA foreign_key_checkafter the migration body, not only in tests. flutter testruns in a plain Dart VM wheresqlite3_flutter_libsdoes
nothing; macOS falls back to the system libsqlite3 (real version-skew risk) and Linux needs libsqlite3-dev installed before the run.
Anti-patterns
This is the start of the file. Read the full SKILL.md on GitHub.
Security
- Security scanPassed, 95 of 100Pattern checks on the skill's files.
- Model reviewPassed
Quality evaluation
- Task evaluationNot runNo evaluation yet. Run one in Skill Studio.
Source
- SKILL.md in the repositoryCheckingskills/run-migration/SKILL.md
Popularity
- Repository stars
- 22
- Repository forks
- 4
- 7-day trend score
- 16
Stars and forks are for the whole GitHub repository, not this skill alone. Not refreshed yet.
Works with
Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.
- Claude Code
- Cursor
- GitHub Copilot
- Windsurf
- Codex
- Gemini CLI
- Cline
- Amp
- Roo Code
- Goose
- Continue
- Kilo Code
- Junie
- Trae
- OpenHands
- Qwen Code
- AI Agent
- Tabnine Chat
- Sourcegraph Cody
- Amazon Q
- Firebase Genkit
- Sweep
- Devin
- Phind
- Mentat
- Claude Desktop
- Aider
- GPT Pilot
- Plandex
- bolt.new
- v0
- Replit Agent
- Anse
- TypingMind
- BetterChatGPT
- LibreChat
- Warp AI
- Pieces
- Fig AI
Embed badge
[](https://verified-skill.com/skills/zakariaf/flutter-skills/run-migration)