Base solution for your next web application
Open Closed

Rollback Strategy #2938


User avatar
0
maharatha created

I am currently working on a Roll back Strategy and this is what I am currently doing.

I am making changes to the migrator tool . First of all I am getting the last migration applied :

var query = "select top 1 MigrationId from __MigrationHistory order by LEFT(MigrationId, 15) desc"; var migrationId = context.Database.SqlQuery<string>(query).FirstOrDefault();

I somehow have to apply this migration if something goes wrong. Something like :

_migrator.RollbackForHost(migrationid);

Can you help me on this ?


3 Answer(s)
  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi,

    Sorry for the delay.

    You can try to do it like this.

    var migrator = new DbMigrator(new Migrations.Configuration());
    migrator.Update(migrationId );
    

    I haven't tried it but I would like to hear your feedback.

    Thanks.

  • User Avatar
    0
    maharatha created

    Yes it works , but I have created a roll back method something like the below :

    public void RollBack(string strlastGoodMigration, string dbconnString)
            {
                
                var configuration = new Migrations.Configuration();
                var migrator = new DbMigrator(configuration);
                configuration.TargetDatabase = new DbConnectionInfo(dbconnString, "System.Data.SqlClient");
                migrator.Update();
    
                Log.Write("Rollback Completed");
    
            }
    

    When a build is completed I am storing the last applied migration in App.config.

    So if we want to roll back this build then we just deploy the roll back with the the proper Release parameter and it should roll back to the current build.

  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi,

    Thanks @maharatha. So, as I understand it is working for you, right ?