Skip to content

Commit 581eb0b

Browse files
author
unknown
committed
Added ability to model deferrable PK and UNIQUE constraints
1 parent da59574 commit 581eb0b

File tree

3 files changed

+10
-1
lines changed

3 files changed

+10
-1
lines changed

forward_engineering/ddlProvider/ddlHelpers/constraintsHelper.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,9 @@ module.exports = ({
8080
: '';
8181
const storageParameters = keyData.storageParameters ? ` WITH (${keyData.storageParameters})` : '';
8282
const tablespace = keyData.tablespace ? ` USING INDEX TABLESPACE ${wrapInQuotes(keyData.tablespace)}` : '';
83+
const deferrable = keyData?.deferrable ? ` ${keyData.deferrable}` : '';
84+
const deferrableConstraintCheckTime = keyData?.deferrable === 'DEFERRABLE' && keyData?.deferrableConstraintCheckTime
85+
? ` ${keyData?.deferrableConstraintCheckTime}` : '';
8386

8487
return {
8588
statement: assignTemplates(templates.createKeyConstraint, {
@@ -89,6 +92,8 @@ module.exports = ({
8992
includeNonKey,
9093
storageParameters,
9194
tablespace,
95+
deferrable,
96+
deferrableConstraintCheckTime,
9297
}),
9398
isActivated: !isAllColumnsDeactivated,
9499
};

forward_engineering/ddlProvider/ddlHelpers/keyHelper.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@ module.exports = (_, clean) => {
5959
comment: options['indexComment'],
6060
tablespace: options['indexTablespace'],
6161
nullsDistinct: options['nullsDistinct'],
62+
deferrable: options['deferrable'],
63+
deferrableConstraintCheckTime: options['deferrableConstraintCheckTime'],
6264
});
6365

6466
const hydratePrimaryKeyOptions = (options, columnName, isActivated, jsonSchema) =>
@@ -75,6 +77,8 @@ module.exports = (_, clean) => {
7577
storageParameters: options['indexStorageParameters'],
7678
comment: options['indexComment'],
7779
tablespace: options['indexTablespace'],
80+
deferrable: options['deferrable'],
81+
deferrableConstraintCheckTime: options['deferrableConstraintCheckTime'],
7882
});
7983

8084
const findName = (keyId, properties) => {

forward_engineering/ddlProvider/templates.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ module.exports = {
2222

2323
createForeignKeyConstraint: '${name} FOREIGN KEY (${foreignKey}) REFERENCES ${primaryTable} (${primaryKey})${match}${onDelete}${onUpdate}${deferrable}${deferrableConstraintCheckTime}',
2424

25-
createKeyConstraint: '${constraintName}${keyType}${columns}${includeNonKey}${storageParameters}${tablespace}',
25+
createKeyConstraint: '${constraintName}${keyType}${columns}${includeNonKey}${storageParameters}${tablespace}${deferrable}${deferrableConstraintCheckTime}',
2626

2727
alterColumnType: 'ALTER TABLE IF EXISTS ${tableName} ALTER COLUMN ${columnName} SET DATA TYPE ${dataType};',
2828

0 commit comments

Comments
 (0)