#[non_exhaustive]pub enum MigrationAction {
Show 15 variants
CreateTable {
table: TableName,
columns: Vec<ColumnDef>,
constraints: Vec<TableConstraint>,
},
DeleteTable {
table: TableName,
},
AddColumn {
table: TableName,
column: Box<ColumnDef>,
fill_with: Option<String>,
},
RenameColumn {
table: TableName,
from: ColumnName,
to: ColumnName,
},
DeleteColumn {
table: TableName,
column: ColumnName,
},
ModifyColumnType {
table: TableName,
column: ColumnName,
new_type: ColumnType,
fill_with: Option<BTreeMap<String, String>>,
narrowing_strategy: Option<NarrowingStrategy>,
timezone: Option<String>,
},
ModifyColumnNullable {
table: TableName,
column: ColumnName,
nullable: bool,
fill_with: Option<String>,
delete_null_rows: Option<bool>,
},
ModifyColumnDefault {
table: TableName,
column: ColumnName,
new_default: Option<String>,
backfill: Option<String>,
},
ModifyColumnComment {
table: TableName,
column: ColumnName,
new_comment: Option<String>,
},
AddConstraint {
table: TableName,
constraint: TableConstraint,
},
RemoveConstraint {
table: TableName,
constraint: TableConstraint,
},
ReplaceConstraint {
table: TableName,
from: TableConstraint,
to: TableConstraint,
},
RemapEnumValues {
table: TableName,
column: ColumnName,
mapping: BTreeMap<i64, i64>,
},
RenameTable {
from: TableName,
to: TableName,
},
RawSql {
sql: String,
},
}Expand description
A single schema change produced by the planner and consumed by the SQL generator.
The planner emits a Vec<MigrationAction> when diffing two schemas. The SQL generator
(vespertide-query) translates each action into backend-specific DDL statements.
Prefer typed actions over MigrationAction::RawSql. Raw SQL is an emergency escape hatch:
it is not portable across backends and is skipped during baseline replay, which means the
planner cannot reason about it.
This enum is #[non_exhaustive]: new variants may be added in future releases.
Downstream match expressions should include a wildcard arm.
Variants (Non-exhaustive)§
This enum is marked as non-exhaustive
CreateTable
Create a new table with the given columns and constraints (CREATE TABLE).
DeleteTable
Drop an existing table and all its data (DROP TABLE).
AddColumn
Add a new column to an existing table (ALTER TABLE ... ADD COLUMN).
Fields
RenameColumn
Rename a column in an existing table (ALTER TABLE ... RENAME COLUMN).
DeleteColumn
Remove a column from an existing table (ALTER TABLE ... DROP COLUMN).
ModifyColumnType
Change the SQL type of an existing column (ALTER TABLE ... ALTER COLUMN ... TYPE).
Fields
column: ColumnNamenew_type: ColumnTypefill_with: Option<BTreeMap<String, String>>Mapping of removed enum values to replacement values for safe enum value removal.
e.g., {"cancelled": "'pending'"} generates an UPDATE before the type change.
narrowing_strategy: Option<NarrowingStrategy>Strategy for transforming existing rows that would violate a narrowed new type
(smaller VARCHAR length, lower NUMERIC scale, smaller integer size, etc.) so the
ALTER COLUMN TYPE cannot fail. When None, the SQL generator emits a plain ALTER —
safe only when the user has independently verified no row violates the new type
(typically prompted by the vespertide revision type-narrowing select UI).
timezone: Option<String>IANA timezone name (e.g. "Asia/Seoul") or numeric UTC offset (e.g. "+09:00")
used when converting between timestamp and timestamptz. Required for safe
migration on PostgreSQL where the conversion is non-trivial; ignored on MySQL
and SQLite where vespertide maps both timestamp and timestamptz to the same
underlying type. Validated by the CLI revision prompt against a 30-name
whitelist plus numeric offset format ±HH:MM.
ModifyColumnNullable
Change whether a column accepts NULL values.
Fields
column: ColumnNameModifyColumnDefault
Change or remove the default value of a column.
Fields
column: ColumnNamebackfill: Option<String>F15 fault gate — backfill existing rows.
ALTER TABLE ... SET DEFAULT ... only affects new rows. When
the user wants every existing row updated to the new default in
the same migration (the common “I want consistency right now”
intent), the CLI’s revision prompt captures that choice and
stores the desired value here. The SQL generator then emits an
UPDATE table SET col = <value> immediately after the ALTER.
None (default, wire-format identical to v0.2.0) → skip the
backfill: existing rows keep their current values. The action
behaves exactly as before this field existed.
ModifyColumnComment
Change or remove the comment on a column.
Fields
column: ColumnNameAddConstraint
Add a constraint (primary key, unique, foreign key, check, or index) to a table.
F2 duplicate-handling strategy lives on the Unique variant of
TableConstraint itself (see TableConstraint::Unique.strategy),
not here — the strategy is intrinsic to a particular unique
constraint, regardless of whether it is added, replaced, or shipped
inside a CreateTable.
RemoveConstraint
Remove a constraint from a table.
ReplaceConstraint
Atomically replace one constraint with another (e.g. when columns in a composite key change).
RemapEnumValues
Remap stored integer values of an integer-backed enum column.
Emitted when the user changes the value of an existing integer
enum variant in the model (e.g. medium: 5 → 10). Because integer
enums are stored as plain INTEGER in the database, the DB itself
cannot detect the drift; if Vespertide stayed silent the ORM mapping
would silently re-interpret existing rows. The SQL generator turns
this action into a single atomic UPDATE table SET col = CASE WHEN col = old THEN new ... END WHERE col IN (...) that re-stamps every
affected row before the new ORM mapping takes effect.
mapping is a BTreeMap<i64, i64> keyed on the old value, so the
type system guarantees a single replacement per source value.
Canonical JSON wire format is {"5": 10, "100": 20} (string keys
are how JSON represents map keys; serde transparently parses them
back to i64). For backward compatibility the legacy array form
[[5, 10], [100, 20]] is still accepted on read — see
remap_mapping_serde for the details. The map iterates in
old_value order at emit time so snapshots stay deterministic.
Variants whose name AND value are unchanged are absent; variants
added or removed (no name overlap on either side) are also absent
— those need a separate migration action.
RenameTable
Rename a table (ALTER TABLE ... RENAME TO).
RawSql
Execute a raw SQL statement verbatim.
Emergency escape hatch only. Raw SQL is not portable across backends and is invisible to baseline replay, so the planner cannot reason about schema state after this action. Use typed actions whenever possible.
Implementations§
Source§impl MigrationAction
impl MigrationAction
Sourcepub fn with_prefix(self, prefix: &str) -> Self
pub fn with_prefix(self, prefix: &str) -> Self
Apply a prefix to all table names in this action.
Source§impl MigrationAction
impl MigrationAction
Sourcepub fn table_name(&self) -> Option<&str>
pub fn table_name(&self) -> Option<&str>
Returns the primary table this action affects, if any.
Returns None for actions that don’t bind to a single table (e.g. RawSql).
Trait Implementations§
Source§impl Clone for MigrationAction
impl Clone for MigrationAction
Source§fn clone(&self) -> MigrationAction
fn clone(&self) -> MigrationAction
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for MigrationAction
impl Debug for MigrationAction
Source§impl<'de> Deserialize<'de> for MigrationAction
impl<'de> Deserialize<'de> for MigrationAction
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Source§impl Display for MigrationAction
impl Display for MigrationAction
impl Eq for MigrationAction
Source§impl JsonSchema for MigrationAction
impl JsonSchema for MigrationAction
Source§fn schema_id() -> Cow<'static, str>
fn schema_id() -> Cow<'static, str>
Source§fn json_schema(generator: &mut SchemaGenerator) -> Schema
fn json_schema(generator: &mut SchemaGenerator) -> Schema
Source§fn inline_schema() -> bool
fn inline_schema() -> bool
$ref keyword. Read moreSource§impl PartialEq for MigrationAction
impl PartialEq for MigrationAction
Source§fn eq(&self, other: &MigrationAction) -> bool
fn eq(&self, other: &MigrationAction) -> bool
self and other values to be equal, and is used by ==.Source§impl Serialize for MigrationAction
impl Serialize for MigrationAction
impl StructuralPartialEq for MigrationAction
Auto Trait Implementations§
impl Freeze for MigrationAction
impl RefUnwindSafe for MigrationAction
impl Send for MigrationAction
impl Sync for MigrationAction
impl Unpin for MigrationAction
impl UnsafeUnpin for MigrationAction
impl UnwindSafe for MigrationAction
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more