Skip to content

Commit 6230157

Browse files
HCK-13032: remove entity-level check statement without expression (#171)
* HCK-13032: remove entity-level check statement without name or expression * fix
1 parent 0df1834 commit 6230157

2 files changed

Lines changed: 12 additions & 8 deletions

File tree

forward_engineering/alterScript/alterScriptHelpers/entityHelpers/checkConstraintHelper.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ const mapCheckConstraintNamesToChangeHistory = collection => {
6868
* */
6969
const getDropCheckConstraintScriptDtos = (constraintHistory, fullTableName) => {
7070
return constraintHistory
71-
.filter(historyEntry => historyEntry.old && !historyEntry.new)
71+
.filter(historyEntry => historyEntry.old?.constrExpression && !historyEntry.new?.constrExpression)
7272
.map(historyEntry => {
7373
const wrappedConstraintName = wrapInQuotes(historyEntry.old.chkConstrName);
7474
return dropConstraint(fullTableName, wrappedConstraintName);
@@ -100,7 +100,7 @@ const addCheckConstraint = (tableName, constraintName, expression, noInherit = f
100100
* */
101101
const getAddCheckConstraintScriptDtos = (constraintHistory, fullTableName) => {
102102
return constraintHistory
103-
.filter(historyEntry => historyEntry.new && !historyEntry.old)
103+
.filter(historyEntry => historyEntry.new?.constrExpression && !historyEntry.old?.constrExpression)
104104
.map(historyEntry => {
105105
const { chkConstrName, constrExpression, noInherit } = historyEntry.new;
106106
return addCheckConstraint(fullTableName, wrapInQuotes(chkConstrName), constrExpression, noInherit);
@@ -116,7 +116,7 @@ const getAddCheckConstraintScriptDtos = (constraintHistory, fullTableName) => {
116116
const getUpdateCheckConstraintScriptDtos = (constraintHistory, fullTableName) => {
117117
return constraintHistory
118118
.filter(historyEntry => {
119-
if (historyEntry.old && historyEntry.new) {
119+
if (historyEntry.old?.constrExpression && historyEntry.new?.constrExpression) {
120120
const oldExpression = historyEntry.old.constrExpression;
121121
const newExpression = historyEntry.new.constrExpression;
122122
const oldNoInherit = historyEntry.old.noInherit;

forward_engineering/ddlProvider/ddlProvider.js

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -290,11 +290,15 @@ module.exports = (baseProvider, options, app) => {
290290
},
291291

292292
createCheckConstraint(checkConstraint) {
293-
return assignTemplates(templates.checkConstraint, {
294-
name: checkConstraint.name ? `CONSTRAINT ${wrapInQuotes(checkConstraint.name)}` : '',
295-
expression: cleanCheckConstraint(checkConstraint.expression),
296-
noInherit: checkConstraint.noInherit ? ' NO INHERIT' : '',
297-
});
293+
const expression = cleanCheckConstraint(checkConstraint.expression);
294+
return (
295+
expression &&
296+
assignTemplates(templates.checkConstraint, {
297+
name: checkConstraint.name ? `CONSTRAINT ${wrapInQuotes(checkConstraint.name)}` : '',
298+
expression,
299+
noInherit: checkConstraint.noInherit ? ' NO INHERIT' : '',
300+
})
301+
);
298302
},
299303

300304
/**

0 commit comments

Comments
 (0)