Skip to main content

Crate drizzle_cli

Crate drizzle_cli 

Source
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

  1. Install the CLI with the drivers it should connect through: cargo install drizzle-cli --locked --features sqlite-all (or postgres-all, mysql-all, or single driver features such as rusqlite). Without a driver, migrate, push, and introspect fail with “No driver available”.
  2. Run drizzle init to create drizzle.config.toml.
  3. Run drizzle generate to write a migration, then drizzle 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

CommandWhat it doesNeeds a database
drizzle initCreate drizzle.config.tomlno
drizzle generateWrite a migration from schema changes (--custom for an empty one)no
drizzle migrateApply pending migrationsyes
drizzle pushApply the schema directly, without migration filesyes
drizzle introspect / drizzle pullGenerate a schema file from a live databaseyes
drizzle statusList local migrations and whether each has a snapshotno
drizzle checkValidate the config fileno
drizzle exportPrint the schema as SQLno
drizzle upUpgrade old snapshots to the current formatno
drizzle import <folder>Write the Rust schema of a TypeScript drizzle-orm project from its drizzle-kit snapshotsno
drizzle newBuild a schema file interactivelyno

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 / pull and import.
commands
One module per drizzle subcommand; each exposes a run function.
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).