Trait diesel_migrations::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

Object Safety§

This trait is not object safe.

Implementors§

source§

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

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>,