Skip to main content

Config

Struct Config 

Source
pub struct Config { /* private fields */ }
Available on crate feature std only.
Expand description

Build-time migration generation configuration.

Implementations§

Source§

impl Config

Source

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.

Source

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.

Source

pub fn file(self, path: impl Into<PathBuf>) -> Config

Add one Rust source file to the build input set.

Source

pub fn out(self, out_dir: impl Into<PathBuf>) -> Config

Set the output migrations directory.

Source

pub const fn casing(self, casing: Casing) -> Config

Set the inferred naming casing strategy.

Source

pub const fn breakpoints(self, enabled: bool) -> Config

Enable or disable statement breakpoints in written SQL.

Source

pub const fn prefix_mode(self, mode: PrefixMode) -> Config

Set migration tag prefix mode.

Source

pub fn name(self, name: impl Into<String>) -> Config

Set a custom suffix for the generated migration tag.

Source

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.

Source

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.

Source

pub fn sqlite_rebuild_data_plan_registry( self, registry: SqliteRebuildDataPlanRegistry, ) -> Config

Attach a versioned registry of snapshot-bound SQLite rebuild plans.

Source

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.

Source

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.

Source

pub const fn dialect(&self) -> Dialect

Dialect this config targets.

Source

pub fn out_dir(&self) -> &Path

Migrations output directory (where generated migration.sql / snapshot.json folders are written).

Source

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.

Source

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.

Trait Implementations§

Source§

impl Clone for Config

Source§

fn clone(&self) -> Config

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Config

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> AliasExt for T

Source§

fn alias(self, name: &'static str) -> AliasedExpr<Self>

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<Mk> MarkerAggValidFor<()> for Mk

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<Scope> ScopeSatisfies<Nil, ()> for Scope

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> TypeEq<T> for T