pub enum Operation {
Show 13 variants
CreateModel {
model: ModelState,
},
DeleteModel {
name: String,
},
RenameModel {
old_name: String,
new_name: String,
table: String,
},
AddField {
model: String,
field: FieldState,
},
RemoveField {
model: String,
name: String,
},
AlterField {
model: String,
name: String,
field: FieldState,
},
RenameField {
model: String,
old_name: String,
new_name: String,
},
CreateIndex {
model: String,
index: IndexState,
},
DeleteIndex {
model: String,
name: String,
},
AddConstraint {
model: String,
constraint: ConstraintState,
},
DeleteConstraint {
model: String,
name: String,
},
RunSQL {
sql: String,
reverse_sql: Option<String>,
},
RunRust {
name: String,
backwards: Option<String>,
},
}Expand description
One atomic schema change (or a data operation).
RunSQL without reverse_sql and RunRust
without backwards are irreversible. DeleteModel and
RemoveField reverse by recreating the object from
state_before.
Variants§
CreateModel
Create a table (and its indexes / table constraints).
Fields
model: ModelStateFull model snapshot after the create.
DeleteModel
Drop a table.
RenameModel
Rename a model (and its table when table differs from the current
table). Detected only when listed in crate::autodetector::RenameHints.
Fields
AddField
Add a column.
RemoveField
Drop a column.
AlterField
Replace a field’s schema (type, nullability, default, …).
Fields
field: FieldStateNew field snapshot.
RenameField
Rename a field. Detected only when listed in
crate::autodetector::RenameHints; otherwise a same-shape
remove+add is refused.
Fields
CreateIndex
Create a named index.
DeleteIndex
Drop a named index.
AddConstraint
Add a table-level constraint.
DeleteConstraint
Drop a table-level constraint.
RunSQL
Developer-authored SQL. Irreversible unless reverse_sql is set.
Fields
RunRust
A function registered at runtime in a
crate::registry::MigrationRegistry. The function itself cannot be
serialized; only the name is stored.
Implementations§
Source§impl Operation
impl Operation
Sourcepub fn apply_to_state(
&self,
state: &mut ProjectState,
) -> Result<(), MigrationError>
pub fn apply_to_state( &self, state: &mut ProjectState, ) -> Result<(), MigrationError>
Apply this operation to state.
§Errors
MigrationError::State when a referenced model or field is missing,
or when creating a duplicate.
Sourcepub fn reverse(&self, state_before: &ProjectState) -> Option<Operation>
pub fn reverse(&self, state_before: &ProjectState) -> Option<Operation>
Inverse operation, or None if this step is irreversible.
state_before is the project state immediately before this operation
was applied. DeleteModel and
RemoveField recreate the dropped object from it.
Sourcepub fn is_unconditionally_irreversible(&self) -> bool
pub fn is_unconditionally_irreversible(&self) -> bool
Whether reversal is impossible regardless of project state
(RunSQL without reverse_sql, RunRust without backwards).