diff --git a/forward_engineering/alterScript/alterScriptHelpers/entityHelpers/checkConstraintHelper.js b/forward_engineering/alterScript/alterScriptHelpers/entityHelpers/checkConstraintHelper.js index 011e34f..f7b8792 100644 --- a/forward_engineering/alterScript/alterScriptHelpers/entityHelpers/checkConstraintHelper.js +++ b/forward_engineering/alterScript/alterScriptHelpers/entityHelpers/checkConstraintHelper.js @@ -68,7 +68,7 @@ const mapCheckConstraintNamesToChangeHistory = collection => { * */ const getDropCheckConstraintScriptDtos = (constraintHistory, fullTableName) => { return constraintHistory - .filter(historyEntry => historyEntry.old && !historyEntry.new) + .filter(historyEntry => historyEntry.old?.constrExpression && !historyEntry.new?.constrExpression) .map(historyEntry => { const wrappedConstraintName = wrapInQuotes(historyEntry.old.chkConstrName); return dropConstraint(fullTableName, wrappedConstraintName); @@ -100,7 +100,7 @@ const addCheckConstraint = (tableName, constraintName, expression, noInherit = f * */ const getAddCheckConstraintScriptDtos = (constraintHistory, fullTableName) => { return constraintHistory - .filter(historyEntry => historyEntry.new && !historyEntry.old) + .filter(historyEntry => historyEntry.new?.constrExpression && !historyEntry.old?.constrExpression) .map(historyEntry => { const { chkConstrName, constrExpression, noInherit } = historyEntry.new; return addCheckConstraint(fullTableName, wrapInQuotes(chkConstrName), constrExpression, noInherit); @@ -116,7 +116,7 @@ const getAddCheckConstraintScriptDtos = (constraintHistory, fullTableName) => { const getUpdateCheckConstraintScriptDtos = (constraintHistory, fullTableName) => { return constraintHistory .filter(historyEntry => { - if (historyEntry.old && historyEntry.new) { + if (historyEntry.old?.constrExpression && historyEntry.new?.constrExpression) { const oldExpression = historyEntry.old.constrExpression; const newExpression = historyEntry.new.constrExpression; const oldNoInherit = historyEntry.old.noInherit; diff --git a/forward_engineering/ddlProvider/ddlProvider.js b/forward_engineering/ddlProvider/ddlProvider.js index f99cd77..cf8a62a 100644 --- a/forward_engineering/ddlProvider/ddlProvider.js +++ b/forward_engineering/ddlProvider/ddlProvider.js @@ -290,11 +290,15 @@ module.exports = (baseProvider, options, app) => { }, createCheckConstraint(checkConstraint) { - return assignTemplates(templates.checkConstraint, { - name: checkConstraint.name ? `CONSTRAINT ${wrapInQuotes(checkConstraint.name)}` : '', - expression: cleanCheckConstraint(checkConstraint.expression), - noInherit: checkConstraint.noInherit ? ' NO INHERIT' : '', - }); + const expression = cleanCheckConstraint(checkConstraint.expression); + return ( + expression && + assignTemplates(templates.checkConstraint, { + name: checkConstraint.name ? `CONSTRAINT ${wrapInQuotes(checkConstraint.name)}` : '', + expression, + noInherit: checkConstraint.noInherit ? ' NO INHERIT' : '', + }) + ); }, /**