示例#1
0
        /// <summary>
        /// Execute the migrations left
        /// </summary>
        /// <returns>An object defining the migration result</returns>
        private MigrationResult RunOutstandingMigrations()
        {
            Log("Running migrations" + (isPreview ? " (preview mode)" : ""));
            Log();

            var result = new MigrationResult();

            Migration current = null;

            try
            {
                foreach (var m in Migrations)
                {
                    current = m;
                    result.Attempted++;
                    switch (Migrate(m))
                    {
                    case MigrateMode.Skip:
                        result.Skipped++;
                        break;

                    case MigrateMode.Run:
                        result.Ran++;
                        break;

                    case MigrateMode.HashMismatch:
                        result.Forced++;
                        break;

                    case MigrateMode.Rename:
                        result.Renamed++;
                        break;

                    default:
                        throw new ArgumentOutOfRangeException();
                    }
                }

                if (db.HasPendingTransaction)
                {
                    db.Commit();
                }

                result.Success = true;
            }
            catch (Exception ex)
            {
                result.Success   = false;
                result.Exception = ex;

                MigrationFailed(current, ex);
            }

            Log($"Attempted {result.Attempted} migrations.");
            if (result.Ran > 0)
            {
                Log($"  Ran:     {result.Ran}");
            }
            if (result.Forced > 0)
            {
                Log($"  Forced:  {result.Forced}");
            }
            if (result.Skipped > 0)
            {
                Log($"  Skipped: {result.Skipped}");
            }
            if (result.Renamed > 0)
            {
                Log($"  Renamed: {result.Renamed}");
            }

            Log();
            Log((result.Success ? "SUCCESS" : "FAIL") + (isPreview ? " (preview mode)" : ""));

            return(result);
        }