Skip to main content

run_migrate_embedded

Function run_migrate_embedded 

Source
pub async fn run_migrate_embedded(
    conn: &impl DbConnection,
    migrations: &[EmbeddedMigration<'_>],
    dialect: Dialect,
) -> Result<u32, MigrateError>
Expand description

Applies pending migrations from an in-memory list instead of a directory.

The counterpart to run_migrate, and identical to it below the byte-fetch: same _migrations bookkeeping, same hash check, same one-transaction-per-migration boundary. A database migrated from a directory and one migrated from the equivalent list are indistinguishable, so a project can switch sources between releases.

Migrations apply in slice order, which is the caller’s declaration of order just as _journal.json is on disk — they are not sorted by name. Entries already in _migrations are skipped, so the count is how many were newly applied.

§Errors

Returns MigrateError::DuplicateMigration when two entries share a name, before anything is written; MigrateError::HashMismatch when an entry’s SQL no longer matches its declared hash, leaving earlier entries applied; or MigrateError::Database when a statement fails, rolling that migration back whole.