private static IConfiguration LoadPluginConfiguration(IMigrationTask migrationTask) { var builder = new ConfigurationBuilder() .SetBasePath(GetAssemblyFolder(migrationTask)) .AddJsonFile("pluginsettings.json", true) .AddJsonFile($"pluginsettings.{GetEnvironmentName()}.json", true) .AddEnvironmentVariables("VOLLEYM_MIGRATION_"); return(builder.Build()); }
/// <summary> /// Circumvents actual SQL task migration code and records its "execution" to the test migration /// context. It allows the actual execution of .NET code patches. /// </summary> /// <param name="context">the migration context</param> /// <param name="task">the task to migrate</param> public override void MigrateTask(IMigrationContext context, IMigrationTask task) { if (task is SqlScriptMigrationTask) { ((TestMigrationContext)context).RecordExecution(task.Name); } else { base.MigrateTask(context, task); } }
private static async Task RunMigrationTask(IMigrationTask migrationTask) { IConfiguration config = LoadPluginConfiguration(migrationTask); Log.Debug("Migration started for {MigrationName}.", migrationTask.GetType().Name); await migrationTask.Initialize(config); Log.Debug("Initialized {MigrationName} migration.", migrationTask.GetType().Name); await migrationTask.MigrateUp(); Log.Debug("Migration {MigrationName} complete.", migrationTask.GetType().Name); }
/// <seealso cref="IComparable.CompareTo(Object)"/> public int CompareTo(IMigrationTask task) { if (!task.Level.HasValue) { return 1; } Int32 taskLevel = task.Level.Value; Int32 curLevel = Level.Value; return curLevel.CompareTo(taskLevel); }
private static string GetAssemblyFolder(IMigrationTask migrationTask) { var fileInfo = new FileInfo(migrationTask.GetType().Assembly.Location); return(fileInfo.DirectoryName); }
/// <summary> /// Returns a user-friendly label for the specified task. /// </summary> /// <param name="task">the task to create a label for</param> /// <returns>a user-friendly label for the specified task</returns> protected String GetTaskLabel(IMigrationTask task) { return task.Name + " [" + task.GetType().FullName + "]"; }
/// <summary> /// Performs the operation of task migration. /// </summary> /// <param name="context">the migration context</param> /// <param name="task">the task to migrate</param> public virtual void MigrateTask(IMigrationContext context, IMigrationTask task) { task.Migrate(context); }
/// <summary> /// Apply a single patch. /// </summary> /// <param name="context"> /// the context the patch will need during application /// </param> /// <param name="task"> /// the application task to carry out /// </param> /// <param name="broadcast"> /// whether to broadcast to listeners that the patch applied /// </param> /// <exception cref="MigrationException">if the patch application fails </exception> public virtual void ApplyPatch(IMigrationContext context, IMigrationTask task, bool broadcast) { String label = GetTaskLabel(task); if (broadcast) { if (MigrationStarted != null) { MigrationStarted(task, context, null); //broadcaster.notifyListeners(task, context, MigrationBroadcaster.TASK_START); //log.Debug("broadcaster has " + broadcaster.Listeners.Count + " listeners"); } } log.Info("Running migration task \"" + label + "\"..."); //Console.WriteLine("Running migration task \"" + label + "\"..."); try { long startTime = DateTime.Now.Ticks; MigrateTask(context, task); long duration = (DateTime.Now.Ticks - startTime) / TimeSpan.TicksPerMillisecond; log.Info("Finished migration task \"" + label + "\" (" + duration + " millis.)"); //Console.WriteLine("Finished migration task \"" + label + "\" (" + duration + " millis.)"); if (broadcast) { if (MigrationSuccessful != null) { MigrationSuccessful(task, context, null); //broadcaster.notifyListeners(task, context, MigrationBroadcaster.TASK_SUCCESS); } } context.Commit(); } catch (MigrationException e) { if (broadcast) { if (MigrationFailed != null) { MigrationFailed(task, context, e); //broadcaster.notifyListeners(task, context, e, MigrationBroadcaster.TASK_FAILED); } } try { context.Rollback(); log.Info("Migration failed; rollback successful"); //Console.WriteLine("Migration failed; rollback successful"); } catch (MigrationException me) { log.Info("Migration failed; COULD NOT ROLL BACK TRANSACTION", me); //Console.WriteLine("Migration failed; COULD NOT ROLL BACK TRANSACTION"); } throw e; } }
public void AddMigration(IMigrationTask migration) { this.migrations.Add(migration); }
void process_MigrationSuccessful(IMigrationTask task, IMigrationContext context, MigrationException e) { succeeded = true; }
void process_MigrationStarted(IMigrationTask task, IMigrationContext context, MigrationException e) { started = true; }
void process_MigrationFailed(IMigrationTask task, IMigrationContext context, MigrationException e) { failed = true; }
/// <seealso cref="MigrationProcess.MigrationStatusEventHandler(IMigrationTask, IMigrationContext, MigrationException)"/> public void MigrationSuccessful(IMigrationTask task, IMigrationContext ctx, MigrationException e) { log.Debug("Task " + task.Name + " was successful for context " + ctx + " in launcher " + this); int patchLevel = task.Level.Value; // update all of our controlled patch tables foreach (IPatchInfoStore patchInfoStore in contexts.Values) { patchInfoStore.UpdatePatchLevel(patchLevel); } }
/// <seealso cref="MigrationProcess.MigrationStatusEventHandler(IMigrationTask, IMigrationContext, MigrationException)"/> public void MigrationStarted(IMigrationTask task, IMigrationContext ctx, MigrationException e) { log.Debug("Started task " + task.Name + " for context " + ctx); }
/// <seealso cref="MigrationProcess.MigrationStatusEventHandler(IMigrationTask, IMigrationContext, MigrationException)"/> public void MigrationFailed(IMigrationTask task, IMigrationContext ctx, MigrationException e) { log.Debug("Task " + task.Name + " failed for context " + ctx, e); }