Skip to content

Commit

Permalink
generateChangelog optionally creates runOnChange=true and replaceIfEx…
Browse files Browse the repository at this point in the history
…ists=true for createView changes
  • Loading branch information
mkarg authored and rberezen committed Dec 8, 2023
1 parent 8ec74b0 commit e321798
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ public class GenerateChangelogCommandStep extends AbstractCommandStep {
public static final CommandArgumentDefinition<String> DATA_OUTPUT_DIR_ARG;
public static final CommandArgumentDefinition<Boolean> OVERWRITE_OUTPUT_FILE_ARG;
public static final CommandArgumentDefinition<String> CHANGELOG_FILE_ARG;
public static final CommandArgumentDefinition<Boolean> CREATEVIEW_RUNONCHANGE_ARG;
public static final CommandArgumentDefinition<Boolean> CREATEVIEW_REPLACEIFEXISTS_ARG;

public static final CommandArgumentDefinition<String> REFERENCE_URL_ARG;
public static final CommandArgumentDefinition<String> REFERENCE_USERNAME_ARG;
Expand Down Expand Up @@ -70,6 +72,10 @@ public class GenerateChangelogCommandStep extends AbstractCommandStep {
.description("Directory to write table data to").build();
OVERWRITE_OUTPUT_FILE_ARG = builder.argument("overwriteOutputFile", Boolean.class)
.defaultValue(false).description("Flag to allow overwriting of output changelog file. Default: false").build();
CREATEVIEW_RUNONCHANGE_ARG = builder.argument("createViewRunOnChange", Boolean.class)
.defaultValue(false).description("Sets runOnChange=\"true\" for changesets containing solely createView changes").build();
CREATEVIEW_REPLACEIFEXISTS_ARG = builder.argument("createViewReplaceIfExists", Boolean.class)
.defaultValue(false).description("Sets replaceIfExists=\"true\" for createView changes").build();

// this happens because the command line asks for "url", but in fact uses it as "referenceUrl"
REFERENCE_URL_ARG = builder.argument("referenceUrl", String.class).hidden().build();
Expand Down Expand Up @@ -131,6 +137,8 @@ public void run(CommandResultsBuilder resultsBuilder) throws Exception {
changeLogWriter.setChangeSetLabels(commandScope.getArgumentValue(LABEL_FILTER_ARG));
}
changeLogWriter.setChangeSetPath(changeLogFile);
changeLogWriter.setChangeSetRunOnChangeForCreateViewChange(commandScope.getArgumentValue(CREATEVIEW_RUNONCHANGE_ARG));
changeLogWriter.setChangeReplaceIfExistsForCreateViewChange(commandScope.getArgumentValue(CREATEVIEW_REPLACEIFEXISTS_ARG));

ObjectQuotingStrategy originalStrategy = referenceDatabase.getObjectQuotingStrategy();
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ public class DiffToChangeLog {
private String changeSetLabels;
private String changeSetAuthor;
private String changeSetPath;
private boolean changeSetRunOnChangeForCreateViewChange;
private boolean changeReplaceIfExistsForCreateViewChange;
private DiffResult diffResult;
private final DiffOutputControl diffOutputControl;
private boolean tryDbaDependencies = true;
Expand Down Expand Up @@ -754,20 +756,26 @@ private void addToChangeSets(Change[] changes, List<ChangeSet> changeSets, Objec

if (useSeparateChangeSets(changes)) {
for (Change change : changes) {
ChangeSet changeSet =
new ChangeSet(generateId(changes), getChangeSetAuthor(), false, false, this.changeSetPath, changeSetContext,
final boolean onlyCreateViewChanges = change instanceof CreateViewChange;
final boolean runOnChange = onlyCreateViewChanges && getChangeSetRunOnChangeForCreateViewChange();
ChangeSet changeSet = new ChangeSet(generateId(changes), getChangeSetAuthor(), false, runOnChange, this.changeSetPath, changeSetContext,
null, true, quotingStrategy, null);
changeSet.setCreated(created);
if (diffOutputControl.getLabels() != null) {
changeSet.setLabels(diffOutputControl.getLabels());
} else {
changeSet.setLabels(new Labels(this.changeSetLabels));
}
if (change instanceof CreateViewChange && getChangeReplaceIfExistsForCreateViewChange()) {
((CreateViewChange) change).setReplaceIfExists(true);
}
changeSet.addChange(change);
changeSets.add(changeSet);
}
} else {
ChangeSet changeSet = new ChangeSet(generateId(changes), getChangeSetAuthor(), false, false, this.changeSetPath, csContext,
final boolean onlyCreateViewChanges = Arrays.asList(changes).stream().allMatch(CreateViewChange.class::isInstance);
final boolean runOnChange = onlyCreateViewChanges && getChangeSetRunOnChangeForCreateViewChange();
ChangeSet changeSet = new ChangeSet(generateId(changes), getChangeSetAuthor(), false, runOnChange, this.changeSetPath, csContext,
null, true, quotingStrategy, null);
changeSet.setCreated(created);
if (diffOutputControl.getLabels() != null) {
Expand All @@ -776,6 +784,9 @@ private void addToChangeSets(Change[] changes, List<ChangeSet> changeSets, Objec
changeSet.setLabels(new Labels(this.changeSetLabels));
}
for (Change change : changes) {
if (change instanceof CreateViewChange && getChangeReplaceIfExistsForCreateViewChange()) {
((CreateViewChange) change).setReplaceIfExists(true);
}
changeSet.addChange(change);
}
changeSets.add(changeSet);
Expand Down Expand Up @@ -836,6 +847,22 @@ public void setChangeSetPath(String changeSetPath) {
this.changeSetPath = changeSetPath;
}

public void setChangeSetRunOnChangeForCreateViewChange(final boolean runOnChange) {
changeSetRunOnChangeForCreateViewChange = runOnChange;
}

protected boolean getChangeSetRunOnChangeForCreateViewChange() {
return changeSetRunOnChangeForCreateViewChange;
}

public void setChangeReplaceIfExistsForCreateViewChange(final boolean replaceIfExists) {
changeReplaceIfExistsForCreateViewChange = replaceIfExists;
}

protected boolean getChangeReplaceIfExistsForCreateViewChange() {
return changeReplaceIfExistsForCreateViewChange;
}

public void setIdRoot(String idRoot) {
this.idRoot = idRoot;
this.overriddenIdRoot = true;
Expand Down

0 comments on commit e321798

Please sign in to comment.