pub struct Config { /* private fields */ }std only.Expand description
Build-time migration generation configuration.
Implementations§
Source§impl Config
impl Config
Sourcepub fn new(dialect: Dialect) -> Config
pub fn new(dialect: Dialect) -> Config
Create a new configuration.
out_dir defaults to ./drizzle, breakpoints are enabled by default,
and migration tag prefixes default to timestamp mode. Tracking defaults
to the dialect-appropriate Tracking::SQLITE / Tracking::POSTGRES.
Sourcepub fn from_toml(path: impl AsRef<Path>) -> Result<Config, BuildError>
pub fn from_toml(path: impl AsRef<Path>) -> Result<Config, BuildError>
Load configuration from a drizzle.config.toml file.
Reads dialect, schema (one path or a list), out, dbCredentials.url
(literal string or { env = "VAR" }), and an optional [migrations]
section with tracking overrides and a checked-in
sqliteRebuildDataPlan path.
Anything else in the file is ignored — this loader covers only what the build-time generate/migrate flow needs. The CLI’s full loader handles multi-database configs, filters, and casing-from-TOML.
§Errors
Returns BuildError::ConfigNotFound if the file is missing,
BuildError::Io for other read failures, or BuildError::Toml
if it fails to parse.
Sourcepub fn file(self, path: impl Into<PathBuf>) -> Config
pub fn file(self, path: impl Into<PathBuf>) -> Config
Add one Rust source file to the build input set.
Sourcepub const fn breakpoints(self, enabled: bool) -> Config
pub const fn breakpoints(self, enabled: bool) -> Config
Enable or disable statement breakpoints in written SQL.
Sourcepub const fn prefix_mode(self, mode: PrefixMode) -> Config
pub const fn prefix_mode(self, mode: PrefixMode) -> Config
Set migration tag prefix mode.
Sourcepub fn name(self, name: impl Into<String>) -> Config
pub fn name(self, name: impl Into<String>) -> Config
Set a custom suffix for the generated migration tag.
Sourcepub fn transform_statements(
self,
transform: impl Fn(Vec<String>) -> Vec<String> + Send + Sync + 'static,
) -> Config
pub fn transform_statements( self, transform: impl Fn(Vec<String>) -> Vec<String> + Send + Sync + 'static, ) -> Config
Rewrite the generated statements before they are written to
migration.sql.
This is the supported place for app-level DDL policy — ephemeral
tables, engine-specific pragmas, IF NOT EXISTS conventions, dropping
statements for objects the app manages itself. Encoding the policy here
keeps it in version control and re-applies it to every future
migration; hand-editing generated SQL does neither.
The callback receives the statements in execution order and returns the
list to write. Returning an empty list makes the run report
Output::NoChanges and write nothing.
The snapshot is not transformed: it records the schema the diff was computed from, and rewriting it would desynchronize the next diff.
§Example
use drizzle_migrations::build::{Config, run};
use drizzle_types::Dialect;
let cfg = Config::new(Dialect::SQLite)
.file("src/schema.rs")
.out("./drizzle")
// Session-scoped scratch tables are created by the app at startup,
// so migrations must not manage them.
.transform_statements(|statements| {
statements
.into_iter()
.filter(|sql| !sql.contains("\"scratch_\""))
.collect()
});
run(&cfg)?;Runtime-generation callers do not need this hook: crate::Plan
exposes statements as a public Vec<String>, so they can rewrite the
plan directly before executing or writing it.
Sourcepub fn sqlite_rebuild_data_plan(self, plan: SqliteRebuildDataPlan) -> Config
pub fn sqlite_rebuild_data_plan(self, plan: SqliteRebuildDataPlan) -> Config
Attach typed data movement to SQLite table rebuilds in this generation.
The plan is validated against both schema snapshots and its exact predecessor ID. It does not rewrite generated statements after diffing.
Sourcepub fn sqlite_rebuild_data_plan_registry(
self,
registry: SqliteRebuildDataPlanRegistry,
) -> Config
pub fn sqlite_rebuild_data_plan_registry( self, registry: SqliteRebuildDataPlanRegistry, ) -> Config
Attach a versioned registry of snapshot-bound SQLite rebuild plans.
Sourcepub fn sqlite_rebuild_data_plan_file(self, path: impl Into<PathBuf>) -> Config
pub fn sqlite_rebuild_data_plan_file(self, path: impl Into<PathBuf>) -> Config
Load a checked-in, versioned SQLite rebuild-data plan during normal generation.
Sourcepub fn watch(&self)
pub fn watch(&self)
Emit cargo:rerun-if-changed= for schema files, the TOML config (if
loaded via Config::from_toml), and the migrations output directory,
plus cargo:rerun-if-env-changed= for any env vars referenced by
dbCredentials.url.
The output directory is watched because the previous-snapshot chain
under it is a diff input: deleting or reverting a migration folder
changes what run generates. Without it, cargo sees no watched path
change, skips the script, replays the cached “generated migration”
output, and the migration is silently never regenerated. Cargo scans a
watched directory recursively, and a not-yet-existing one counts as
changed — the first run creates it, so this converges.
Call this once after construction so cargo reruns build.rs whenever
any relevant input changes.
Sourcepub fn out_dir(&self) -> &Path
pub fn out_dir(&self) -> &Path
Migrations output directory (where generated migration.sql /
snapshot.json folders are written).
Sourcepub fn url(&self) -> Result<String, BuildError>
pub fn url(&self) -> Result<String, BuildError>
Resolved database URL, reading from the environment if configured as
{ env = "VAR" }.
§Errors
Returns BuildError::MissingUrl if no URL was configured,
BuildError::EnvVarNotSet if a referenced env var is unset, or
BuildError::EnvVarNotUnicode if it is set but contains invalid UTF-8.
Sourcepub fn tracking(&self) -> MigrationTracking
pub fn tracking(&self) -> MigrationTracking
Migration tracking table/schema for this config.
Defaults to the dialect-appropriate Tracking::SQLITE /
Tracking::POSTGRES, with overrides applied from
[migrations] table = ... / schema = ... in TOML if present.