Habanero.DB.DBMigrator.Migrate C# (CSharp) Method

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
        public void Migrate(int startAfterVersion, int endVersion)
        {
            //Each migration should be done separately because changes to DDL does not support rollback.
            var stepsToRun = endVersion - startAfterVersion;
            startAfterVersion++;
            if (stepsToRun > 0 && this.OnDbMigrationStarted != null)
                this.OnDbMigrationStarted(this, new DBMigratorEventArgs((uint)startAfterVersion, (uint)startAfterVersion, (uint)endVersion));
            for (int i = startAfterVersion; i <= endVersion; i++)
            {
                try
                {
                    _connection.ExecuteSql(GetMigrationSql(i - 1, i).ToArray());
                }
                catch (Exception ex)
                {
                    if (this.OnDbMigrationException != null)
                        this.OnDbMigrationException(this, new DBMigratorEventArgs((uint)startAfterVersion, (uint)i, (uint)endVersion));
                    throw ex;
                }
                SetCurrentVersion(i);
                if (this.OnDbMigrationProgress != null)
                    this.OnDbMigrationProgress(this, new DBMigratorEventArgs((uint)startAfterVersion, (uint)i, (uint)endVersion));
            }
            if (stepsToRun > 0 && this.OnDbMigrationCompleted != null)
                this.OnDbMigrationCompleted(this, new DBMigratorEventArgs((uint)startAfterVersion, (uint)endVersion, (uint)endVersion));
        }