Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix missing attributes in serialization #2585

Merged
merged 9 commits into from
Jun 22, 2022
42 changes: 37 additions & 5 deletions liquibase-core/src/main/java/liquibase/changelog/ChangeSet.java
Original file line number Diff line number Diff line change
Expand Up @@ -955,14 +955,26 @@ public boolean isAlwaysRun() {
return alwaysRun;
}

public void setAlwaysRun(boolean alwaysRun) {
nvoxland marked this conversation as resolved.
Show resolved Hide resolved
this.alwaysRun = alwaysRun;
}

public boolean isRunOnChange() {
return runOnChange;
}

public void setRunOnChange(boolean runOnChange) {
this.runOnChange = runOnChange;
}

public boolean isRunInTransaction() {
return runInTransaction;
}

public void setRunInTransaction(boolean runInTransaction) {
this.runInTransaction = runInTransaction;
}

public RollbackContainer getRollback() {
return rollback;
}
Expand Down Expand Up @@ -1142,11 +1154,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 @@ -1242,6 +1254,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 @@ -63,6 +66,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