Skip to content

Commit 22705a0

Browse files
HCK-13032: omit constraints with empty expression (#169)
1 parent 4e2eb84 commit 22705a0

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

forward_engineering/alterScript/alterScriptHelpers/columnHelpers/checkConstraintHelper.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ const mapColumnCheckConstraintsToChangeHistory = collection => {
105105
* */
106106
const getDropColumnCheckConstraintScriptDtos = (constraintHistory, fullTableName) => {
107107
return constraintHistory
108-
.filter(historyEntry => historyEntry.old && !historyEntry.new)
108+
.filter(historyEntry => historyEntry.old?.expression && !historyEntry.new?.expression)
109109
.map(historyEntry => {
110110
const wrappedConstraintName = getConstraintName(
111111
historyEntry.old.name,
@@ -124,7 +124,7 @@ const getDropColumnCheckConstraintScriptDtos = (constraintHistory, fullTableName
124124
* */
125125
const getAddColumnCheckConstraintScriptDtos = (constraintHistory, fullTableName) => {
126126
return constraintHistory
127-
.filter(historyEntry => historyEntry.new && !historyEntry.old)
127+
.filter(historyEntry => historyEntry.new?.expression && !historyEntry.old?.expression)
128128
.map(historyEntry => {
129129
const { name, expression, noInherit } = historyEntry.new;
130130
const constraintName = getConstraintName(name, historyEntry.columnName, fullTableName);
@@ -142,7 +142,7 @@ const getAddColumnCheckConstraintScriptDtos = (constraintHistory, fullTableName)
142142
const getUpdateColumnCheckConstraintScriptDtos = (constraintHistory, fullTableName) => {
143143
return constraintHistory
144144
.filter(historyEntry => {
145-
if (historyEntry.old && historyEntry.new) {
145+
if (historyEntry.old?.expression && historyEntry.new?.expression) {
146146
const oldExpression = historyEntry.old.expression;
147147
const newExpression = historyEntry.new.expression;
148148
const oldNoInherit = historyEntry.old.noInherit;

forward_engineering/ddlProvider/ddlProvider.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -224,9 +224,12 @@ module.exports = (baseProvider, options, app) => {
224224
const defaultValue = !_.isUndefined(columnDefinition.default)
225225
? ' DEFAULT ' + decorateDefault(type, columnDefinition.default, isArrayType)
226226
: '';
227-
const checkConstraint = !_.isEmpty(columnDefinition.checkConstraint)
228-
? ' ' + this.createCheckConstraint(_.first(columnDefinition.checkConstraint)).trim()
227+
228+
const checkConstraintData = _.first(columnDefinition.checkConstraint);
229+
const checkConstraint = checkConstraintData?.expression
230+
? ' ' + this.createCheckConstraint(checkConstraintData).trim()
229231
: '';
232+
230233
const generatedColumnClause =
231234
columnDefinition.dbVersion >= 12 &&
232235
columnDefinition.generatedColumn &&

0 commit comments

Comments
 (0)