C# Class Habanero.DB.DBMigrator

Manages database migrations that are needed to ensure that working copies of a project have the up-to-date database structure.
This migrator requires access to an ISettings service that can read and write a a DATABASE_VERSION setting. Since ConfigFileSettings does not have write support, you will either need to use DatabaseSettings or reimplement a settings operator. The setting will need to be in existence before this operation will execute correctly.
This class is commonly used inside an implementation of IApplicationVersionUpgrader . See the tutorials for usage examples.
Show file Open project: Chillisoft/habanero Class Usage Examples

Public Methods

Method Description
AddMigration ( int number, SqlStatement sql ) : void

Adds a sql migration that can be performed

AddMigration ( int number, string sql ) : void

Adds a sql migration that can be performed

CurrentVersion ( ) : int

Returns the current version number

DBMigrator ( IDatabaseConnection connection ) : System

Constructor to initialise the migrator with the connection provided

GetMigration ( int number ) : ISqlStatement

Returns the sql migration statement with the version number specified

GetMigrationSql ( int startAfterVersion, int endVersion ) : IEnumerable

Returns a set of sql statements between two specified version numbers, excluding the start version and including the end version.

LatestVersion ( ) : int

Returns the most recent migration version number available

Migrate ( int startAfterVersion, int endVersion ) : void

Performs the migrations from after the start version up to and including the end version. Updates the stored version number to the end version number specified.

MigrateTo ( int version ) : void

Carries out all migrations from the current version to the version specified. Note: The DBMigrator currently only supports forward migrations.

MigrateToLatestVersion ( ) : void

Performs all migrations available from the current version number to the most recent version available. This is the common-case method used to carry out a migration, unless you require more specific control.

SetCurrentVersion ( int version ) : void

Sets the current version number to that specified

SetSettingsStorer ( ISettings storer ) : void

Sets this instance's settings storer to that specified

Method Details

AddMigration() public method

Adds a sql migration that can be performed
public AddMigration ( int number, SqlStatement sql ) : void
number int The migration number
sql SqlStatement The sql statement object to add
return void

AddMigration() public method

Adds a sql migration that can be performed
public AddMigration ( int number, string sql ) : void
number int The migration number
sql string The sql statement string to add
return void

CurrentVersion() public method

Returns the current version number
Thrown if the /// settings storer has not been assigned
public CurrentVersion ( ) : int
return int

DBMigrator() public method

Constructor to initialise the migrator with the connection provided
public DBMigrator ( IDatabaseConnection connection ) : System
connection IDatabaseConnection The database connection
return System

GetMigration() public method

Returns the sql migration statement with the version number specified
public GetMigration ( int number ) : ISqlStatement
number int The version number
return ISqlStatement

GetMigrationSql() public method

Returns a set of sql statements between two specified version numbers, excluding the start version and including the end version.
public GetMigrationSql ( int startAfterVersion, int endVersion ) : IEnumerable
startAfterVersion int The start version number (exclusive)
endVersion int The end version number (inclusive)
return IEnumerable

LatestVersion() public method

Returns the most recent migration version number available
public LatestVersion ( ) : int
return int

Migrate() public method

Performs the migrations from after the start version up to and including the end version. Updates the stored version number to the end version number specified.
public Migrate ( int startAfterVersion, int endVersion ) : void
startAfterVersion int The start version (exclusive)
endVersion int The end version (inclusive)
return void

MigrateTo() public method

Carries out all migrations from the current version to the version specified. Note: The DBMigrator currently only supports forward migrations.
public MigrateTo ( int version ) : void
version int The version number to migrate to (inclusive)
return void

MigrateToLatestVersion() public method

Performs all migrations available from the current version number to the most recent version available. This is the common-case method used to carry out a migration, unless you require more specific control.
public MigrateToLatestVersion ( ) : void
return void

SetCurrentVersion() public method

Sets the current version number to that specified
public SetCurrentVersion ( int version ) : void
version int The version number to set to
return void

SetSettingsStorer() public method

Sets this instance's settings storer to that specified
public SetSettingsStorer ( ISettings storer ) : void
storer ISettings The settings storer
return void