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
4 changes: 2 additions & 2 deletions forward_engineering/configs/templates.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ module.exports = {

spatialIndex: 'CREATE SPATIAL INDEX ${name} ON ${table} (${column})${using}\n${options}${terminator}\n',

checkConstraint: 'CONSTRAINT [${name}] ${check}${notForReplication} (${expression})',
checkConstraint: 'CONSTRAINT [${name}] CHECK${notForReplication} (${expression})',

createForeignKeyConstraint:
'CONSTRAINT ${name} FOREIGN KEY (${foreignKey}) REFERENCES ${primaryTable} (${primaryKey}) ${onDelete}${onUpdate}',
Expand Down Expand Up @@ -75,7 +75,7 @@ module.exports = {
addColumn: 'ADD ${script}',

addCheckConstraint:
'ALTER TABLE ${tableName} ADD CONSTRAINT ${constraintName} ${check} (${expression})${terminator}',
'ALTER TABLE ${tableName}${noCheck} ADD CONSTRAINT ${constraintName} CHECK (${expression})${terminator}',

addNotNullConstraint: 'ALTER TABLE ${tableName} ALTER COLUMN ${columnName} ${columnType} NOT NULL${terminator}',

Expand Down
7 changes: 3 additions & 4 deletions forward_engineering/ddlProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -255,10 +255,9 @@ module.exports = (baseProvider, options, app) => {
return createTableIndex(terminator, tableName, index, isActivated && isParentActivated);
},

createCheckConstraint(checkConstraint, isInline = true) {
createCheckConstraint(checkConstraint) {
return assignTemplates(templates.checkConstraint, {
name: checkConstraint.name,
check: checkConstraint.check || isInline ? 'CHECK' : 'NOCHECK',
notForReplication: checkConstraint.enforceForReplication ? '' : ' NOT FOR REPLICATION',
expression: _.trim(checkConstraint.expression).replace(/^\(([\s\S]*)\)$/, '$1'),
terminator,
Expand Down Expand Up @@ -717,7 +716,7 @@ module.exports = (baseProvider, options, app) => {
alterTableAddCheckConstraint(fullTableName, checkConstraint) {
return assignTemplates(templates.alterTableAddConstraint, {
tableName: fullTableName,
constraint: this.createCheckConstraint(checkConstraint, false),
constraint: this.createCheckConstraint(checkConstraint),
terminator,
});
},
Expand Down Expand Up @@ -977,7 +976,7 @@ module.exports = (baseProvider, options, app) => {
constraintName,
expression,
terminator,
check: check ? 'CHECK' : 'NOCHECK',
noCheck: check ? '' : ' WITH NOCHECK',
};
return assignTemplates(templates.addCheckConstraint, templateConfig);
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ module.exports = (app, options) => {
}),
);
const checkConstraints = (jsonSchema.chkConstr || []).map(check =>
ddlProvider.createCheckConstraint(ddlProvider.hydrateCheckConstraint(check), true),
ddlProvider.createCheckConstraint(ddlProvider.hydrateCheckConstraint(check)),
);
const tableData = {
name: tableName,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,9 @@ const getUpdateCheckConstraintScriptDtos = (_, ddlProvider) => (constraintHistor
const oldName = historyEntry.old.chkConstrName;
const newName = historyEntry.new.chkConstrName;
const hasOnlyNameChanged = oldExpression === newName && newName !== oldName;
const hasCheckChanged = historyEntry.old.constrCheck !== historyEntry.new.constrCheck;

return oldExpression !== newExpression || hasOnlyNameChanged;
return oldExpression !== newExpression || hasOnlyNameChanged || hasCheckChanged;
}
return false;
})
Expand Down