Search in sources :

Example 1 with CreateTableChange

use of liquibase.change.core.CreateTableChange in project liquibase by liquibase.

the class ChangeFactoryTest method create_badClass.

@Test(expected = UnexpectedLiquibaseException.class)
public void create_badClass() {
    ChangeFactory.getInstance().register(SometimesExceptionThrowingChange.class);
    Change change = ChangeFactory.getInstance().create("createTable");
    assertNotNull(change);
    assertTrue(change instanceof CreateTableChange);
}
Also used : CreateTableChange(liquibase.change.core.CreateTableChange) AddAutoIncrementChange(liquibase.change.core.AddAutoIncrementChange) DropTableChange(liquibase.change.core.DropTableChange) CreateTableChange(liquibase.change.core.CreateTableChange) Test(org.junit.Test)

Example 2 with CreateTableChange

use of liquibase.change.core.CreateTableChange in project liquibase by liquibase.

the class PostgreSQLIntegrationTest method testMissingDataGenerator.

@Test
public void testMissingDataGenerator() throws Exception {
    Scope.getCurrentScope().getSingleton(ExecutorService.class).getExecutor("jdbc", getDatabase()).execute(new RawSqlStatement("CREATE TABLE \"FIRST_TABLE\" (\"ID\" INT, \"NAME\" VARCHAR(20), \"LAST_NAME\" VARCHAR(20) DEFAULT 'Snow', " + "\"AGE\" INT DEFAULT 25, \"REGISTRATION_DATE\" date DEFAULT TO_DATE('2014-08-11', 'YYYY-MM-DD'), " + "\"COMPVALCOL\" INT DEFAULT 1*22)"));
    Scope.getCurrentScope().getSingleton(ExecutorService.class).getExecutor("jdbc", getDatabase()).execute(new RawSqlStatement("CREATE TABLE \"SECOND_TABLE\" (\"ID\" INT, \"NAME\" VARCHAR(20))"));
    Scope.getCurrentScope().getSingleton(ExecutorService.class).getExecutor("jdbc", getDatabase()).execute(new RawSqlStatement("ALTER TABLE \"FIRST_TABLE\" ADD CONSTRAINT \"FIRST_TABLE_PK\" PRIMARY KEY (\"ID\")"));
    Scope.getCurrentScope().getSingleton(ExecutorService.class).getExecutor("jdbc", getDatabase()).execute(new RawSqlStatement("ALTER TABLE \"SECOND_TABLE\" ADD CONSTRAINT \"FIRST_TABLE_FK\" FOREIGN KEY (\"ID\") REFERENCES \"FIRST_TABLE\"(\"ID\")"));
    Scope.getCurrentScope().getSingleton(ExecutorService.class).getExecutor("jdbc", getDatabase()).execute(new RawSqlStatement("CREATE INDEX \"IDX_FIRST_TABLE\" ON \"FIRST_TABLE\"(\"NAME\")"));
    Scope.getCurrentScope().getSingleton(ExecutorService.class).getExecutor("jdbc", getDatabase()).execute(new RawSqlStatement("INSERT INTO \"FIRST_TABLE\"(\"ID\", \"NAME\") VALUES (1, 'JOHN')"));
    Scope.getCurrentScope().getSingleton(ExecutorService.class).getExecutor("jdbc", getDatabase()).execute(new RawSqlStatement("INSERT INTO \"FIRST_TABLE\"(\"ID\", \"NAME\", \"LAST_NAME\", \"AGE\", \"REGISTRATION_DATE\", \"COMPVALCOL\") VALUES (2, 'JEREMY', 'IRONS', 71, TO_DATE('2020-04-01', 'YYYY-MM-DD'), 2*11 )"));
    Scope.getCurrentScope().getSingleton(ExecutorService.class).getExecutor("jdbc", getDatabase()).execute(new RawSqlStatement("INSERT INTO \"SECOND_TABLE\"(\"ID\", \"NAME\") VALUES (1, 'JOHN')"));
    Scope.getCurrentScope().getSingleton(ExecutorService.class).getExecutor("jdbc", getDatabase()).execute(new RawSqlStatement("INSERT INTO \"SECOND_TABLE\"(\"ID\", \"NAME\") VALUES (2, 'JEREMY')"));
    DiffResult diffResult = DiffGeneratorFactory.getInstance().compare(getDatabase(), null, new CompareControl());
    DiffToChangeLog changeLogWriter = new DiffToChangeLog(diffResult, new DiffOutputControl(false, false, false, null));
    List<ChangeSet> changeSets = changeLogWriter.generateChangeSets();
    boolean found = false;
    for (ChangeSet changeSet : changeSets) {
        List<Change> changes = changeSet.getChanges();
        for (Change change : changes) {
            if (!(change instanceof CreateTableChange)) {
                continue;
            }
            found = ((CreateTableChange) change).getTableName().equals("FIRST_TABLE");
            if (found) {
                break;
            }
        }
        if (found) {
            break;
        }
    }
    Assert.assertTrue("There should be a table named \"FIRST_TABLE\"", found);
}
Also used : RawSqlStatement(liquibase.statement.core.RawSqlStatement) CreateTableChange(liquibase.change.core.CreateTableChange) CompareControl(liquibase.diff.compare.CompareControl) DiffOutputControl(liquibase.diff.output.DiffOutputControl) DiffToChangeLog(liquibase.diff.output.changelog.DiffToChangeLog) DiffResult(liquibase.diff.DiffResult) Change(liquibase.change.Change) CreateTableChange(liquibase.change.core.CreateTableChange) AddPrimaryKeyChange(liquibase.change.core.AddPrimaryKeyChange) ChangeSet(liquibase.changelog.ChangeSet) Test(org.junit.Test) AbstractIntegrationTest(liquibase.dbtest.AbstractIntegrationTest)

Example 3 with CreateTableChange

use of liquibase.change.core.CreateTableChange in project liquibase by liquibase.

the class AbstractJdbcDatabaseTest method executeRollbackStatements_WithChangeOverload_ShouldNotIncludeAppendTextFromApplyToRollbackFalseVisitor.

@Test
public void executeRollbackStatements_WithChangeOverload_ShouldNotIncludeAppendTextFromApplyToRollbackFalseVisitor() throws Exception {
    Database database = getDatabase();
    final MockExecutor mockExecutor = new MockExecutor();
    Scope.getCurrentScope().getSingleton(ExecutorService.class).setExecutor("jdbc", database, mockExecutor);
    final List<SqlVisitor> sqlVisitors = new ArrayList<SqlVisitor>();
    final CreateTableChange change = new CreateTableChange();
    change.setTableName("test_table");
    final AppendSqlVisitor appendSqlVisitor = new AppendSqlVisitor();
    appendSqlVisitor.setApplyToRollback(false);
    appendSqlVisitor.setValue(" SHOULD NOT BE APPENDED");
    sqlVisitors.add(appendSqlVisitor);
    database.executeRollbackStatements(change, sqlVisitors);
    assertEquals("DROP TABLE test_table;", mockExecutor.getRanSql().trim());
}
Also used : AppendSqlVisitor(liquibase.sql.visitor.AppendSqlVisitor) MockExecutor(liquibase.sdk.executor.MockExecutor) ExecutorService(liquibase.executor.ExecutorService) ArrayList(java.util.ArrayList) CreateTableChange(liquibase.change.core.CreateTableChange) SqlVisitor(liquibase.sql.visitor.SqlVisitor) AppendSqlVisitor(liquibase.sql.visitor.AppendSqlVisitor) Test(org.junit.Test)

Example 4 with CreateTableChange

use of liquibase.change.core.CreateTableChange in project liquibase by liquibase.

the class ValidatingVisitorPreConditionsTest method setUp.

/**
 * Create a DatabaseChangelog, one changeset, and a create sequence change
 */
@Before
public void setUp() {
    changeLog = new DatabaseChangeLog();
    changeSet1 = new ChangeSet("1", "testAuthor", false, false, "path/changelog", null, null, null);
    changeLog.addChangeSet(changeSet1);
    CreateTableChange change1 = new CreateTableChange();
    change1.setTableName("valid_test");
    change1.addColumn(new ColumnConfig().setName("id").setType("int"));
    changeSet1.addChange(change1);
}
Also used : ColumnConfig(liquibase.change.ColumnConfig) CreateTableChange(liquibase.change.core.CreateTableChange) RanChangeSet(liquibase.changelog.RanChangeSet) ChangeSet(liquibase.changelog.ChangeSet) DatabaseChangeLog(liquibase.changelog.DatabaseChangeLog) Before(org.junit.Before)

Example 5 with CreateTableChange

use of liquibase.change.core.CreateTableChange in project liquibase by liquibase.

the class ValidatingVisitorTest method visit_setupException.

@Test
public void visit_setupException() throws Exception {
    changeSet1.addChange(new CreateTableChange() {

        @Override
        public void finishInitialization() throws SetupException {
            throw new SetupException("Test message");
        }
    });
    ValidatingVisitor handler = new ValidatingVisitor(new ArrayList<RanChangeSet>());
    handler.visit(changeSet1, new DatabaseChangeLog(), null, null);
    assertEquals(1, handler.getSetupExceptions().size());
    assertEquals("Test message", handler.getSetupExceptions().get(0).getMessage());
    assertFalse(handler.validationPassed());
}
Also used : SetupException(liquibase.exception.SetupException) CreateTableChange(liquibase.change.core.CreateTableChange) DatabaseChangeLog(liquibase.changelog.DatabaseChangeLog) RanChangeSet(liquibase.changelog.RanChangeSet) Test(org.junit.Test)

Aggregations

CreateTableChange (liquibase.change.core.CreateTableChange)13 Test (org.junit.Test)10 ColumnConfig (liquibase.change.ColumnConfig)5 DatabaseChangeLog (liquibase.changelog.DatabaseChangeLog)5 RanChangeSet (liquibase.changelog.RanChangeSet)5 ArrayList (java.util.ArrayList)4 ChangeSet (liquibase.changelog.ChangeSet)3 MockDatabase (liquibase.database.core.MockDatabase)3 Change (liquibase.change.Change)2 AddAutoIncrementChange (liquibase.change.core.AddAutoIncrementChange)2 DropTableChange (liquibase.change.core.DropTableChange)2 Database (liquibase.database.Database)2 ValidationErrors (liquibase.exception.ValidationErrors)2 ExecutorService (liquibase.executor.ExecutorService)2 MockExecutor (liquibase.sdk.executor.MockExecutor)2 AppendSqlVisitor (liquibase.sql.visitor.AppendSqlVisitor)2 SqlVisitor (liquibase.sql.visitor.SqlVisitor)2 BigInteger (java.math.BigInteger)1 CatalogAndSchema (liquibase.CatalogAndSchema)1 AddColumnConfig (liquibase.change.AddColumnConfig)1