Derive Macro MigrationContext

Source
#[derive(MigrationContext)]
{
    // Attributes available to this derive:
    #[tern]
}
Expand description

MigrationContext implements the trait MigrationContext, which is required of a type to be suitable for use in a migration Runner. A bound of MigrationSource exists, which can be satisfied by hand or by using the derive macro provided here, MigrationSource. Custom, dynamic behavior for a migration can be defined for the context, which is available to QueryBuilder.

The macro exposes one optional macro attribute and one optional field attribute:

  • table is the optional macro attribute. With it enabled, the migration history will be stored in this table, located in the default schema for the database driver, instead of the default table, _tern_migrations.
  • executor_via decorates the field holding an Executor, which is required of the type to be a context. If not specified then it is expected that the type itself implements Executor.

ยงUsage

use tern::{SqlxPgExecutor, MigrationContext};

#[derive(MigrationContext)]
#[tern(table = "_my_migration_history")]
pub struct MyContext {
    #[tern(executor_via)]
    executor: SqlxPgExecutor,
}