Skip to content

Commit

Permalink
Fix missing attributes in serialization (#2585)
Browse files Browse the repository at this point in the history
* Serialize fields that were not serialized
* Extend ChangeSet XML serialization test for new serialized attributes

Co-authored-by: Tobias Schmidt <t.schmidt@exec.de>
Co-authored-by: Nathan Voxland <nathan@voxland.net>
  • Loading branch information
3 people committed Jun 22, 2022
1 parent d2d634f commit ad4fe6c
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 9 deletions.
30 changes: 25 additions & 5 deletions liquibase-core/src/main/java/liquibase/changelog/ChangeSet.java
Original file line number Diff line number Diff line change
Expand Up @@ -1219,11 +1219,11 @@ public String getSerializedObjectName() {
@Override
public Set<String> getSerializableFields() {
return new LinkedHashSet<>(
Arrays.asList(
"id", "author", "runAlways", "runOnChange", "failOnError", "context", "labels", "dbms",
"objectQuotingStrategy", "comment", "preconditions", "changes", "rollback", "labels",
"logicalFilePath", "created"
)
Arrays.asList(
"id", "author", "runAlways", "runOnChange", "failOnError", "context", "labels", "dbms",
"objectQuotingStrategy", "comment", "preconditions", "changes", "rollback", "labels",
"logicalFilePath", "created", "runInTransaction", "runOrder", "ignore"
)
);
}

Expand Down Expand Up @@ -1319,6 +1319,26 @@ public Object getSerializableFieldValue(String field) {
}
}

if ("runInTransaction".equals(field)) {
if (!this.isRunInTransaction()) {
return false;
} else {
return null;
}
}

if ("runOrder".equals(field)) {
return getRunOrder();
}

if ("ignore".equals(field)) {
if (this.isIgnore()) {
return true;
} else {
return null;
}
}

throw new UnexpectedLiquibaseException("Unexpected field request on changeSet: " + field);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,12 @@ public class ChangeSetTest extends Specification {
continue
} else if (param == "objectQuotingStrategy") {
testValue[param] = "QUOTE_ONLY_RESERVED_WORDS"
} else if (param == "runInTransaction") {
testValue[param] = "false"
} else if (param == "runOrder") {
testValue[param] = "last"
} else if (param == "ignore") {
testValue[param] = "true"
} else {
testValue[param] = "value for ${param}"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,10 @@ public void serialize_changeSet() {
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 changeSet = new ChangeSet("1", "nvoxland", false, false, "path/to/file.json", null, null,false, null);
changeSet.setPreconditions(newSamplePreconditions());
changeSet.setRunOrder("last");
changeSet.setIgnore(true);
changeSet.addChange(addColumnChange);
//when
String serializedJson = new JsonChangeLogSerializer().serialize(changeSet, true);
Expand All @@ -46,6 +48,7 @@ public void serialize_changeSet() {
" \"changeSet\": {\n" +
" \"id\": \"1\",\n" +
" \"author\": \"nvoxland\",\n" +
" \"ignore\": true,\n" +
" \"objectQuotingStrategy\": \"LEGACY\",\n" +
" \"preconditions\": {\n" +
" \"preConditions\": {\n" +
Expand All @@ -64,6 +67,8 @@ public void serialize_changeSet() {
" \"onSqlOutput\": \"FAIL\"\n" +
" }\n" +
" },\n" +
" \"runInTransaction\": false,\n" +
" \"runOrder\": \"last\",\n" +
" \"changes\": [\n" +
" {\n" +
" \"addColumn\": {\n" +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -905,7 +905,8 @@ public void createNode_ChangeSetParameters() throws Exception {
"objectQuotingStrategy","LEGACY",
"failOnError","true",
"labels","label",
"created","created"),
"created","created",
"runInTransaction","false"),
attsMap(node));

}
Expand Down Expand Up @@ -935,6 +936,8 @@ public void serialize_pretty_ChangeSetParameters() throws Exception {
changeSet.setFailOnError(true);
changeSet.setLabels(new Labels("label"));
changeSet.setLogicalFilePath("path/to/file.json");
changeSet.setIgnore(true);
changeSet.setRunOrder("last");

String out = new XMLChangeLogSerializer().serialize(changeSet, true);

Expand All @@ -944,11 +947,14 @@ public void serialize_pretty_ChangeSetParameters() throws Exception {
+ " dbms=\"mssql\"\n"
+ " failOnError=\"true\"\n"
+ " id=\"1\"\n"
+ " ignore=\"true\"\n"
+ " labels=\"label\"\n"
+ " logicalFilePath=\"path/to/file.json\"\n"
+ " objectQuotingStrategy=\"LEGACY\"\n"
+ " runAlways=\"true\"\n"
+ " runOnChange=\"true\"/>", out);
+ " runInTransaction=\"false\"\n"
+ " runOnChange=\"true\"\n"
+ " runOrder=\"last\"/>", out);

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ public class YamlChangeLogSerializerTest {

@Test
public void serialize__change() {
ChangeSet changeSet = new ChangeSet("test1", "nvoxland", false, true, "/test/me.txt", null, null, null);
ChangeSet changeSet = new ChangeSet("test1", "nvoxland", false, true, "/test/me.txt", null, null,false, null);
changeSet.setIgnore(true);
changeSet.setRunOrder("last");
CreateTableChange change = new CreateTableChange();
change.setTableName("testTable");
change.addColumn(new ColumnConfig().setName("id").setType("int"));
Expand Down

0 comments on commit ad4fe6c

Please sign in to comment.