Search in sources :

Example 26 with ChangeSet

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));
}
Also used : Element(org.w3c.dom.Element) Labels(liquibase.Labels) ChangeSet(liquibase.changelog.ChangeSet) Test(org.junit.Test)

Example 27 with ChangeSet

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);
}
Also used : DatabaseFunction(liquibase.statement.DatabaseFunction) Calendar(java.util.Calendar) AddColumnConfig(liquibase.change.AddColumnConfig) SequenceNextValueFunction(liquibase.statement.SequenceNextValueFunction) AddColumnChange(liquibase.change.core.AddColumnChange) ChangeSet(liquibase.changelog.ChangeSet) Test(org.junit.Test)

Example 28 with ChangeSet

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);
    }
}
Also used : PreconditionFailedException(liquibase.exception.PreconditionFailedException) RanChangeSet(liquibase.changelog.RanChangeSet) ChangeSet(liquibase.changelog.ChangeSet) ObjectQuotingStrategy(liquibase.database.ObjectQuotingStrategy) PreconditionFailedException(liquibase.exception.PreconditionFailedException) PreconditionErrorException(liquibase.exception.PreconditionErrorException) RanChangeSet(liquibase.changelog.RanChangeSet) PreconditionErrorException(liquibase.exception.PreconditionErrorException)

Example 29 with ChangeSet

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;
}
Also used : RawSQLChange(liquibase.change.core.RawSQLChange) InputStream(java.io.InputStream) ChangeLogParseException(liquibase.exception.ChangeLogParseException) IOException(java.io.IOException) ChangeSet(liquibase.changelog.ChangeSet) DatabaseChangeLog(liquibase.changelog.DatabaseChangeLog)

Example 30 with ChangeSet

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());
}
Also used : ChangeSet(liquibase.changelog.ChangeSet) Test(org.junit.Test)

Aggregations

ChangeSet (liquibase.changelog.ChangeSet)72 Test (org.junit.Test)41 Contexts (liquibase.Contexts)12 DatabaseChangeLog (liquibase.changelog.DatabaseChangeLog)11 RanChangeSet (liquibase.changelog.RanChangeSet)10 Liquibase (liquibase.Liquibase)9 Change (liquibase.change.Change)9 Database (liquibase.database.Database)9 LiquibaseException (liquibase.exception.LiquibaseException)8 ArrayList (java.util.ArrayList)7 DiffOutputControl (liquibase.diff.output.DiffOutputControl)7 DiffToChangeLog (liquibase.diff.output.changelog.DiffToChangeLog)7 ObjectQuotingStrategy (liquibase.database.ObjectQuotingStrategy)6 DiffResult (liquibase.diff.DiffResult)6 CompareControl (liquibase.diff.compare.CompareControl)6 IOException (java.io.IOException)5 Sql (liquibase.sql.Sql)5 MarkChangeSetRanStatement (liquibase.statement.core.MarkChangeSetRanStatement)5 Date (java.util.Date)4 Labels (liquibase.Labels)4