From f7464f706dbba51ba25e2481c6b1d5ee34f75cb6 Mon Sep 17 00:00:00 2001 From: Alik Rakhmonov Date: Tue, 14 Oct 2025 15:27:05 +0200 Subject: [PATCH 1/2] HCK-13032: remove entity-level check statement without name or expression --- .../entityHelpers/checkConstraintHelper.js | 11 ++++++++--- forward_engineering/ddlProvider/ddlProvider.js | 14 +++++++++----- 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/forward_engineering/alterScript/alterScriptHelpers/entityHelpers/checkConstraintHelper.js b/forward_engineering/alterScript/alterScriptHelpers/entityHelpers/checkConstraintHelper.js index 011e34f..d0cb716 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,12 @@ const addCheckConstraint = (tableName, constraintName, expression, noInherit = f * */ const getAddCheckConstraintScriptDtos = (constraintHistory, fullTableName) => { return constraintHistory - .filter(historyEntry => historyEntry.new && !historyEntry.old) + .filter( + historyEntry => + historyEntry.new?.chkConstrName && + historyEntry.new?.constrExpression && + !historyEntry.old?.constrExpression, + ) .map(historyEntry => { const { chkConstrName, constrExpression, noInherit } = historyEntry.new; return addCheckConstraint(fullTableName, wrapInQuotes(chkConstrName), constrExpression, noInherit); @@ -116,7 +121,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' : '', + }) + ); }, /** From a74154640ef75316152d42fb636424f72e21d957 Mon Sep 17 00:00:00 2001 From: Alik Rakhmonov Date: Tue, 14 Oct 2025 16:51:39 +0200 Subject: [PATCH 2/2] fix --- .../entityHelpers/checkConstraintHelper.js | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/forward_engineering/alterScript/alterScriptHelpers/entityHelpers/checkConstraintHelper.js b/forward_engineering/alterScript/alterScriptHelpers/entityHelpers/checkConstraintHelper.js index d0cb716..f7b8792 100644 --- a/forward_engineering/alterScript/alterScriptHelpers/entityHelpers/checkConstraintHelper.js +++ b/forward_engineering/alterScript/alterScriptHelpers/entityHelpers/checkConstraintHelper.js @@ -100,12 +100,7 @@ const addCheckConstraint = (tableName, constraintName, expression, noInherit = f * */ const getAddCheckConstraintScriptDtos = (constraintHistory, fullTableName) => { return constraintHistory - .filter( - historyEntry => - historyEntry.new?.chkConstrName && - historyEntry.new?.constrExpression && - !historyEntry.old?.constrExpression, - ) + .filter(historyEntry => historyEntry.new?.constrExpression && !historyEntry.old?.constrExpression) .map(historyEntry => { const { chkConstrName, constrExpression, noInherit } = historyEntry.new; return addCheckConstraint(fullTableName, wrapInQuotes(chkConstrName), constrExpression, noInherit);