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);
}
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);
}
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());
}
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);
}
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());
}
Aggregations