public void ThrowIfNoMigrationForVersion() { Assembly assembly = Assembly.Load("ECM7.Migrator.TestAssembly"); MigrationAssembly migrationAssembly = new MigrationAssembly(assembly); Assert.Throws <Exception>(() => migrationAssembly.GetMigrationInfo(99999999)); }
public void ThrowIfNoMigrationForVersion() { Assembly assembly = GetType().GetTypeInfo().Assembly; MigrationAssembly migrationAssembly = new MigrationAssembly(assembly); Assert.Throws <Exception>(() => migrationAssembly.GetMigrationInfo(99999999)); }
public void ForNullProviderShouldThrowException() { Assembly assembly = Assembly.Load("ECM7.Migrator.TestAssembly"); var loader = new MigrationAssembly(assembly); var mi = loader.GetMigrationInfo(1); Assert.Throws <Exception>(() => loader.InstantiateMigration(mi, null)); }
public void ForNullProviderShouldThrowException() { Assembly assembly = GetType().GetTypeInfo().Assembly; var loader = new MigrationAssembly(assembly); var mi = loader.GetMigrationInfo(1); Assert.Throws <ArgumentNullException>(() => loader.InstantiateMigration(mi, null)); }
public void CanCreateMigrationObject() { Assembly assembly = Assembly.Load("ECM7.Migrator.TestAssembly"); MigrationAssembly migrationAssembly = new MigrationAssembly(assembly); Mock <ITransformationProvider> provider = new Mock <ITransformationProvider>(); var mi = migrationAssembly.GetMigrationInfo(2); IMigration migration = migrationAssembly.InstantiateMigration(mi, provider.Object); Assert.IsNotNull(migration); Assert.That(migration is SecondTestMigration); Assert.AreSame(provider.Object, migration.Database); }
public void CanCreateMigrationObject() { Assembly assembly = GetType().GetTypeInfo().Assembly; MigrationAssembly migrationAssembly = new MigrationAssembly(assembly); Mock <ITransformationProvider> provider = new Mock <ITransformationProvider>(); var mi = migrationAssembly.GetMigrationInfo(2); Migration migration = migrationAssembly.InstantiateMigration(mi, provider.Object); Assert.NotNull(migration); Assert.True(migration is TestMigration02); Assert.Same(provider.Object, migration.Database); }
/// <summary> /// ���������� �������� /// </summary> /// <param name="targetVersion">������ ����������� ��������</param> /// <param name="currentDatabaseVersion">������� ������ ��</param> public void ExecuteMigration(long targetVersion, long currentDatabaseVersion) { var migrationInfo = migrationAssembly.GetMigrationInfo(targetVersion); Migration migration = migrationAssembly.InstantiateMigration(migrationInfo, Provider); try { if (!migrationInfo.WithoutTransaction) { Provider.BeginTransaction(); } if (targetVersion <= currentDatabaseVersion) { Logger.MigrateDown(targetVersion, migration.Name); migration.Revert(); Provider.MigrationUnApplied(targetVersion, Key); } else { Logger.MigrateUp(targetVersion, migration.Name); migration.Apply(); Provider.MigrationApplied(targetVersion, Key); } if (!migrationInfo.WithoutTransaction) { Provider.Commit(); } } catch (Exception ex) { Logger.Exception(targetVersion, migration.Name, ex); if (!migrationInfo.WithoutTransaction) { // если изменения выполняются в транзакции, откатываем // изменения текущей миграции, которые успели выполниться Provider.Rollback(); Logger.RollingBack(currentDatabaseVersion); } throw; } }
/// <summary> /// Выполнение миграции /// </summary> /// <param name="targetVersion">Версия выполняемой миграции</param> /// <param name="currentDatabaseVersion">Текущая версия БД</param> public void ExecuteMigration(long targetVersion, long currentDatabaseVersion) { var migrationInfo = migrationAssembly.GetMigrationInfo(targetVersion); IMigration migration = migrationAssembly.InstantiateMigration(migrationInfo, provider); try { if (!migrationInfo.WithoutTransaction) { provider.BeginTransaction(); } if (targetVersion <= currentDatabaseVersion) { MigratorLogManager.Log.MigrateDown(targetVersion, migration.Name); migration.Revert(); provider.MigrationUnApplied(targetVersion, Key); } else { MigratorLogManager.Log.MigrateUp(targetVersion, migration.Name); migration.Apply(); provider.MigrationApplied(targetVersion, Key); } if (!migrationInfo.WithoutTransaction) { provider.Commit(); } } catch (Exception ex) { MigratorLogManager.Log.Exception(targetVersion, migration.Name, ex); if (!migrationInfo.WithoutTransaction) { // при ошибке откатываем изменения provider.Rollback(); MigratorLogManager.Log.RollingBack(currentDatabaseVersion); } throw; } }