Trait sqlx_migrator::migration::Migration
source · pub trait Migration<DB, State = ()>: Send + Sync {
// Required methods
fn app(&self) -> &str;
fn name(&self) -> &str;
fn parents(&self) -> Vec<Box<dyn Migration<DB, State>>>;
fn operations(&self) -> Vec<Box<dyn Operation<DB, State>>>;
// Provided methods
fn replaces(&self) -> Vec<Box<dyn Migration<DB, State>>> { ... }
fn run_before(&self) -> Vec<Box<dyn Migration<DB, State>>> { ... }
fn is_atomic(&self) -> bool { ... }
fn is_virtual(&self) -> bool { ... }
}
Expand description
Trait for migration
Required Methods§
sourcefn app(&self) -> &str
fn app(&self) -> &str
Migration app name. Can be name of folder or library where migration is located
sourcefn parents(&self) -> Vec<Box<dyn Migration<DB, State>>>
fn parents(&self) -> Vec<Box<dyn Migration<DB, State>>>
Parents of migration (migrations that should be applied before this migration)
sourcefn operations(&self) -> Vec<Box<dyn Operation<DB, State>>>
fn operations(&self) -> Vec<Box<dyn Operation<DB, State>>>
Operation performed for migration (create, drop, etc.). Migration can contains multiple operation within each other which are interrelated
Provided Methods§
sourcefn replaces(&self) -> Vec<Box<dyn Migration<DB, State>>>
fn replaces(&self) -> Vec<Box<dyn Migration<DB, State>>>
Replace certain migrations. If any one of listed migration is applied than migration will not be applied else migration will apply/revert instead of applying/reverting those migration.
sourcefn run_before(&self) -> Vec<Box<dyn Migration<DB, State>>>
fn run_before(&self) -> Vec<Box<dyn Migration<DB, State>>>
Run before(for applying)/after(for reverting) certain migration. This can be helpful in condition where other library migration need to be applied after this migration or reverted before this migration
sourcefn is_atomic(&self) -> bool
fn is_atomic(&self) -> bool
Whether migration is atomic or not. By default it is atomic so this
function returns true
. If you make migration non atomic all its
operation will be non atomic if any operation needs to be atomic it is
recommended to split migration so one migration will have atomic
operation where as another have non atomic operation
sourcefn is_virtual(&self) -> bool
fn is_virtual(&self) -> bool
Whether migration is virtual or not. By default migration are not virtual. If migration is virtual than it expects another migration with same app and name present inside migration list which is not virtual. For virtual migration all other methods gets ignored since it is reference to actual migration instead of actual migration