tern_derive

Derive Macro MigrationSource

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

MigrationSource does the work of collecting all of the migrations, sorting them, unifying SQL and Rust migrations under a common interface by implementing Migration, and then exposing methods to return an ordered subset of them to be used in a given operation. It has one required attribute and one optional attribute.

  • source is a required macro attribute. It is the location of the migration files relative to the project root.
  • table is an 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.

ยงUsage

use tern::{SqlxPgExecutor, MigrationSource};

#[derive(MigrationSource)]
#[tern(source = "src/migrations", table = "_my_migrations_history")]
pub struct MyContext {
    #[tern(executor_via)]
    executor: SqlxPgExecutor,
}