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§
sourcefn migration_from(&self) -> Result<Option<Cow<'_, str>>>where
Self: Sized,
fn migration_from(&self) -> Result<Option<Cow<'_, str>>>where
Self: Sized,
Get the name of the migration before this one (if any).
sourcefn up_sql(&self, backend_name: &str) -> Result<Option<String>>
fn up_sql(&self, backend_name: &str) -> Result<Option<String>>
The backend-specific commands to apply this migration.
sourcefn down_sql(&self, backend_name: &str) -> Result<Option<String>>
fn down_sql(&self, backend_name: &str) -> Result<Option<String>>
The backend-specific commands to undo this migration.
sourcefn sql_backends(&self) -> Result<Vec<String>>
fn sql_backends(&self) -> Result<Vec<String>>
The names of the backends this migration has sql for.
Provided Methods§
sourcefn apply(&self, conn: &mut impl BackendConnection) -> Result<()>
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
sourcefn mark_applied(&self, conn: &impl ConnectionMethods) -> Result<()>
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.
sourcefn downgrade(&self, conn: &mut impl BackendConnection) -> Result<()>
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.