Idempotent schema management in plain SQL for MySQL, PostgreSQL, SQLite and SQL Server
open sourceMIT AND Apache-2.0free
A schema migration tool that keeps your whole schema in one plain SQL file: edit the file, and sqldef compares it with the live database and generates and applies the DDL to get there, from any starting state. Each database has its own command (mysqldef for MySQL, MariaDB and TiDB, psqldef, sqlite3def, mssqldef) with the native client's connection options, and each can export the current schema and preview changes with a dry run. A single binary with no dependencies, started by Takashi Kokubun and inspired by Ridgepole's Ruby DSL. MIT licensed, with its SQL parser under Apache 2.0.
Problems it solves
- change my database schema by editing one SQL file instead of writing migration files
- get the ALTER statements needed to make my database match a schema file
- keep schema changes idempotent so running them twice is safe
Features
- desired-state schema migrations from a plain SQL file
- MySQL, MariaDB, TiDB, PostgreSQL, SQLite and SQL Server
- export the current schema
- dry run that shows the DDL before applying
- single binary with no dependencies
Alternatives
The same job
These do what sqldef does.
- Atlas Database schema as code: plan, lint, test and apply schema migrations, like Terraform for databases
- pgschema Terraform-style declarative schema migrations for PostgreSQL: dump, edit, plan, apply
- Liquibase Track, version, deploy and roll back database schema changes across 70+ databases
- Reylo Import .sql files into TypeScript with types inferred from your live database, plus SQL-first migrations
- dbmate A lightweight, framework-agnostic database migration tool for plain SQL migrations
- goose (database migrations) Database migration tool for SQL files and Go functions
