Skip to content

Repository files navigation

shki-logo

Warning

shki is still a work in progress. Declarative Schema support is active, but some deeper diff/render coverage and validation workflows are still being built.

shki

shki manages database schema change by comparing an intended database shape with recorded schema history and producing migration artifacts. It is SQL-first and Drizzle-inspired:

  • You author a Declarative Schema in SQL.
  • shki compiles it in a disposable Shadow Database.
  • The resulting Snapshot is compared with the latest recorded Snapshot from the Journal.
  • shki diff previews the Migration Plan.
  • shki generate writes migration SQL, a new Snapshot, and a Journal entry.
  • shki migrate applies migration artifacts to the live database.

It also generates Rust/TypeScript/Protobuf types from that schema, and type-safe sqlx query functions from annotated SQL.

📖 Documentation: https://dk0d.github.io/shki

Install

# macOS and Linux
curl --proto '=https' --tlsv1.2 -LsSf https://github.com/dk0d/shki/releases/latest/download/shki-installer.sh | sh
# Windows (PowerShell)
irm https://github.com/dk0d/shki/releases/latest/download/shki-installer.ps1 | iex

Also available via cargo binstall --git https://github.com/dk0d/shki shki or cargo install --git https://github.com/dk0d/shki. See the installation guide.

Quick start

shki init db --dialect postgres          # scaffold shki.toml, schema/, migrations/
export DATABASE_URL='postgres://user:pass@localhost:5432/mydb'
$EDITOR db/schema/main.sql               # write the schema you want
shki diff                                # preview the Migration Plan
shki generate create_users --down        # write migration SQL + Snapshot + Journal entry
shki migrate                             # apply pending migrations

No PostgreSQL install is needed for the Shadow Database — shki manages an embedded one by default. Full walkthrough: Quick Start.

Supported dialects

Workflow PostgreSQL MySQL SQLite
Apply/status/down migration runner yes yes yes
Custom Migration creation yes yes yes
Dump live shape as SQL/JSON yes yes yes
Dump live shape as Directory Schema yes yes yes
Declarative Schema compile/diff/generate yes no planned
Rich Catalog introspection coverage strongest basic basic

Documentation

Topic What's there
How it works Declarative Schema, Shadow Database, Snapshots, Journal
Declarative Schema Shadow Database setup, extensions, multi-file schemas
Migrations diff, generate, Custom Migrations, apply, adopt, roll back
Code generation Rust, TypeScript, and Protobuf types from schema shape
Typed queries type-safe sqlx functions from annotated SQL
CLI reference every command, flag, and alias
Configuration shki.toml keys and environment variables

Contributing

Issues and pull requests are welcome. See Contributing for the dev setup and test workflow.

License

MIT, see LICENSE.

Related projects

shki stands on the shoulders of projects that explored these ideas first — full credits in Inspired By:

  • pgschema — declarative, Terraform-style schema management for PostgreSQL.
  • jayy-lmao/sql-gen — generating typed Rust code from a live database schema.
  • squirrel — type-safe SQL code generation from introspected queries.
  • goose — a database migration tool. Supports SQL migrations and Go functions.

About

A drizzle-orm inspired database schema management and migration tool for Rust.

Resources

Stars

2 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages