MigrationStore

Trait MigrationStore 

Source
pub trait MigrationStore {
    // Required methods
    fn init(&mut self) -> Result<(), Error>;
    fn applied(&self) -> Result<Vec<MigrationRecord>, Error>;
    fn mark_applied(&mut self, version: u64, name: &str) -> Result<(), Error>;
    fn mark_rolled_back(&mut self, version: u64) -> Result<(), Error>;

    // Provided methods
    fn is_applied(&self, version: u64) -> Result<bool, Error> { ... }
    fn current_version(&self) -> Result<u64, Error> { ... }
}
Expand description

Storage backend for tracking applied migrations.

Implement this trait to store migration state in your preferred backend:

  • SQLite, PostgreSQL, MySQL
  • JSON/YAML file
  • Redis, etcd
  • In-memory (for testing)

The store is responsible for:

  • Initializing any required schema/structure
  • Recording when migrations are applied/rolled back
  • Querying which migrations have been applied

Required Methods§

Source

fn init(&mut self) -> Result<(), Error>

Initialize the store (create tables, files, etc.)

Source

fn applied(&self) -> Result<Vec<MigrationRecord>, Error>

Get all applied migrations, sorted by version ascending

Source

fn mark_applied(&mut self, version: u64, name: &str) -> Result<(), Error>

Record a migration as applied

Source

fn mark_rolled_back(&mut self, version: u64) -> Result<(), Error>

Record a migration as rolled back (remove from applied)

Provided Methods§

Source

fn is_applied(&self, version: u64) -> Result<bool, Error>

Check if a specific version has been applied

Source

fn current_version(&self) -> Result<u64, Error>

Get the highest applied version (0 if none)

Implementors§