Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand All @@ -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;
Expand Down
14 changes: 9 additions & 5 deletions forward_engineering/ddlProvider/ddlProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -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' : '',
})
);
},

/**
Expand Down