use of org.flywaydb.core.internal.metadatatable.AppliedMigration in project flyway by flyway.
the class DbBaselineTest method sameBaselineMarkerPresentWithoutMigrations.
@Test
public void sameBaselineMarkerPresentWithoutMigrations() {
// arrange
AppliedMigration baseline = new AppliedMigration(TEST_BASELINE_VERSION, TEST_BASELINE_DESCRIPTION, MigrationType.BASELINE, "V2.0.0__test-migration.sql", 12345, 100, true);
when(this.metaDataTable.hasBaselineMarker()).thenReturn(true);
when(this.metaDataTable.getBaselineMarker()).thenReturn(baseline);
when(this.metaDataTable.hasAppliedMigrations()).thenReturn(false);
// act
this.testBaseline.baseline();
// assert
verify(metaDataTable, never()).addBaselineMarker(Mockito.<MigrationVersion>anyObject(), anyString());
}
use of org.flywaydb.core.internal.metadatatable.AppliedMigration in project flyway by flyway.
the class DbBaseline method baseline.
/**
* Baselines the database.
*/
public void baseline() {
try {
for (final FlywayCallback callback : callbacks) {
new TransactionTemplate(connection).execute(new Callable<Object>() {
@Override
public Object call() throws SQLException {
dbSupport.changeCurrentSchemaTo(schema);
callback.beforeBaseline(connection);
return null;
}
});
}
new TransactionTemplate(connection).execute(new Callable<Object>() {
@Override
public Void call() {
dbSupport.changeCurrentSchemaTo(schema);
if (metaDataTable.hasBaselineMarker()) {
AppliedMigration baselineMarker = metaDataTable.getBaselineMarker();
if (baselineVersion.equals(baselineMarker.getVersion()) && baselineDescription.equals(baselineMarker.getDescription())) {
LOG.info("Metadata table " + metaDataTable + " already initialized with (" + baselineVersion + "," + baselineDescription + "). Skipping.");
return null;
}
throw new FlywayException("Unable to baseline metadata table " + metaDataTable + " with (" + baselineVersion + "," + baselineDescription + ") as it has already been initialized with (" + baselineMarker.getVersion() + "," + baselineMarker.getDescription() + ")");
}
if (metaDataTable.hasSchemasMarker() && baselineVersion.equals(MigrationVersion.fromVersion("0"))) {
throw new FlywayException("Unable to baseline metadata table " + metaDataTable + " with version 0 as this version was used for schema creation");
}
if (metaDataTable.hasAppliedMigrations()) {
throw new FlywayException("Unable to baseline metadata table " + metaDataTable + " as it already contains migrations");
}
metaDataTable.addBaselineMarker(baselineVersion, baselineDescription);
return null;
}
});
LOG.info("Successfully baselined schema with version: " + baselineVersion);
for (final FlywayCallback callback : callbacks) {
new TransactionTemplate(connection).execute(new Callable<Object>() {
@Override
public Object call() throws SQLException {
dbSupport.changeCurrentSchemaTo(schema);
callback.afterBaseline(connection);
return null;
}
});
}
} finally {
dbSupport.restoreCurrentSchema();
}
}
use of org.flywaydb.core.internal.metadatatable.AppliedMigration in project flyway by flyway.
the class DbRepair method repairChecksumsAndDescriptions.
public void repairChecksumsAndDescriptions() {
migrationInfoService.refresh();
for (MigrationInfo migrationInfo : migrationInfoService.all()) {
MigrationInfoImpl migrationInfoImpl = (MigrationInfoImpl) migrationInfo;
ResolvedMigration resolved = migrationInfoImpl.getResolvedMigration();
AppliedMigration applied = migrationInfoImpl.getAppliedMigration();
if (resolved != null && applied != null && resolved.getVersion() != null) {
if (!ObjectUtils.nullSafeEquals(resolved.getChecksum(), applied.getChecksum()) || !ObjectUtils.nullSafeEquals(resolved.getDescription(), applied.getDescription())) {
metaDataTable.update(migrationInfoImpl.getVersion(), resolved.getDescription(), resolved.getChecksum());
}
}
}
}
use of org.flywaydb.core.internal.metadatatable.AppliedMigration in project flyway by flyway.
the class MigrationInfoDumperSmallTest method createMetaDataTable.
/**
* Creates a metadata table for testing.
*
* @return The metadata table.
*/
private MetaDataTable createMetaDataTable() {
MetaDataTable metaDataTable = mock(MetaDataTable.class);
when(metaDataTable.allAppliedMigrations()).thenReturn(new ArrayList<AppliedMigration>());
return metaDataTable;
}
use of org.flywaydb.core.internal.metadatatable.AppliedMigration in project flyway by flyway.
the class MigrationInfoImplSmallTest method validateFuture.
@Test
public void validateFuture() {
MigrationVersion version = MigrationVersion.fromVersion("1");
String description = "test";
MigrationType type = MigrationType.SQL;
AppliedMigration appliedMigration = new AppliedMigration(1, version, description, type, null, 123, new Date(), "abc", 0, true);
MigrationInfoImpl migrationInfo = new MigrationInfoImpl(null, appliedMigration, new MigrationInfoContext(), false);
String message = migrationInfo.validate();
assertTrue(message, message.contains("not resolved"));
}
Aggregations