/// <summary>
        /// Instantiate and execute a single migration
        /// </summary>
        /// <param name="direction">Diretion to run the migration in</param>
        /// <param name="migrationData"><see cref="MigrationData"/> describing to migration to instantiate and execute</param>
        /// <param name="connection">Connection to use to execute the migration</param>
        protected virtual void RunMigration(MigrationDirection direction, MigrationData migrationData, TConnection connection)
        {
            var migration = this.CreateMigration(migrationData);
            var data      = new MigrationRunData <TConnection>(connection, this.Logger ?? NullLogger.Instance, direction);

            migration.RunMigration(data);
        }
Beispiel #2
0
        void IMigration <DbConnection> .RunMigration(MigrationRunData <DbConnection> data)
        {
            this.Connection = data.Connection;
            this.Logger     = data.Logger;

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

                        this.Transaction.Commit();
                    }
                    catch
                    {
                        this.Transaction?.Rollback();
                        throw;
                    }
                    finally
                    {
                        this.Transaction = null;
                    }
                }
            }
            else
            {
                if (data.Direction == MigrationDirection.Up)
                {
                    this.Up();
                }
                else
                {
                    this.Down();
                }
            }
        }