use of liquibase.changelog.ChangeSet in project liquibase by liquibase.
the class XMLChangeLogSerializerTest method createNode_ChangeSetParameters.
@Test
public void createNode_ChangeSetParameters() throws Exception {
ChangeSet changeSet = new ChangeSet("1", "tms", true, true, "path/to/file.json", "context", "mssql", null, false, ObjectQuotingStrategy.LEGACY, null);
changeSet.setCreated("created");
changeSet.setFailOnError(true);
changeSet.setLabels(new Labels("label"));
changeSet.setLogicalFilePath("path/to/file.json");
Element node = new XMLChangeLogSerializer(DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument()).createNode(changeSet);
assertEquals("element name", "changeSet", node.getTagName());
assertEquals("changeSet Attributes", attsMap("id", "1", "author", "tms", "runAlways", "true", "runOnChange", "true", "logicalFilePath", "path/to/file.json", "context", "context", "dbms", "mssql", "objectQuotingStrategy", "LEGACY", "failOnError", "true", "labels", "label", "created", "created"), attsMap(node));
}
use of liquibase.changelog.ChangeSet 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.changelog.ChangeSet in project liquibase by liquibase.
the class ChangeSetExecutedPrecondition method check.
@Override
public void check(Database database, DatabaseChangeLog changeLog, ChangeSet changeSet, ChangeExecListener changeExecListener) throws PreconditionFailedException, PreconditionErrorException {
ObjectQuotingStrategy objectQuotingStrategy = null;
if (changeSet == null) {
objectQuotingStrategy = ObjectQuotingStrategy.LEGACY;
} else {
objectQuotingStrategy = changeSet.getObjectQuotingStrategy();
}
String changeLogFile = getChangeLogFile();
if (changeLogFile == null) {
changeLogFile = changeLog.getLogicalFilePath();
}
ChangeSet interestedChangeSet = new ChangeSet(getId(), getAuthor(), false, false, changeLogFile, null, null, false, objectQuotingStrategy, changeLog);
RanChangeSet ranChangeSet;
try {
ranChangeSet = database.getRanChangeSet(interestedChangeSet);
} catch (Exception e) {
throw new PreconditionErrorException(e, changeLog, this);
}
if ((ranChangeSet == null) || (ranChangeSet.getExecType() == null) || !ranChangeSet.getExecType().ran) {
throw new PreconditionFailedException("Change Set '" + interestedChangeSet.toString(false) + "' has not been run", changeLog, this);
}
}
use of liquibase.changelog.ChangeSet in project liquibase by liquibase.
the class SqlChangeLogParser method parse.
@Override
public DatabaseChangeLog parse(String physicalChangeLogLocation, ChangeLogParameters changeLogParameters, ResourceAccessor resourceAccessor) throws ChangeLogParseException {
DatabaseChangeLog changeLog = new DatabaseChangeLog();
changeLog.setPhysicalFilePath(physicalChangeLogLocation);
RawSQLChange change = new RawSQLChange();
try {
InputStream sqlStream = resourceAccessor.openStream(null, physicalChangeLogLocation);
if (sqlStream != null) {
String sql = StreamUtil.readStreamAsString(sqlStream);
change.setSql(sql);
} else {
throw new ChangeLogParseException(FileUtil.getFileNotFoundMessage(physicalChangeLogLocation));
}
} catch (IOException e) {
throw new ChangeLogParseException(e);
}
change.setSplitStatements(false);
change.setStripComments(false);
ChangeSet changeSet = new ChangeSet("raw", "includeAll", false, false, physicalChangeLogLocation, null, null, true, ObjectQuotingStrategy.LEGACY, changeLog);
changeSet.addChange(change);
changeLog.addChangeSet(changeSet);
return changeLog;
}
use of liquibase.changelog.ChangeSet in project liquibase by liquibase.
the class CountChangeSetFilterTest method acceptsTwoCorrectly.
@Test
public void acceptsTwoCorrectly() {
CountChangeSetFilter filter = new CountChangeSetFilter(2);
assertTrue(filter.accepts(new ChangeSet("a1", "b1", false, false, "c1", null, null, null)).isAccepted());
assertTrue(filter.accepts(new ChangeSet("a2", "b2", false, false, "c2", null, null, null)).isAccepted());
assertFalse(filter.accepts(new ChangeSet("a3", "b3", false, false, "c3", null, null, null)).isAccepted());
}
Aggregations