Exemplo n.º 1
0
        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());
        }
Exemplo n.º 2
0
 /// <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);
     }
 }
Exemplo n.º 3
0
        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);
        }
Exemplo n.º 4
0
        /// <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);
        }
Exemplo n.º 5
0
        private static string GetAssemblyFolder(IMigrationTask migrationTask)
        {
            var fileInfo = new FileInfo(migrationTask.GetType().Assembly.Location);

            return(fileInfo.DirectoryName);
        }
Exemplo n.º 6
0
 /// <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 + "]";
 }
Exemplo n.º 7
0
 /// <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);
 }
Exemplo n.º 8
0
        /// <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;
            }
        }
Exemplo n.º 9
0
 public void AddMigration(IMigrationTask migration)
 {
     this.migrations.Add(migration);
 }
Exemplo n.º 10
0
 void process_MigrationSuccessful(IMigrationTask task, IMigrationContext context, MigrationException e)
 {
     succeeded = true;
 }
Exemplo n.º 11
0
 void process_MigrationStarted(IMigrationTask task, IMigrationContext context, MigrationException e)
 {
     started = true;
 }
Exemplo n.º 12
0
 void process_MigrationFailed(IMigrationTask task, IMigrationContext context, MigrationException e)
 {
     failed = true;
 }
Exemplo n.º 13
0
        /// <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);
            }
        }
Exemplo n.º 14
0
 /// <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);
 }
Exemplo n.º 15
0
 /// <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);
 }