Migration

Trait Migration 

Source
pub trait Migration<Ctx>: Send + Sync {
    // Required methods
    fn version(&self) -> u64;
    fn name(&self) -> &str;
    fn apply(&self, ctx: &mut Ctx) -> Result<(), Error>;

    // Provided methods
    fn phase(&self) -> Phase { ... }
    fn rollback(&self, ctx: &mut Ctx) -> Result<(), Error> { ... }
    fn can_rollback(&self) -> bool { ... }
}
Expand description

A migration that can be applied or rolled back.

Migrations are versioned changes to your system. Each migration has:

  • A unique version number (must be sequential starting from 1)
  • A human-readable name
  • A deployment phase (pre-deploy or post-deploy)
  • An apply action
  • An optional rollback action

The generic type Ctx is the context passed to apply/rollback functions. This could be a database connection, file system handle, API client, etc.

Required Methods§

Source

fn version(&self) -> u64

Unique version number (must be sequential: 1, 2, 3, …)

Source

fn name(&self) -> &str

Human-readable name for this migration

Source

fn apply(&self, ctx: &mut Ctx) -> Result<(), Error>

Apply the migration

Provided Methods§

Source

fn phase(&self) -> Phase

Deployment phase (pre-deploy or post-deploy)

Source

fn rollback(&self, ctx: &mut Ctx) -> Result<(), Error>

Rollback the migration (optional)

Source

fn can_rollback(&self) -> bool

Whether this migration supports rollback

Implementors§

Source§

impl<Ctx> Migration<Ctx> for SqlMigration
where Ctx: SqlExecutor,

Source§

impl<Ctx, F, R> Migration<Ctx> for FnMigration<Ctx, F, R>
where F: Fn(&mut Ctx) -> Result<(), Error> + Send + Sync, R: Fn(&mut Ctx) -> Result<(), Error> + Send + Sync,