Search in sources :

Example 1 with DropTableStatement

use of liquibase.statement.core.DropTableStatement in project liquibase by liquibase.

the class AbstractJdbcDatabaseTest method executeRollbackStatements_WithStatementsOverload_ShouldIncludeAppendTextFromApplyToRollbackTrueVisitor.

@Test
public void executeRollbackStatements_WithStatementsOverload_ShouldIncludeAppendTextFromApplyToRollbackTrueVisitor() throws Exception {
    Database database = getDatabase();
    final MockExecutor mockExecutor = new MockExecutor();
    ExecutorService.getInstance().setExecutor(database, mockExecutor);
    final List<SqlVisitor> sqlVisitors = new ArrayList<SqlVisitor>();
    final SqlStatement dropTableStatement = new DropTableStatement(null, null, "test_table", false);
    final AppendSqlVisitor appendSqlVisitor = new AppendSqlVisitor();
    appendSqlVisitor.setApplyToRollback(true);
    appendSqlVisitor.setValue(" SHOULD BE APPENDED");
    sqlVisitors.add(appendSqlVisitor);
    database.executeRollbackStatements(new SqlStatement[] { dropTableStatement }, sqlVisitors);
    assertEquals("DROP TABLE test_table SHOULD BE APPENDED;", mockExecutor.getRanSql().trim());
}
Also used : AppendSqlVisitor(liquibase.sql.visitor.AppendSqlVisitor) SqlStatement(liquibase.statement.SqlStatement) MockExecutor(liquibase.sdk.executor.MockExecutor) ArrayList(java.util.ArrayList) DropTableStatement(liquibase.statement.core.DropTableStatement) SqlVisitor(liquibase.sql.visitor.SqlVisitor) AppendSqlVisitor(liquibase.sql.visitor.AppendSqlVisitor) Test(org.junit.Test)

Example 2 with DropTableStatement

use of liquibase.statement.core.DropTableStatement 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)

Example 3 with DropTableStatement

use of liquibase.statement.core.DropTableStatement in project liquibase by liquibase.

the class AbstractJdbcDatabaseTest method executeRollbackStatements_WithStatementsOverload_ShouldNotIncludeAppendTextFromApplyToRollbackFalseVisitor.

@Test
public void executeRollbackStatements_WithStatementsOverload_ShouldNotIncludeAppendTextFromApplyToRollbackFalseVisitor() throws Exception {
    Database database = getDatabase();
    final MockExecutor mockExecutor = new MockExecutor();
    ExecutorService.getInstance().setExecutor(database, mockExecutor);
    final List<SqlVisitor> sqlVisitors = new ArrayList<SqlVisitor>();
    final SqlStatement dropTableStatement = new DropTableStatement(null, null, "test_table", false);
    final AppendSqlVisitor appendSqlVisitor = new AppendSqlVisitor();
    appendSqlVisitor.setApplyToRollback(false);
    appendSqlVisitor.setValue(" SHOULD NOT BE APPENDED");
    sqlVisitors.add(appendSqlVisitor);
    database.executeRollbackStatements(new SqlStatement[] { dropTableStatement }, sqlVisitors);
    assertEquals("DROP TABLE test_table;", mockExecutor.getRanSql().trim());
}
Also used : AppendSqlVisitor(liquibase.sql.visitor.AppendSqlVisitor) SqlStatement(liquibase.statement.SqlStatement) MockExecutor(liquibase.sdk.executor.MockExecutor) ArrayList(java.util.ArrayList) DropTableStatement(liquibase.statement.core.DropTableStatement) SqlVisitor(liquibase.sql.visitor.SqlVisitor) AppendSqlVisitor(liquibase.sql.visitor.AppendSqlVisitor) Test(org.junit.Test)

Aggregations

DropTableStatement (liquibase.statement.core.DropTableStatement)3 Test (org.junit.Test)3 ArrayList (java.util.ArrayList)2 MockExecutor (liquibase.sdk.executor.MockExecutor)2 AppendSqlVisitor (liquibase.sql.visitor.AppendSqlVisitor)2 SqlVisitor (liquibase.sql.visitor.SqlVisitor)2 SqlStatement (liquibase.statement.SqlStatement)2 CatalogAndSchema (liquibase.CatalogAndSchema)1 Liquibase (liquibase.Liquibase)1 DatabaseConnection (liquibase.database.DatabaseConnection)1 DiffResult (liquibase.diff.DiffResult)1 CompareControl (liquibase.diff.compare.CompareControl)1 DiffOutputControl (liquibase.diff.output.DiffOutputControl)1 DiffToChangeLog (liquibase.diff.output.changelog.DiffToChangeLog)1 DiffToReport (liquibase.diff.output.report.DiffToReport)1 DatabaseException (liquibase.exception.DatabaseException)1 ValidationFailedException (liquibase.exception.ValidationFailedException)1 Executor (liquibase.executor.Executor)1 LockService (liquibase.lockservice.LockService)1 DatabaseSnapshot (liquibase.snapshot.DatabaseSnapshot)1