pub struct Migrator<S> { /* private fields */ }Expand description
Migrator is used to apply database migrations.
Create it with Database::migrator.
When all migrations are done, it can be turned into a Database instance with Migrator::finish.
Implementations§
Source§impl<S: Schema> Migrator<S>
impl<S: Schema> Migrator<S>
Sourcepub fn migrate<'x, M>(
self,
m: impl Send + FnOnce(&mut TransactionMigrate<S>) -> M,
) -> Migrator<M::To>where
M: SchemaMigration<'x, From = S>,
pub fn migrate<'x, M>(
self,
m: impl Send + FnOnce(&mut TransactionMigrate<S>) -> M,
) -> Migrator<M::To>where
M: SchemaMigration<'x, From = S>,
Apply a database migration if the current schema is S and return a Migrator for the next schema N.
This function will panic if the schema on disk does not match what is expected for its user_version.
#[schema(Schema)]
#[version(0..=1)]
pub mod vN {
pub struct User {
pub name: String,
#[version(1..)]
pub score: i64,
}
}
fn main() {
Database::migrator(Config::open_in_memory())
.unwrap()
.migrate(|txn| v0::migrate::Schema {
user: txn.migrate_ok(|old: Lazy<v0::User>| v0::migrate::User {
score: old.name.len() as i64,
}),
})
.finish()
.unwrap();
}Sourcepub fn fixup(self, f: impl Send + FnOnce(&'static mut Transaction<S>)) -> Self
pub fn fixup(self, f: impl Send + FnOnce(&'static mut Transaction<S>)) -> Self
Mutate the database as part of migrations.
The closure will only be executed if the database got migrated to schema version S
by this Migrator instance.
If Migrator::fixup is used before all Migrator::migrate, then the closures is only executed
when the database is created.
Auto Trait Implementations§
impl<S> !Freeze for Migrator<S>
impl<S> !RefUnwindSafe for Migrator<S>
impl<S> !Sync for Migrator<S>
impl<S> !UnwindSafe for Migrator<S>
impl<S> Send for Migrator<S>where
S: Send,
impl<S> Unpin for Migrator<S>where
S: Unpin,
impl<S> UnsafeUnpin for Migrator<S>
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
Mutably borrows from an owned value. Read more