pub struct MigrationEngine { /* private fields */ }Expand description
The migration engine manages schema versioning for a SQLite database.
Implementations§
Source§impl MigrationEngine
impl MigrationEngine
Sourcepub fn new(conn: Arc<Mutex<Connection>>) -> PunchResult<Self>
pub fn new(conn: Arc<Mutex<Connection>>) -> PunchResult<Self>
Create a new engine and ensure the tracking table exists.
Sourcepub fn current_version(&self) -> PunchResult<u64>
pub fn current_version(&self) -> PunchResult<u64>
Return the highest applied migration version, or 0 if none.
Sourcepub fn pending_migrations<'a>(
&self,
all: &'a [Migration],
) -> PunchResult<Vec<&'a Migration>>
pub fn pending_migrations<'a>( &self, all: &'a [Migration], ) -> PunchResult<Vec<&'a Migration>>
Return migrations from all that have not yet been applied, sorted by
version ascending.
Sourcepub fn migrate_up(&self, migrations: &[Migration]) -> PunchResult<Vec<u64>>
pub fn migrate_up(&self, migrations: &[Migration]) -> PunchResult<Vec<u64>>
Apply all pending migrations in order. Each migration runs inside its own transaction. Returns the versions that were applied.
Sourcepub fn migrate_down(
&self,
migrations: &[Migration],
target_version: u64,
) -> PunchResult<Vec<u64>>
pub fn migrate_down( &self, migrations: &[Migration], target_version: u64, ) -> PunchResult<Vec<u64>>
Roll back applied migrations whose version is greater than
target_version, in reverse order. Returns the versions that were
rolled back.
Sourcepub fn migration_status(
&self,
migrations: &[Migration],
) -> PunchResult<Vec<MigrationStatus>>
pub fn migration_status( &self, migrations: &[Migration], ) -> PunchResult<Vec<MigrationStatus>>
Show the status (applied / pending) of every known migration.
Sourcepub fn verify_checksums(&self, migrations: &[Migration]) -> PunchResult<()>
pub fn verify_checksums(&self, migrations: &[Migration]) -> PunchResult<()>
Verify that every applied migration’s stored checksum matches the
current up_sql content. Returns an error on the first mismatch.
Sourcepub fn builtin_migrations() -> Vec<Migration>
pub fn builtin_migrations() -> Vec<Migration>
Return the 6 built-in migrations that define the Punch schema.