Skip to content

Instantly share code, notes, and snippets.

@davidhagg
Created July 13, 2015 06:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save davidhagg/d6e45e002325e3e1c3cd to your computer and use it in GitHub Desktop.
Save davidhagg/d6e45e002325e3e1c3cd to your computer and use it in GitHub Desktop.
private void ExecuteMigrationScripts(IEnumerable<KeyValuePair<IMigrationScriptFile, string>> scripts, Action<DbTransaction, long> updateVersionAction)
{
using (DbTransaction tran = Database.BeginTransaction())
{
IMigrationScriptFile currentScript = null;
try
{
foreach (var script in scripts)
{
currentScript = script.Key;
Database.ExecuteScript(tran, script.Value);
updateVersionAction(tran, script.Key.Version);
}
tran.Commit();
}
catch (Exception ex)
{
tran.Rollback();
string filePath = (currentScript == null) ? "NULL" : currentScript.FilePath;
throw new MigrationException("Error executing migration script: " + filePath, filePath, ex);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment