use of liquibase.exception.ValidationFailedException in project dropwizard by dropwizard.
the class AbstractLiquibaseCommand method run.
@Override
@SuppressWarnings("UseOfSystemOutOrSystemErr")
protected void run(Bootstrap<T> bootstrap, Namespace namespace, T configuration) throws Exception {
final PooledDataSourceFactory dbConfig = strategy.getDataSourceFactory(configuration);
dbConfig.asSingleConnectionPool();
try (final CloseableLiquibase liquibase = openLiquibase(dbConfig, namespace)) {
run(namespace, liquibase);
} catch (ValidationFailedException e) {
e.printDescriptiveError(System.err);
throw e;
}
}
use of liquibase.exception.ValidationFailedException in project liquibase by liquibase.
the class DatabaseChangeLog method validate.
public void validate(Database database, Contexts contexts, LabelExpression labelExpression) throws LiquibaseException {
ChangeLogIterator logIterator = new ChangeLogIterator(this, new DbmsChangeSetFilter(database), new ContextChangeSetFilter(contexts), new LabelChangeSetFilter(labelExpression));
ValidatingVisitor validatingVisitor = new ValidatingVisitor(database.getRanChangeSetList());
validatingVisitor.validate(database, this);
logIterator.run(validatingVisitor, new RuntimeEnvironment(database, contexts, labelExpression));
for (String message : validatingVisitor.getWarnings().getMessages()) {
LogFactory.getLogger().warning(message);
}
if (!validatingVisitor.validationPassed()) {
throw new ValidationFailedException(validatingVisitor);
}
}
use of liquibase.exception.ValidationFailedException in project liquibase by liquibase.
the class AbstractMssqlIntegrationTest method smartDataLoad.
@Test
public void smartDataLoad() throws Exception {
if (this.getDatabase() == null) {
return;
}
Liquibase liquibase = createLiquibase("changelogs/common/smartDataLoad.changelog.xml");
clearDatabase(liquibase);
try {
liquibase.update(this.contexts);
} catch (ValidationFailedException e) {
e.printDescriptiveError(System.out);
throw e;
}
try {
liquibase.rollback(new Date(0), this.contexts);
} catch (ValidationFailedException e) {
e.printDescriptiveError(System.out);
throw e;
}
}
use of liquibase.exception.ValidationFailedException in project liquibase by liquibase.
the class OracleIntegrationTest method indexCreatedOnCorrectSchema.
@Test
public void indexCreatedOnCorrectSchema() throws Exception {
if (this.getDatabase() == null) {
return;
}
Liquibase liquibase = createLiquibase(this.indexOnSchemaChangeLog);
clearDatabase(liquibase);
try {
liquibase.update(this.contexts);
} catch (ValidationFailedException e) {
e.printDescriptiveError(System.out);
throw e;
}
Statement queryIndex = ((JdbcConnection) this.getDatabase().getConnection()).getUnderlyingConnection().createStatement();
ResultSet indexOwner = queryIndex.executeQuery("SELECT owner FROM ALL_INDEXES WHERE index_name = 'IDX_BOOK_ID'");
assertTrue(indexOwner.next());
String owner = indexOwner.getString("owner");
assertEquals("LIQUIBASEB", owner);
// check that the automatically rollback now works too
try {
liquibase.rollback(new Date(0), this.contexts);
} catch (ValidationFailedException e) {
e.printDescriptiveError(System.out);
throw e;
}
}
use of liquibase.exception.ValidationFailedException in project liquibase by liquibase.
the class AbstractIntegrationTest method testRerunDiffChangeLogAltSchema.
@Test
public void testRerunDiffChangeLogAltSchema() throws Exception {
if (database == null) {
return;
}
if (!database.supportsSchemas()) {
return;
}
Liquibase liquibase = createLiquibase(includedChangeLog);
clearDatabase(liquibase);
database.setDefaultSchemaName("lbcat2");
LockService lockService = LockServiceFactory.getInstance().getLockService(database);
lockService.forceReleaseLock();
liquibase.update(includedChangeLog);
DatabaseSnapshot originalSnapshot = SnapshotGeneratorFactory.getInstance().createSnapshot(database.getDefaultSchema(), database, new SnapshotControl(database));
CompareControl compareControl = new CompareControl(new CompareControl.SchemaComparison[] { new CompareControl.SchemaComparison(CatalogAndSchema.DEFAULT, new CatalogAndSchema(null, "lbcat2")) }, originalSnapshot.getSnapshotControl().getTypesToInclude());
DiffResult diffResult = DiffGeneratorFactory.getInstance().compare(database, null, compareControl);
File tempFile = File.createTempFile("liquibase-test", ".xml");
FileOutputStream output = new FileOutputStream(tempFile);
try {
new DiffToChangeLog(diffResult, new DiffOutputControl()).print(new PrintStream(output));
output.flush();
} finally {
output.close();
}
liquibase = createLiquibase(tempFile.getName());
clearDatabase(liquibase);
//run again to test changelog testing logic
Executor executor = ExecutorService.getInstance().getExecutor(database);
try {
executor.execute(new DropTableStatement("lbcat2", "lbcat2", database.getDatabaseChangeLogTableName(), false));
} catch (DatabaseException e) {
//ok
}
try {
executor.execute(new DropTableStatement("lbcat2", "lbcat2", database.getDatabaseChangeLogLockTableName(), false));
} catch (DatabaseException e) {
//ok
}
database.commit();
DatabaseConnection connection = DatabaseTestContext.getInstance().getConnection(url);
database = DatabaseFactory.getInstance().findCorrectDatabaseImplementation(connection);
database.setDefaultSchemaName("lbcat2");
liquibase = createLiquibase(tempFile.getName());
try {
liquibase.update(this.contexts);
} catch (ValidationFailedException e) {
e.printDescriptiveError(System.out);
throw e;
}
tempFile.deleteOnExit();
DatabaseSnapshot finalSnapshot = SnapshotGeneratorFactory.getInstance().createSnapshot(database.getDefaultSchema(), database, new SnapshotControl(database));
CompareControl finalCompareControl = new CompareControl();
finalCompareControl.addSuppressedField(Column.class, "autoIncrementInformation");
DiffResult finalDiffResult = DiffGeneratorFactory.getInstance().compare(originalSnapshot, finalSnapshot, finalCompareControl);
new DiffToReport(finalDiffResult, System.out).print();
assertTrue(finalDiffResult.areEqual());
}
Aggregations