Skip to content

Commit b7e4740

Browse files
committed
HCK-13030: ignore generating FK/UK if no columns
1 parent 2fe9ea6 commit b7e4740

1 file changed

Lines changed: 13 additions & 5 deletions

File tree

forward_engineering/ddlProvider/ddlHelpers/constraintsHelper.js

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,14 @@ const foreignActiveKeysToString = keys => {
6969
* }}
7070
* */
7171
const createKeyConstraint = (templates, isParentActivated) => keyData => {
72-
const constraintName = wrapInQuotes(_.trim(keyData.name));
72+
if (_.isEmpty(keyData.columns)) {
73+
return {
74+
statement: '',
75+
isActivated: false,
76+
};
77+
}
7378
const isAllColumnsDeactivated = checkAllKeysDeactivated(keyData.columns || []);
79+
const constraintName = wrapInQuotes(_.trim(keyData.name));
7480
const columns = !_.isEmpty(keyData.columns)
7581
? getColumnsList(keyData.columns, isAllColumnsDeactivated, isParentActivated)
7682
: '';
@@ -149,10 +155,12 @@ const createInlineCheckConstraint = checkConstraint => {
149155
const alterKeyConstraint = (tableName, isParentActivated, keyData) => {
150156
const constraintStatementDto = createKeyConstraint(templates, isParentActivated)(keyData);
151157
return {
152-
statement: assignTemplates(templates.addPkConstraint, {
153-
constraintStatement: (constraintStatementDto.statement || '').trim(),
154-
tableName,
155-
}),
158+
statement: constraintStatementDto.statement
159+
? assignTemplates(templates.addPkConstraint, {
160+
constraintStatement: constraintStatementDto.statement.trim(),
161+
tableName,
162+
})
163+
: '',
156164
isActivated: constraintStatementDto.isActivated,
157165
};
158166
};

0 commit comments

Comments
 (0)