Skip to main content

Migrator

Struct Migrator 

Source
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

Source

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.

Source

pub fn with_lock_timeout(self, timeout: Duration) -> Self

Sets how long run and rollback wait for another process to finish its migrations.

Source

pub fn migrations(&self) -> &[Migration]

The migrations in name order.

Source

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.

Source

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.

Source

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.

Source

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

Source

pub 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

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.

Source

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§

Source§

impl Clone for Migrator

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Migrator

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more