Expand description
Library behind the drizzle migration CLI for drizzle-rs.
The CLI reads a drizzle.config.toml instead of Rust code, so you can
generate and apply migrations without a build.rs. This crate exposes the
config loader (Config) and the command implementations
(commands) that the binary dispatches to.
§Quick start
- Install the CLI with the drivers it should connect through:
cargo install drizzle-cli --locked --features sqlite-all(orpostgres-all,mysql-all, or single driver features such asrusqlite). Without a driver,migrate,push, andintrospectfail with “No driver available”. - Run
drizzle initto createdrizzle.config.toml. - Run
drizzle generateto write a migration, thendrizzle migrate.
§Configuration
drizzle.config.toml in the project root (or run drizzle init):
dialect = "sqlite"
schema = "src/schema.rs"
out = "./drizzle"
[dbCredentials]
url = "./dev.db"For PostgreSQL:
dialect = "postgresql"
schema = "src/schema.rs"
out = "./drizzle"
[dbCredentials]
url = "postgres://user:pass@localhost:5432/mydb"§Commands
| Command | What it does | Needs a database |
|---|---|---|
drizzle init | Create drizzle.config.toml | no |
drizzle generate | Write a migration from schema changes (--custom for an empty one) | no |
drizzle migrate | Apply pending migrations | yes |
drizzle push | Apply the schema directly, without migration files | yes |
drizzle introspect / drizzle pull | Generate a schema file from a live database | yes |
drizzle status | List local migrations and whether each has a snapshot | no |
drizzle check | Validate the config file | no |
drizzle export | Print the schema as SQL | no |
drizzle up | Upgrade old snapshots to the current format | no |
drizzle import <folder> | Write the Rust schema of a TypeScript drizzle-orm project from its drizzle-kit snapshots | no |
drizzle new | Build a schema file interactively | no |
Re-exports§
pub use config::Config;pub use config::Credentials;pub use config::Dialect;pub use config::Driver;pub use config::Error;pub use error::CliError;
Modules§
- codegen
- Rust schema source from a snapshot, shared by
introspect/pullandimport. - commands
- One module per
drizzlesubcommand; each exposes arunfunction. - config
- Loading and validating
drizzle.config.toml. - db
- Live-database work for CLI commands: planning and applying migrations,
planning and applying
push, and introspection. - error
CliError, the error type every command returns.- output
- Terminal styling helpers, so every command formats output the same way (in the style of drizzle-kit).
- snapshot
- Shared handling of schema-parser diagnostics for commands that build a
snapshot from schema files (
generate,push,export).