C# Class SimpleMigrations.DatabaseProvider.DatabaseProviderBaseWithVersionTableLock

DatabaseProviderBase subclass for databases which use a transaction on the VersionInfo table to guard against concurrent migrators.
This uses two connections for each operation: one which uses a transaction to acquire a lock on the VersionInfo table and to update it, and another to run migrations on.
Inheritance: DatabaseProviderBase
ファイルを表示 Open project: canton7/SimpleMigrations

Public Methods

Method Description
BeginOperation ( ) : DbConnection

Called when SimpleMigrator{TConnection, TMigrationBase}.MigrateTo(long) or SimpleMigrator{TConnection, TMigrationBase}.Baseline(long) is invoked, before any migrations are run. This creates the VersionTableConnection and MigrationsConnection, and invokes AcquireVersionTableLock to acquire the VersionInfo table lock.

DatabaseProviderBaseWithVersionTableLock ( Func connectionFactory ) : System

Initialises a new instance of the DatabaseProviderBaseWithVersionTableLock class

EndOperation ( ) : void

Called after migrations are run, this invokes AcquireVersionTableLock to release the VersionInfo table lock, and then closes VersionTableConnection and MigrationsConnection"/>

EnsureCreatedAndGetCurrentVersion ( ) : long

Ensures that the version table is created, and returns the current version.

This is not surrounded by calls to BeginOperation or EndOperation, so it should create its own connection. If the version table is empty, this should return 0.

GetCurrentVersion ( ) : long

Fetch the current database schema version, or 0.

This method is always invoked after a call to BeginOperation, but before a call to EndOperation. It should use VersionTableConnection and VersionTableLockTransaction

UpdateVersion ( long oldVersion, long newVersion, string newDescription ) : void

Update the VersionInfo table to indicate that the given migration was successfully applied.

This is always invoked after a call to BeginOperation but before a call to EndOperation, It should use VersionTableConnection and VersionTableLockTransaction

Protected Methods

Method Description
AcquireVersionTableLock ( ) : void

Creates and sets VersionTableLockTransaction, and uses it to lock the VersionInfo table

ReleaseVersionTableLock ( ) : void

Destroys VersionTableLockTransaction, thus releasing the VersionInfo table lock

Method Details

AcquireVersionTableLock() protected abstract method

Creates and sets VersionTableLockTransaction, and uses it to lock the VersionInfo table
protected abstract AcquireVersionTableLock ( ) : void
return void

BeginOperation() public method

Called when SimpleMigrator{TConnection, TMigrationBase}.MigrateTo(long) or SimpleMigrator{TConnection, TMigrationBase}.Baseline(long) is invoked, before any migrations are run. This creates the VersionTableConnection and MigrationsConnection, and invokes AcquireVersionTableLock to acquire the VersionInfo table lock.
public BeginOperation ( ) : DbConnection
return System.Data.Common.DbConnection

DatabaseProviderBaseWithVersionTableLock() public method

Initialises a new instance of the DatabaseProviderBaseWithVersionTableLock class
public DatabaseProviderBaseWithVersionTableLock ( Func connectionFactory ) : System
connectionFactory Func Factory to be used to create new connections
return System

EndOperation() public method

Called after migrations are run, this invokes AcquireVersionTableLock to release the VersionInfo table lock, and then closes VersionTableConnection and MigrationsConnection"/>
public EndOperation ( ) : void
return void

EnsureCreatedAndGetCurrentVersion() public method

Ensures that the version table is created, and returns the current version.
This is not surrounded by calls to BeginOperation or EndOperation, so it should create its own connection. If the version table is empty, this should return 0.
public EnsureCreatedAndGetCurrentVersion ( ) : long
return long

GetCurrentVersion() public method

Fetch the current database schema version, or 0.
This method is always invoked after a call to BeginOperation, but before a call to EndOperation. It should use VersionTableConnection and VersionTableLockTransaction
public GetCurrentVersion ( ) : long
return long

ReleaseVersionTableLock() protected abstract method

Destroys VersionTableLockTransaction, thus releasing the VersionInfo table lock
protected abstract ReleaseVersionTableLock ( ) : void
return void

UpdateVersion() public method

Update the VersionInfo table to indicate that the given migration was successfully applied.
This is always invoked after a call to BeginOperation but before a call to EndOperation, It should use VersionTableConnection and VersionTableLockTransaction
public UpdateVersion ( long oldVersion, long newVersion, string newDescription ) : void
oldVersion long The previous version of the database schema
newVersion long The version of the new database schema
newDescription string The description of the migration which was applied
return void