Skip to main content

drizzle_cli/
lib.rs

1//! Library behind the `drizzle` migration CLI for drizzle-rs.
2//!
3//! The CLI reads a `drizzle.config.toml` instead of Rust code, so you can
4//! generate and apply migrations without a `build.rs`. This crate exposes the
5//! config loader ([`Config`]) and the command implementations
6//! ([`commands`]) that the binary dispatches to.
7//!
8//! # Quick start
9//!
10//! 1. Install the CLI with the drivers it should connect through:
11//!    `cargo install drizzle-cli --locked --features sqlite-all` (or
12//!    `postgres-all`, `mysql-all`, or single driver features such as
13//!    `rusqlite`). Without a driver, `migrate`, `push`, and `introspect`
14//!    fail with "No driver available".
15//! 2. Run `drizzle init` to create `drizzle.config.toml`.
16//! 3. Run `drizzle generate` to write a migration, then `drizzle migrate`.
17//!
18//! # Configuration
19//!
20//! `drizzle.config.toml` in the project root (or run `drizzle init`):
21//!
22//! ```toml
23//! dialect = "sqlite"
24//! schema = "src/schema.rs"
25//! out = "./drizzle"
26//!
27//! [dbCredentials]
28//! url = "./dev.db"
29//! ```
30//!
31//! For PostgreSQL:
32//!
33//! ```toml
34//! dialect = "postgresql"
35//! schema = "src/schema.rs"
36//! out = "./drizzle"
37//!
38//! [dbCredentials]
39//! url = "postgres://user:pass@localhost:5432/mydb"
40//! ```
41//!
42//! # Commands
43//!
44//! | Command | What it does | Needs a database |
45//! |---|---|---|
46//! | `drizzle init` | Create `drizzle.config.toml` | no |
47//! | `drizzle generate` | Write a migration from schema changes (`--custom` for an empty one) | no |
48//! | `drizzle migrate` | Apply pending migrations | yes |
49//! | `drizzle push` | Apply the schema directly, without migration files | yes |
50//! | `drizzle introspect` / `drizzle pull` | Generate a schema file from a live database | yes |
51//! | `drizzle status` | List local migrations and whether each has a snapshot | no |
52//! | `drizzle check` | Validate the config file | no |
53//! | `drizzle export` | Print the schema as SQL | no |
54//! | `drizzle up` | Upgrade old snapshots to the current format | no |
55//! | `drizzle import <folder>` | Write the Rust schema of a TypeScript drizzle-orm project from its drizzle-kit snapshots | no |
56//! | `drizzle new` | Build a schema file interactively | no |
57
58pub mod codegen;
59pub mod commands;
60pub mod config;
61pub mod db;
62pub mod error;
63pub mod output;
64pub mod snapshot;
65
66pub use config::{Config, Credentials, Dialect, Driver, Error};
67pub use error::CliError;