Skip to main content

Migrate

Trait Migrate 

Source
pub trait Migrate
where Self: TableSchema,
{ // Provided methods fn default_value(_column: &str) -> Option<Value> { ... } fn transform_column(_column: &str, _old: Value) -> DbmsResult<Option<Value>> { ... } }
Expand description

Per-table extension hook for schema migrations.

The derive macro #[derive(Table)] emits an empty impl Migrate for T {} for every table by default, so callers only need to provide a manual impl when they tag the struct with #[migrate]. The trait extends TableSchema so implementors automatically have access to the table’s column definitions and snapshot.

Provided Methods§

Source

fn default_value(_column: &str) -> Option<Value>

Dynamic default for an MigrationOp::AddColumn operation on a non-nullable column.

Returning None falls back to the static #[default = ...] attribute declared on the column. If neither produces a value, migration aborts with MigrationError::DefaultMissing.

Source

fn transform_column(_column: &str, _old: Value) -> DbmsResult<Option<Value>>

Transform a stored value when its column changes to an incompatible type that does not fit the framework’s widening whitelist.

  • Ok(None) — no transform; the framework errors with MigrationError::IncompatibleType unless widening already applies.
  • Ok(Some(v)) — use v as the new value.
  • Err(_) — abort the migration; the journaled session rolls back.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§