pub struct Migrator { /* private fields */ }Expand description
The migrations of one app, sorted by name. Build it with Migrator::from_dir or
migrations!.
Implementations§
Source§impl Migrator
impl Migrator
Sourcepub fn new(migrations: Vec<Migration>) -> Result<Self, Error>
pub fn new(migrations: Vec<Migration>) -> Result<Self, Error>
Sorts the migrations by name. A name must start with a 14-digit timestamp and an
underscore, as 20261108000000_create_users does. Two migrations with the same name, or
the same timestamp, are an error.
Sourcepub fn with_lock_timeout(self, timeout: Duration) -> Self
pub fn with_lock_timeout(self, timeout: Duration) -> Self
Sets how long run and rollback wait for another process to finish its migrations.
Sourcepub fn migrations(&self) -> &[Migration]
pub fn migrations(&self) -> &[Migration]
The migrations in name order.
Sourcepub fn from_dir(dir: impl AsRef<Path>) -> Result<Self, Error>
pub fn from_dir(dir: impl AsRef<Path>) -> Result<Self, Error>
Reads every folder in dir as a migration, such as migrations/20261108000000_create_users.
Each folder needs up.sql and down.sql. Hidden entries are skipped.
Sourcepub async fn run(&self, db: &Database) -> Result<Vec<String>, Error>
pub async fn run(&self, db: &Database) -> Result<Vec<String>, Error>
Applies every pending migration, in name order, as one new batch. Each migration runs in its own transaction. The run stops at the first failure, and the error names it. The migrations before it stay applied in this batch.
MySQL and SQLite do not roll back DDL, and PostgreSQL does. On MySQL a failing migration can leave the DDL it ran before the failure in place; only its DML is rolled back. Returns the names that were applied.
Only one process runs migrations at a time. A second process waits up to the lock timeout,
then fails with Error::MigrationsLocked. The lock is held differently on each database;
see docs/laravel-differences.md.
Sourcepub async fn status(&self, db: &Database) -> Result<Vec<Status>, Error>
pub async fn status(&self, db: &Database) -> Result<Vec<Status>, Error>
Lists every migration in this migrator as applied (with its batch) or pending. Applied migrations without files here are not listed.
Sourcepub async fn rollback(&self, db: &Database) -> Result<Vec<String>, Error>
pub async fn rollback(&self, db: &Database) -> Result<Vec<String>, Error>
Reverts the last batch, running each down.sql in reverse name order, each in its own
transaction. It checks that every migration in the batch has files here before it reverts
anything. Returns the names that were reverted, or nothing when no migration has run.
Batch 0 holds the history that Diesel recorded, so a rollback that reaches batch 0 reverts those migrations and removes their rows from Diesel’s table too.
As with run, DDL in a down.sql is only rolled back on PostgreSQL.
Source§impl Migrator
impl Migrator
Sourcepub async fn import_diesel_history(
&self,
db: &Database,
) -> Result<Vec<String>, Error>
👎Deprecated since 0.1.1: not needed any more: run, status and rollback upgrade the migrations table themselves. This returns an empty list and will be removed in a later release
pub async fn import_diesel_history( &self, db: &Database, ) -> Result<Vec<String>, Error>
not needed any more: run, status and rollback upgrade the migrations table themselves. This returns an empty list and will be removed in a later release
Brings Diesel’s history into this migrator’s table. Orbit and Diesel share
__diesel_schema_migrations, so the rows Diesel wrote are already the applied history, in
batch 0. This call does what is still needed for them: it adds the batch column to a
table that has only Diesel’s columns. No up.sql runs, and no row is added or changed.
It returns nothing, because there is nothing new to record. It is safe to call again.
Sourcepub async fn unmatched_diesel_versions(
&self,
db: &Database,
) -> Result<Vec<String>, Error>
pub async fn unmatched_diesel_versions( &self, db: &Database, ) -> Result<Vec<String>, Error>
The versions in the migrations table that have no migration in this migrator, in order. They include versions that Orbit recorded when a folder has since been removed. Empty when the table does not exist. Only reads the table.
Trait Implementations§
Auto Trait Implementations§
impl Forget for Migrator
impl Freeze for Migrator
impl Move for Migrator
impl RefUnwindSafe for Migrator
impl Send for Migrator
impl Sync for Migrator
impl Unpin for Migrator
impl UnsafeUnpin for Migrator
impl UnwindSafe for Migrator
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,
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