Skip to main content

Migration

Trait Migration 

Source
pub trait Migration: Send + Sync {
    // Required methods
    fn version(&self) -> u32;
    fn name(&self) -> &str;
    fn up(&self, conn: &Connection) -> Result<()>;

    // Provided methods
    fn down(&self, _conn: &Connection) -> Result<()> { ... }
    fn verify(&self, _conn: &Connection) -> Result<()> { ... }
}
Expand description

Migration trait

Implement this to define a database migration.

Required Methods§

Source

fn version(&self) -> u32

The version number this migration targets

Versions should be sequential starting from 2 (version 1 is the base schema).

Source

fn name(&self) -> &str

Human-readable name for this migration

Source

fn up(&self, conn: &Connection) -> Result<()>

Apply the migration (upgrade)

Provided Methods§

Source

fn down(&self, _conn: &Connection) -> Result<()>

Rollback the migration (downgrade)

Optional - default implementation returns an error.

Source

fn verify(&self, _conn: &Connection) -> Result<()>

Optional: verify the migration was applied correctly

Implementors§