The name
"stig" is Swedish for path, or footpath. The verb form means to step, or to ascend.
Each migrate is a step forward along that path. Each snapshot is a footprint left behind, in case you ever need to find your way back.
An open-source command-line tool for SQLite migrations and schema management, written in Rust.
The name
"stig" is Swedish for path, or footpath. The verb form means to step, or to ascend.
Each migrate is a step forward along that path. Each snapshot is a footprint left behind, in case you ever need to find your way back.
What stig does
Applies pending migrations in lexicographic order, with checksum verification so nobody's local edits get silently skipped.
Takes a snapshot before every migration, so you can redo back to it and replay forward without touching a backup service.
stig status catches when an applied migration's file has changed underneath you, before it causes a surprise.
Generates TypeScript types straight from your live schema, so your types never drift from the database that backs them.
Usage
Install with cargo, then run stig init in your project. From there it's a loop: write a migration, apply it, and let stig snapshot as it goes.
# bootstrap a new project $ stig init ✓ project initialized # create a timestamped migration file $ stig new create_users → opens $EDITOR # apply all pending migrations, snapshot taken automatically $ stig migrate ✓ 1 applied # generate TypeScript types from the live schema $ stig generate ✓ typescript → lib/database/types.ts
Command reference
| Command | What it does |
|---|---|
| init | Bootstraps a new project: config file, migrations directory, backups directory, and the schema_migrations table. |
| new <description> | Creates a timestamped migration file and opens it in $EDITOR. |
| migrate | Applies all pending migrations in order, with automatic snapshots and checksum verification. --dry-run previews without applying. |
| status | Reports applied, pending, and drifted migrations, without making changes. |
| redo [version] | Restores the snapshot from before a version and replays migrations forward from there. Defaults to the most recent. |
| reset | Moves the live database into backups and re-migrates from empty. Destructive; prompts for confirmation. |
| restore [timestamp] | Restores the database from a reset backup. Defaults to the most recent. |
| generate [target] | Runs configured codegen targets against the live schema. Runs all targets if none is named. |
| backups list | Lists snapshots and reset backups with sizes and ages. |
| backups prune | Removes old backups according to retention policy. Prompts for confirmation. |
How it works
Every path stig can take, from the happy path to error recovery. Trail colour marks who's acting: developer, stig, the database, or the filesystem.
Happy path: first migration
Bootstrapping a project and applying your first migration.
stig init: creates config, migrations dir, snapshots dirschema_migrations table createdstig new create_users: scaffolds migration filestig migratepre-VERSION.dbCREATE TABLE users (...) executedschema_migrationsEdit an applied migration, snapshot available
Local testing reveals a mistake. The pre-migration snapshot is still around, so redo recovers it.
stig status: compares checksums against schema_migrationspre-VERSION.db is availablestig redo VERSIONpre-VERSION.db over the live databaseEdit an applied migration, snapshot pruned
Same mistake as above, but the snapshot's gone (default: only 5 kept). Choose between starting fresh or keeping the old data.
stig status: drift detected, but the snapshot has been prunedstig reset --yesresets/stig restore --yesMigration SQL error
A syntax error or a reference to a table that doesn't exist. Transactional migrations auto-rollback; non-transactional ones auto-restore from snapshot.
stig migrateschema_migrationsstig migrate (retry), applies cleanlyReset and restore
Test against a clean database without losing existing data. reset backs up the live database, restore brings it back.
stig reset --yesresets/stig restore --yesCodegen flow
After migrating, generate TypeScript types from the live schema.
stig migrate: applies pending migrationsstig generatelib/database/types.tsDry-run / preview flow
Preview what would change before applying, for catching surprises early.
stig status: one migration pendingstig migrate --dry-runstig migrate, applies for realOpen source
stig is free and open source under the MIT license. Issues, questions, and pull requests are welcome on GitHub.