Search in sources :

Example 6 with ValidationFailedException

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;
    }
}
Also used : ValidationFailedException(liquibase.exception.ValidationFailedException) PooledDataSourceFactory(io.dropwizard.db.PooledDataSourceFactory)

Example 7 with ValidationFailedException

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);
    }
}
Also used : LabelChangeSetFilter(liquibase.changelog.filter.LabelChangeSetFilter) ValidatingVisitor(liquibase.changelog.visitor.ValidatingVisitor) RuntimeEnvironment(liquibase.RuntimeEnvironment) ValidationFailedException(liquibase.exception.ValidationFailedException) ContextChangeSetFilter(liquibase.changelog.filter.ContextChangeSetFilter) DbmsChangeSetFilter(liquibase.changelog.filter.DbmsChangeSetFilter)

Example 8 with ValidationFailedException

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;
    }
}
Also used : Liquibase(liquibase.Liquibase) ValidationFailedException(liquibase.exception.ValidationFailedException) Date(java.util.Date) AbstractIntegrationTest(liquibase.dbtest.AbstractIntegrationTest) Test(org.junit.Test)

Example 9 with ValidationFailedException

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;
    }
}
Also used : Liquibase(liquibase.Liquibase) ValidationFailedException(liquibase.exception.ValidationFailedException) Statement(java.sql.Statement) ResultSet(java.sql.ResultSet) Date(java.util.Date) AbstractIntegrationTest(liquibase.dbtest.AbstractIntegrationTest) Test(org.junit.Test)

Example 10 with ValidationFailedException

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());
}
Also used : LockService(liquibase.lockservice.LockService) DiffOutputControl(liquibase.diff.output.DiffOutputControl) CatalogAndSchema(liquibase.CatalogAndSchema) Liquibase(liquibase.Liquibase) Executor(liquibase.executor.Executor) ValidationFailedException(liquibase.exception.ValidationFailedException) DiffToReport(liquibase.diff.output.report.DiffToReport) CompareControl(liquibase.diff.compare.CompareControl) DiffToChangeLog(liquibase.diff.output.changelog.DiffToChangeLog) DatabaseConnection(liquibase.database.DatabaseConnection) DiffResult(liquibase.diff.DiffResult) DatabaseSnapshot(liquibase.snapshot.DatabaseSnapshot) SnapshotControl(liquibase.snapshot.SnapshotControl) DropTableStatement(liquibase.statement.core.DropTableStatement) DatabaseException(liquibase.exception.DatabaseException) Test(org.junit.Test)

Aggregations

ValidationFailedException (liquibase.exception.ValidationFailedException)11 Liquibase (liquibase.Liquibase)9 Test (org.junit.Test)8 AbstractIntegrationTest (liquibase.dbtest.AbstractIntegrationTest)6 Date (java.util.Date)4 ResultSet (java.sql.ResultSet)2 Statement (java.sql.Statement)2 DiffResult (liquibase.diff.DiffResult)2 CompareControl (liquibase.diff.compare.CompareControl)2 DiffOutputControl (liquibase.diff.output.DiffOutputControl)2 DiffToChangeLog (liquibase.diff.output.changelog.DiffToChangeLog)2 DiffToReport (liquibase.diff.output.report.DiffToReport)2 DatabaseSnapshot (liquibase.snapshot.DatabaseSnapshot)2 SnapshotControl (liquibase.snapshot.SnapshotControl)2 PooledDataSourceFactory (io.dropwizard.db.PooledDataSourceFactory)1 CatalogAndSchema (liquibase.CatalogAndSchema)1 RuntimeEnvironment (liquibase.RuntimeEnvironment)1 ContextChangeSetFilter (liquibase.changelog.filter.ContextChangeSetFilter)1 DbmsChangeSetFilter (liquibase.changelog.filter.DbmsChangeSetFilter)1 LabelChangeSetFilter (liquibase.changelog.filter.LabelChangeSetFilter)1