예제 #1
0
        public static void Migrate(IMigrationLogger MigrationLogger = null, bool update_database = false)
        {
            SchemaUpdate schemaUpdate = new SchemaUpdate(_configuration);

            if (MigrationLogger == null)
            {
                schemaUpdate.Execute(false, update_database);
            }

            Migrator.Migrate(schemaUpdate, MigrationLogger, update_database);
        }
        /// <summary>
        /// Initialises a new instance of the <see cref="MigrationRunData{TConnection}"/> class
        /// </summary>
        /// <param name="connection">Connection to use to run the migration</param>
        /// <param name="logger">Logger to use to log SQL statements run, and other messages</param>
        /// <param name="direction">Direction to run the migration in</param>
        public MigrationRunData(TConnection connection, IMigrationLogger logger, MigrationDirection direction)
        {
            if (connection == null)
            {
                throw new ArgumentNullException(nameof(connection));
            }
            if (logger == null)
            {
                throw new ArgumentNullException(nameof(logger));
            }

            this.Connection = connection;
            this.Logger     = logger;
            this.Direction  = direction;
        }
예제 #3
0
        public MigrationContext(
            [NotNull] IServiceContext services,
            [NotNull] UmbracoDatabase database,
            [NotNull] CacheHelper cacheHelper,
            [NotNull] IMigrationRecordRepository migrationRecords,
            [NotNull] MigrationConfiguration configuration,
            [CanBeNull] IMigrationLogger logger = null
            )
        {
            Services         = Argument.NotNull(nameof(services), services);
            Database         = Argument.NotNull(nameof(database), database);
            MigrationRecords = Argument.NotNull(nameof(migrationRecords), migrationRecords);
            Configuration    = Argument.NotNull(nameof(configuration), configuration);
            Logger           = logger;

            _cacheHelper = cacheHelper;
        }
예제 #4
0
        void IMigration <DbConnection> .Execute(DbConnection connection, IMigrationLogger logger, MigrationDirection direction)
        {
            this.Connection = connection;
            this.Logger     = logger;

            if (this.UseTransaction)
            {
                using (this.Transaction = connection.BeginTransaction(IsolationLevel.Serializable))
                {
                    try
                    {
                        if (direction == MigrationDirection.Up)
                        {
                            this.Up();
                        }
                        else
                        {
                            this.Down();
                        }

                        this.Transaction.Commit();
                    }
                    catch
                    {
                        this.Transaction?.Rollback();
                        throw;
                    }
                    finally
                    {
                        this.Transaction = null;
                    }
                }
            }
            else
            {
                if (direction == MigrationDirection.Up)
                {
                    this.Up();
                }
                else
                {
                    this.Down();
                }
            }
        }
예제 #5
0
        void IMigration <IDbConnection> .RunMigration(MigrationRunData <IDbConnection> data)
        {
            using (TransactionScope scope = new TransactionScope(TransactionScopeOption.Required, TimeSpan.FromMinutes(10)))
            {
                Connection = data.Connection;
                Logger     = data.Logger;

                if (data.Direction == MigrationDirection.Up)
                {
                    Up();
                    Down();
                    Up();
                }
                else
                {
                    Down();
                }

                scope.Complete();
            }
        }
예제 #6
0
        void IMigration <SQLiteConnection> .RunMigration(MigrationRunData <SQLiteConnection> data)
        {
            this.Connection = data.Connection;
            this.Logger     = data.Logger;

            if (this.UseTransaction)
            {
                try
                {
                    this.Connection.BeginTransaction();

                    if (data.Direction == MigrationDirection.Up)
                    {
                        this.Up();
                    }
                    else
                    {
                        this.Down();
                    }

                    this.Connection.Commit();
                }
                catch
                {
                    this.Connection.Rollback();
                    throw;
                }
            }
            else
            {
                if (data.Direction == MigrationDirection.Up)
                {
                    this.Up();
                }
                else
                {
                    this.Down();
                }
            }
        }
예제 #7
0
        void IMigration <SQLiteConnection> .Execute(SQLiteConnection connection, IMigrationLogger logger, MigrationDirection direction)
        {
            this.Connection = connection;
            this.Logger     = logger;

            if (this.UseTransaction)
            {
                try
                {
                    connection.BeginTransaction();

                    if (direction == MigrationDirection.Up)
                    {
                        this.Up();
                    }
                    else
                    {
                        this.Down();
                    }

                    connection.Commit();
                }
                catch
                {
                    connection.Rollback();
                    throw;
                }
            }
            else
            {
                if (direction == MigrationDirection.Up)
                {
                    this.Up();
                }
                else
                {
                    this.Down();
                }
            }
        }
예제 #8
0
 public static void Migrate(SchemaUpdate schemaUpdate, IMigrationLogger migrationLogger, bool update_database = false)
 {
     schemaUpdate.Execute(migrationLogger.Log(), update_database);
 }
예제 #9
0
 public IMigrationContext WithLogger(IMigrationLogger logger)
 {
     return(new MigrationContext(Services, Database, _cacheHelper, MigrationRecords, Configuration, logger));
 }
예제 #10
0
 /// <summary>
 /// Logs the given log entry with information level
 /// </summary>
 /// <param name="logger">The logger instance</param>
 /// <param name="exception">An optional exception</param>
 /// <param name="messageFormat">The message format</param>
 public static void LogInformation(this IMigrationLogger logger, Exception exception, string messageFormat) =>
 logger.Log(MigrationLogLevel.Information, exception, messageFormat, EmptyArgs);
예제 #11
0
 /// <summary>
 /// Logs the given log entry with debug level
 /// </summary>
 /// <param name="logger">The logger instance</param>
 /// <param name="exception">An optional exception</param>
 /// <param name="messageFormat">The message format</param>
 /// <param name="args">An optional collection of message format arguments</param>
 public static void LogDebug(this IMigrationLogger logger, Exception exception, string messageFormat, params string[] args) =>
 logger.Log(MigrationLogLevel.Debug, exception, messageFormat, args);
예제 #12
0
 /// <summary>
 /// Logs the given log entry
 /// </summary>
 /// <param name="logger">The logger instance</param>
 /// <param name="level">The log level</param>
 /// <param name="exception">An optional exception</param>
 /// <param name="messageFormat">The message format</param>
 public static void Log(this IMigrationLogger logger, MigrationLogLevel level, Exception exception, string messageFormat) =>
 logger.Log(level, exception, messageFormat);
예제 #13
0
 /// <summary>
 /// Creates a logger scope with the given information.
 /// </summary>
 /// <param name="logger">The logger instance</param>
 /// <param name="messageFormat">The message format</param>
 /// <returns>The disposable logger scope</returns>
 public static IDisposable Scope(this IMigrationLogger logger, string messageFormat) =>
 logger.Scope(messageFormat, EmptyArgs);
예제 #14
0
 public void Execute(IDbConnection connection, IMigrationLogger logger, MigrationDirection direction)
 {
     throw new NotImplementedException();
 }