use of liquibase.change.core.AddColumnChange in project liquibase by liquibase.
the class JsonChangeLogSerializerTest method serialize_changeSet.
@Test
public void serialize_changeSet() {
// given
AddColumnChange addColumnChange = new AddColumnChange();
addColumnChange.setCatalogName("cat");
addColumnChange.addColumn((AddColumnConfig) new AddColumnConfig().setName("col1").setDefaultValueNumeric(3));
addColumnChange.addColumn((AddColumnConfig) new AddColumnConfig().setName("col2").setDefaultValueComputed(new DatabaseFunction("NOW()")));
addColumnChange.addColumn((AddColumnConfig) new AddColumnConfig().setName("col3").setDefaultValueBoolean(true));
// Get the Date object for 1970-01-01T00:00:00 in the current time zone.
Calendar cal = Calendar.getInstance();
cal.setTimeInMillis(0);
cal.set(1970, 0, 1, 0, 0, 0);
addColumnChange.addColumn((AddColumnConfig) new AddColumnConfig().setName("col2").setDefaultValueDate(cal.getTime()));
addColumnChange.addColumn((AddColumnConfig) new AddColumnConfig().setName("col2").setDefaultValueSequenceNext(new SequenceNextValueFunction("seq_me")));
ChangeSet changeSet = new ChangeSet("1", "nvoxland", false, false, "path/to/file.json", null, null, null);
changeSet.setPreconditions(newSamplePreconditions());
changeSet.addChange(addColumnChange);
// when
String serializedJson = new JsonChangeLogSerializer().serialize(changeSet, true);
// then
assertEquals("{\n" + " \"changeSet\": {\n" + " \"id\": \"1\",\n" + " \"author\": \"nvoxland\",\n" + " \"objectQuotingStrategy\": \"LEGACY\",\n" + " \"preconditions\": {\n" + " \"preConditions\": {\n" + " \"nestedPreconditions\": [\n" + " {\n" + " \"preConditions\": {\n" + " \"onError\": \"WARN\",\n" + " \"onFail\": \"CONTINUE\",\n" + " \"onSqlOutput\": \"TEST\"\n" + " }\n" + " }]\n" + " ,\n" + " \"onError\": \"CONTINUE\",\n" + " \"onFail\": \"MARK_RAN\",\n" + " \"onSqlOutput\": \"FAIL\"\n" + " }\n" + " },\n" + " \"changes\": [\n" + " {\n" + " \"addColumn\": {\n" + " \"catalogName\": \"cat\",\n" + " \"columns\": [\n" + " {\n" + " \"column\": {\n" + " \"defaultValueNumeric\": 3,\n" + " \"name\": \"col1\"\n" + " }\n" + " },\n" + " {\n" + " \"column\": {\n" + " \"defaultValueComputed\": \"NOW()\",\n" + " \"name\": \"col2\"\n" + " }\n" + " },\n" + " {\n" + " \"column\": {\n" + " \"defaultValueBoolean\": true,\n" + " \"name\": \"col3\"\n" + " }\n" + " },\n" + " {\n" + " \"column\": {\n" + " \"defaultValueDate\": \"1970-01-01T00:00:00\",\n" + " \"name\": \"col2\"\n" + " }\n" + " },\n" + " {\n" + " \"column\": {\n" + " \"defaultValueSequenceNext\": \"seq_me\",\n" + " \"name\": \"col2\"\n" + " }\n" + " }]\n" + " \n" + " }\n" + " }]\n" + " \n" + " }\n" + "}\n", serializedJson);
}
use of liquibase.change.core.AddColumnChange in project liquibase by liquibase.
the class OfflineDatabaseTest method canOutputSQLFromOfflineOracleDB.
/**
* Check if it it's possible to output SQL from an OfflineConnection
* set to Oracle (offline:oracle).
*
* @see <a href="https://liquibase.jira.com/browse/CORE-2192">CORE-2192</a>
*/
@Test
public void canOutputSQLFromOfflineOracleDB() throws Exception {
AddColumnChange change = new AddColumnChange();
AddColumnConfig column1 = new AddColumnConfig();
column1.setName("column1");
column1.setType("INT");
change.addColumn(column1);
AddColumnConfig column2 = new AddColumnConfig();
column2.setName("column2");
column2.setType("INT");
change.addColumn(column2);
SqlStatement[] statements = new SqlStatement[0];
try {
statements = change.generateStatements(createOfflineDatabase("offline:oracle"));
} catch (DatabaseException e) {
Assert.fail("Can't generate statements from an Offline Oracle database.");
}
Assert.assertEquals(1, statements.length);
Assert.assertTrue(statements[0] instanceof AddColumnStatement);
AddColumnStatement stmt = (AddColumnStatement) statements[0];
Assert.assertTrue(stmt.isMultiple());
Assert.assertEquals(2, stmt.getColumns().size());
}
use of liquibase.change.core.AddColumnChange in project liquibase by liquibase.
the class AddColumnChangeTest method generateStatements_singleColumn_uniqueConstraintName.
@Test
public void generateStatements_singleColumn_uniqueConstraintName() {
String myUniqueConstraintName = "my_unique_constraint";
AddColumnChange change = new AddColumnChange();
change.setTableName("my_table");
AddColumnConfig column = new AddColumnConfig();
column.setName("column1");
column.setType("integer");
ConstraintsConfig constraintsConfig = new ConstraintsConfig();
constraintsConfig.setUnique(true);
constraintsConfig.setUniqueConstraintName(myUniqueConstraintName);
column.setConstraints(constraintsConfig);
change.addColumn(column);
SqlStatement[] statements = change.generateStatements(new MockDatabase());
Assert.assertEquals(1, statements.length);
Assert.assertTrue(statements[0] instanceof AddColumnStatement);
AddColumnStatement stmt = (AddColumnStatement) statements[0];
Assert.assertEquals(myUniqueConstraintName, stmt.getUniqueStatementName());
}
use of liquibase.change.core.AddColumnChange in project liquibase by liquibase.
the class AddColumnChangeTest method generateStatements_singleColumn_null_uniqueConstraintName.
@Test
public void generateStatements_singleColumn_null_uniqueConstraintName() {
AddColumnChange change = new AddColumnChange();
change.setTableName("my_table");
AddColumnConfig column = new AddColumnConfig();
column.setName("column1");
column.setType("integer");
ConstraintsConfig constraintsConfig = new ConstraintsConfig();
constraintsConfig.setUnique(true);
column.setConstraints(constraintsConfig);
change.addColumn(column);
SqlStatement[] statements = change.generateStatements(new MockDatabase());
Assert.assertEquals(1, statements.length);
Assert.assertTrue(statements[0] instanceof AddColumnStatement);
AddColumnStatement stmt = (AddColumnStatement) statements[0];
Assert.assertNull(stmt.getUniqueStatementName());
}
use of liquibase.change.core.AddColumnChange in project minijax by minijax.
the class LiquibaseHelperTest method testNotIgnoreAddColumn.
@Test
public void testNotIgnoreAddColumn() {
final AddColumnChange change = new AddColumnChange();
final ChangeSet changeSet = new ChangeSet(null);
changeSet.addChange(change);
assertFalse(LiquibaseHelper.isIgnoredChangeSet(changeSet));
}
Aggregations