Trait butane_core::migrations::Migration

source ·
pub trait Migration: Debug + PartialEq {
    // Required methods
    fn db(&self) -> Result<ADB>;
    fn migration_from(&self) -> Result<Option<Cow<'_, str>>>
       where Self: Sized;
    fn name(&self) -> Cow<'_, str>;
    fn up_sql(&self, backend_name: &str) -> Result<Option<String>>;
    fn down_sql(&self, backend_name: &str) -> Result<Option<String>>;
    fn sql_backends(&self) -> Result<Vec<String>>;

    // Provided methods
    fn apply(&self, conn: &mut impl BackendConnection) -> Result<()> { ... }
    fn mark_applied(&self, conn: &impl ConnectionMethods) -> Result<()> { ... }
    fn downgrade(&self, conn: &mut impl BackendConnection) -> Result<()> { ... }
}
Expand description

Type representing a database migration. A migration describes how to bring the database from state A to state B. In general, the methods on this type are persistent – they read from and write to the filesystem.

A Migration cannot be constructed directly, only retrieved from Migrations.

Required Methods§

source

fn db(&self) -> Result<ADB>

Retrieves the full abstract database state describing all tables

source

fn migration_from(&self) -> Result<Option<Cow<'_, str>>>
where Self: Sized,

Get the name of the migration before this one (if any).

source

fn name(&self) -> Cow<'_, str>

The name of this migration.

source

fn up_sql(&self, backend_name: &str) -> Result<Option<String>>

The backend-specific commands to apply this migration.

source

fn down_sql(&self, backend_name: &str) -> Result<Option<String>>

The backend-specific commands to undo this migration.

source

fn sql_backends(&self) -> Result<Vec<String>>

The names of the backends this migration has sql for.

Provided Methods§

source

fn apply(&self, conn: &mut impl BackendConnection) -> Result<()>

Apply the migration to a database connection. The connection must be for the same type of database as this and the database must be in the state of the migration prior to this one

source

fn mark_applied(&self, conn: &impl ConnectionMethods) -> Result<()>

Mark the migration as being applied without doing any work. Use carefully – the caller must ensure that the database schema already matches that expected by this migration.

source

fn downgrade(&self, conn: &mut impl BackendConnection) -> Result<()>

Un-apply (downgrade) the migration to a database connection. The connection must be for the same type of database as this and this must be the latest migration applied to the database.

Object Safety§

This trait is not object safe.

Implementors§