public void FlagMigrationAsFinished(IUmbracoMigration migration) { var migrationName = migration.GetType().Name; var migrationHistory = UmbracoDatabase.Single <MigrationHistory>("WHERE Name = @Name", new { Name = migrationName }); migrationHistory.Completed = true; UmbracoDatabase.Update(migrationHistory); }
private void ProcessMigration(IUmbracoMigration umbracoMigration) { if (_databaseUtil.HasMigrationExecuted(umbracoMigration)) { return; } _databaseUtil.FlagMigrationAsStarted(umbracoMigration); _databaseUtil.UmbracoDatabase.OpenSharedConnection(); try { _databaseUtil.UmbracoDatabase.BeginTransaction(); Log.Info(string.Format("========== Executing migration {0} ==========", umbracoMigration.GetType().FullName)); umbracoMigration.Migrate(); Log.Info(string.Format("---------- Executed migration {0} ----------", umbracoMigration.GetType().FullName)); _databaseUtil.FlagMigrationAsFinished(umbracoMigration); Log.Info("Transaction completed"); _databaseUtil.UmbracoDatabase.CompleteTransaction(); } catch (Exception exception) { Log.Error("Transaction aborted.", exception); _databaseUtil.UmbracoDatabase.AbortTransaction(); throw; } finally { Log.Info("Shared connection closed."); _databaseUtil.UmbracoDatabase.CloseSharedConnection(); } }
public bool HasMigrationExecuted(IUmbracoMigration migration) { var migrationName = migration.GetType().Name; try { UmbracoDatabase.OpenSharedConnection(); using (var transaction = GetTransaction()) { var migrationHistory = UmbracoDatabase.FirstOrDefault <MigrationHistory>("WHERE Name = @Name", new { Name = migrationName }); var hasMigrationExecuted = migrationHistory != null; Log.Debug(string.Format("HasMigrationExecuted for {0} is {1}", migrationName, hasMigrationExecuted)); transaction.Complete(); return(hasMigrationExecuted); } } finally { UmbracoDatabase.CloseSharedConnection(); } }
public void FlagMigrationAsStarted(IUmbracoMigration migration) { try { UmbracoDatabase.OpenSharedConnection(); using (var transaction = GetTransaction()) { var row = new MigrationHistory { Completed = false, Name = migration.GetType().Name, Timestamp = DateTime.UtcNow }; UmbracoDatabase.Insert(row); transaction.Complete(); } } finally { UmbracoDatabase.CloseSharedConnection(); } }
public MigrationStartingEventArgs([NotNull] IUmbracoMigration migration, [NotNull] IMigrationContext context) : base(migration, context) { }
public MigrationEventArgs([NotNull] IUmbracoMigration migration, [NotNull] IMigrationContext context) : base(context) { Migration = Argument.NotNull("migration", migration); }
public EmbeddedResourceHelper(IUmbracoMigration migration) { _migration = migration; }