hazel is a declarative schema management tool for SQLite. It reads the desired schema from SQL files and generates the DDL that brings a database in line with it. Documentation: https://winebarrel.github.io/hazel/ How it works The schema files are run in an in-memory database and read back from sqlite_schema and the schema PRAGMAs, the same way the target database is read. The two schemas are compared, and the difference becomes ALTER TABLE where SQLite supports the change, or a rebuild of the table, which runs only when it is allowed. Expressions and views are compared by the bytecode SQLite compiles them to. brew install winebarrel/hazel/hazel Release binaries and Linux packages are on the releases page. See Installation. Quick start Write the schema of an existing database to a file: $ hazel dump app.db > schema.sql Edit schema.sql, for example to add a column, and see the DDL that takes the database to it: $ hazel plan app.db schema.sql -- Database: /path/to/app.db -- Plan (1 table, 0 views, 1 index, 0 triggers) ALTER TABLE users ADD COLUMN email TEXT; Run it in one transaction: $ hazel apply app.db schema.sql -- Database: /path/to/app.db -- Plan (1 table, 0 views, 1 index, 0 triggers) ALTER TABLE users ADD COLUMN email TEXT; -- ok (0ms) -- Applied 1 statement Try it with Docker The demo image bundles hazel, sqlite3 and a sample database: docker run --rm -it ghcr.io/winebarrel/hazel-demo Commands See the command reference for the options. Development make build # builds ./hazel make test make lint Related projects pistachio is a declarative schema management tool for PostgreSQL.
AI NEWS JOURNAL
Hacker News Show HNAI NEWS / JOURNAL
Show HN: Hazel – Declarative schema management for SQLite
Article URL: https://github.com/winebarrel/hazel Comments URL: https://news.ycombinator.com/item?id=50504187 Points: 1 # Comments: 0