NAME
sqlite-schema-diff
A schema-first approach to SQLite migrations.
DESCRIPTION
sqlite-schema-diff takes a schema-first approach to SQLite migrations. You define your schema in .sql files and the tool works out what changed.
Define the desired schema, diff it against your database to preview the changes, then apply them automatically. No numbered migration files and no merge conflicts, just SQL.
Apply is built to protect your data. It creates a backup through VACUUM INTO, runs every statement in a single transaction, and rolls back instead of committing a foreign key violation. Destructive changes are flagged and prompt for confirmation.
The tool is under active development, so always back up your database before applying changes. It works as a CLI and as a Go library.
FEATURES
- Diff your database against .sql schema files and preview changes
- Automatic apply inside a single transaction started with BEGIN IMMEDIATE
- Backup through VACUUM INTO before anything is touched
- Destructive changes flagged with confirmation prompts
- Covers tables, indexes, views, and triggers
- Raw SQL output for diffs with the --sql flag
- Usable as a Go library alongside the CLI
QUICK START
# Preview changes sqlite-schema-diff diff --database app.db --schema ./schema # Apply changes sqlite-schema-diff apply --database app.db --schema ./schema
go install github.com/mizuchilabs/sqlite-schema-diff@latest
sqlite-schema-diff dump --database app.db --output ./schema
CONFIGURATION
| Name | Description |
|---|---|
| --database | Database file to compare. Used by diff, apply, and dump. |
| --schema | Directory of .sql schema files. |
| --sql | Output raw SQL from diff. |
| --dry-run | Show what would happen without applying. |
| --force | Skip confirmation for destructive changes. |
| --skip-destructive | Skip destructive changes. |
| --backup=false | Disable automatic backup. |
RELATED
- Declarative SQLite with sqlite-schema-diffblog/sqlite-schema-diff
LINKS
Self-hosting sqlite-schema-diff is free under the Apache-2.0 license. Run it on your own iron. Commercial licensing, support, and managed offerings for businesses are on the business page.