Trait MigrationContext

Source
pub trait MigrationContext:
    MigrationSource<Ctx = Self>
    + Send
    + Sync
    + 'static {
    type Exec: Executor;

    const HISTORY_TABLE: &'static str;

    // Required method
    fn executor(&mut self) -> &mut Self::Exec;

    // Provided methods
    fn apply<'migration, 'conn, M>(
        &'conn mut self,
        migration: &'migration M,
    ) -> Pin<Box<dyn Future<Output = Result<AppliedMigration, Error>> + Send + 'migration>>
       where 'conn: 'migration,
             M: Migration<Ctx = Self> + Send + Sync + ?Sized { ... }
    fn latest_version(
        &mut self,
    ) -> Pin<Box<dyn Future<Output = Result<Option<i64>, Error>> + Send + '_>> { ... }
    fn previously_applied(
        &mut self,
    ) -> Pin<Box<dyn Future<Output = Result<Vec<AppliedMigration>, Error>> + Send + '_>> { ... }
    fn check_history_table(
        &mut self,
    ) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + '_>> { ... }
    fn drop_history_table(
        &mut self,
    ) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + '_>> { ... }
    fn insert_applied<'migration, 'conn>(
        &'conn mut self,
        applied: &'migration AppliedMigration,
    ) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'migration>>
       where 'conn: 'migration { ... }
    fn upsert_applied<'migration, 'conn>(
        &'conn mut self,
        applied: &'migration AppliedMigration,
    ) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'migration>>
       where 'conn: 'migration { ... }
}
Expand description

The context in which a migration run occurs.

Required Associated Constants§

Source

const HISTORY_TABLE: &'static str

The name of the table in the database that tracks the history of this migration set.

It defaults to _tern_migrations in the default schema for the database driver if using the derive macro for this trait.

Required Associated Types§

Source

type Exec: Executor

The type for executing queries in a migration run.

Required Methods§

Source

fn executor(&mut self) -> &mut Self::Exec

A reference to the underlying Executor.

Provided Methods§

Source

fn apply<'migration, 'conn, M>( &'conn mut self, migration: &'migration M, ) -> Pin<Box<dyn Future<Output = Result<AppliedMigration, Error>> + Send + 'migration>>
where 'conn: 'migration, M: Migration<Ctx = Self> + Send + Sync + ?Sized,

For a migration that is capable of building its query in this migration context, this builds the query, applies the migration, then updates the schema history table after.

Source

fn latest_version( &mut self, ) -> Pin<Box<dyn Future<Output = Result<Option<i64>, Error>> + Send + '_>>

Gets the version of the most recently applied migration.

Source

fn previously_applied( &mut self, ) -> Pin<Box<dyn Future<Output = Result<Vec<AppliedMigration>, Error>> + Send + '_>>

Get all previously applied migrations.

Source

fn check_history_table( &mut self, ) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + '_>>

Check that the history table exists and create it if not.

Source

fn drop_history_table( &mut self, ) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + '_>>

Drop the history table if requested.

Source

fn insert_applied<'migration, 'conn>( &'conn mut self, applied: &'migration AppliedMigration, ) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'migration>>
where 'conn: 'migration,

Insert an applied migration.

Source

fn upsert_applied<'migration, 'conn>( &'conn mut self, applied: &'migration AppliedMigration, ) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'migration>>
where 'conn: 'migration,

Upsert applied migrations.

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§