pub trait MigrationPersistence: Send + Sync {
    // Required methods
    fn baseline_initialize(&mut self) -> BoxFuture<'_, ConnectorResult<()>>;
    fn initialize(
        &mut self,
        namespaces: Option<Namespaces>
    ) -> BoxFuture<'_, ConnectorResult<()>>;
    fn mark_migration_applied_impl<'a>(
        &'a mut self,
        migration_name: &'a str,
        checksum: &'a str
    ) -> BoxFuture<'a, ConnectorResult<String>>;
    fn mark_migration_rolled_back_by_id<'a>(
        &'a mut self,
        migration_id: &'a str
    ) -> BoxFuture<'a, ConnectorResult<()>>;
    fn record_migration_started_impl<'a>(
        &'a mut self,
        migration_name: &'a str,
        checksum: &'a str
    ) -> BoxFuture<'a, ConnectorResult<String>>;
    fn record_successful_step<'a>(
        &'a mut self,
        id: &'a str
    ) -> BoxFuture<'a, ConnectorResult<()>>;
    fn record_failed_step<'a>(
        &'a mut self,
        id: &'a str,
        logs: &'a str
    ) -> BoxFuture<'a, ConnectorResult<()>>;
    fn record_migration_finished<'a>(
        &'a mut self,
        id: &'a str
    ) -> BoxFuture<'a, ConnectorResult<()>>;
    fn list_migrations(
        &mut self
    ) -> BoxFuture<'_, ConnectorResult<Result<Vec<MigrationRecord>, PersistenceNotInitializedError>>>;

    // Provided methods
    fn mark_migration_applied<'a>(
        &'a mut self,
        migration_name: &'a str,
        script: &'a str
    ) -> BoxFuture<'a, ConnectorResult<String>> { ... }
    fn record_migration_started<'a>(
        &'a mut self,
        migration_name: &'a str,
        script: &'a str
    ) -> BoxFuture<'a, ConnectorResult<String>> { ... }
}
Expand description

Management of imperative migrations state in the database.

Required Methods§

source

fn baseline_initialize(&mut self) -> BoxFuture<'_, ConnectorResult<()>>

Initialize the migration persistence without checking the database first.

source

fn initialize( &mut self, namespaces: Option<Namespaces> ) -> BoxFuture<'_, ConnectorResult<()>>

This method is responsible for checking whether the migrations persistence is initialized.

If the migration persistence is not present in the target database, check whether the database schema is empty. If it is, initialize the migration persistence. If not, return a DatabaseSchemaNotEmpty error.

source

fn mark_migration_applied_impl<'a>( &'a mut self, migration_name: &'a str, checksum: &'a str ) -> BoxFuture<'a, ConnectorResult<String>>

Implementation in the connector for the core’s MarkMigrationApplied command. See the docs there. Note that the started_at and finished_at for the migration should be the same.

source

fn mark_migration_rolled_back_by_id<'a>( &'a mut self, migration_id: &'a str ) -> BoxFuture<'a, ConnectorResult<()>>

Mark the failed instances of the migration in the persistence as rolled back, so they will be ignored by the engine in the future.

source

fn record_migration_started_impl<'a>( &'a mut self, migration_name: &'a str, checksum: &'a str ) -> BoxFuture<'a, ConnectorResult<String>>

Record that a migration is about to be applied. Returns the unique identifier for the migration.

This is an implementation detail, consumers should use record_migration_started() instead.

source

fn record_successful_step<'a>( &'a mut self, id: &'a str ) -> BoxFuture<'a, ConnectorResult<()>>

Increase the applied_steps_count counter.

source

fn record_failed_step<'a>( &'a mut self, id: &'a str, logs: &'a str ) -> BoxFuture<'a, ConnectorResult<()>>

Report logs for a failed migration step. We assume the next steps in the migration will not be applied, and the error reported.

source

fn record_migration_finished<'a>( &'a mut self, id: &'a str ) -> BoxFuture<'a, ConnectorResult<()>>

Record that the migration completed successfully. This means populating the finished_at field in the migration record.

source

fn list_migrations( &mut self ) -> BoxFuture<'_, ConnectorResult<Result<Vec<MigrationRecord>, PersistenceNotInitializedError>>>

List all applied migrations, ordered by started_at. This should fail with a PersistenceNotInitializedError when the migration persistence is not initialized.

Provided Methods§

source

fn mark_migration_applied<'a>( &'a mut self, migration_name: &'a str, script: &'a str ) -> BoxFuture<'a, ConnectorResult<String>>

Implementation in the connector for the core’s MarkMigrationApplied command. See the docs there. Note that the started_at and finished_at for the migration should be the same.

Connectors should implement mark_migration_applied_impl to avoid doing the checksuming themselves.

source

fn record_migration_started<'a>( &'a mut self, migration_name: &'a str, script: &'a str ) -> BoxFuture<'a, ConnectorResult<String>>

Record that a migration is about to be applied. Returns the unique identifier for the migration.

This is a default method that computes the checksum. Implementors should implement record_migration_started_impl.

Implementors§