diesel_migrations

Trait MigrationHarness

Source
pub trait MigrationHarness<DB: Backend> {
    // Required methods
    fn run_migration(
        &mut self,
        migration: &dyn Migration<DB>,
    ) -> Result<MigrationVersion<'static>>;
    fn revert_migration(
        &mut self,
        migration: &dyn Migration<DB>,
    ) -> Result<MigrationVersion<'static>>;
    fn applied_migrations(&mut self) -> Result<Vec<MigrationVersion<'static>>>;

    // Provided methods
    fn has_pending_migration<S: MigrationSource<DB>>(
        &mut self,
        source: S,
    ) -> Result<bool> { ... }
    fn run_pending_migrations<S: MigrationSource<DB>>(
        &mut self,
        source: S,
    ) -> Result<Vec<MigrationVersion<'_>>> { ... }
    fn run_next_migration<S: MigrationSource<DB>>(
        &mut self,
        source: S,
    ) -> Result<MigrationVersion<'_>> { ... }
    fn revert_all_migrations<S: MigrationSource<DB>>(
        &mut self,
        source: S,
    ) -> Result<Vec<MigrationVersion<'_>>> { ... }
    fn revert_last_migration<S: MigrationSource<DB>>(
        &mut self,
        source: S,
    ) -> Result<MigrationVersion<'static>> { ... }
    fn pending_migrations<S: MigrationSource<DB>>(
        &mut self,
        source: S,
    ) -> Result<Vec<Box<dyn Migration<DB>>>> { ... }
}
Expand description

A migration harness is an entity which applies migration to an existing database

Required Methods§

Source

fn run_migration( &mut self, migration: &dyn Migration<DB>, ) -> Result<MigrationVersion<'static>>

Apply a single migration

Types implementing this trait should call Migration::run internally and record that a specific migration version was executed afterwards.

Source

fn revert_migration( &mut self, migration: &dyn Migration<DB>, ) -> Result<MigrationVersion<'static>>

Revert a single migration

Types implementing this trait should call Migration::revert internally and record that a specific migration version was reverted afterwards.

Source

fn applied_migrations(&mut self) -> Result<Vec<MigrationVersion<'static>>>

Get a list of already applied migration versions

Provided Methods§

Source

fn has_pending_migration<S: MigrationSource<DB>>( &mut self, source: S, ) -> Result<bool>

Checks if the database represented by the current harness has unapplied migrations

Source

fn run_pending_migrations<S: MigrationSource<DB>>( &mut self, source: S, ) -> Result<Vec<MigrationVersion<'_>>>

Execute all unapplied migrations for a given migration source

Source

fn run_next_migration<S: MigrationSource<DB>>( &mut self, source: S, ) -> Result<MigrationVersion<'_>>

Execute the next migration from the given migration source

Source

fn revert_all_migrations<S: MigrationSource<DB>>( &mut self, source: S, ) -> Result<Vec<MigrationVersion<'_>>>

Revert all applied migrations from a given migration source

Source

fn revert_last_migration<S: MigrationSource<DB>>( &mut self, source: S, ) -> Result<MigrationVersion<'static>>

Revert the last migration from a given migration source

This method returns a error if the given migration source does not contain the last applied migration

Source

fn pending_migrations<S: MigrationSource<DB>>( &mut self, source: S, ) -> Result<Vec<Box<dyn Migration<DB>>>>

Get a list of non applied migrations for a specific migration source

The returned migration list is sorted in ascending order by the individual version of each migration

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§

Source§

impl<'b, C, DB> MigrationHarness<DB> for C
where DB: Backend, C: Connection<Backend = DB> + MigrationConnection + 'static, Order<Select<table, version>, Desc<version>>: LoadQuery<'b, C, MigrationVersion<'static>>, for<'a> InsertStatement<table, <Eq<version, MigrationVersion<'static>> as Insertable<table>>::Values>: QueryFragment<DB> + ExecuteDsl<C, DB>, DeleteStatement<<Find<table, MigrationVersion<'static>> as HasTable>::Table, <Find<table, MigrationVersion<'static>> as IntoUpdateTarget>::WhereClause>: ExecuteDsl<C>, str: ToSql<Text, DB>,

Source§

impl<C, W, DB> MigrationHarness<DB> for HarnessWithOutput<'_, C, W>
where W: Write, C: MigrationHarness<DB>, DB: Backend,