From fe4c8e12b39dd3cdfc233f07e3fe2ff0676252b0 Mon Sep 17 00:00:00 2001 From: Fabio Di Stasio Date: Wed, 31 Mar 2021 15:57:23 +0200 Subject: [PATCH] feat(PostgreSQL): foreign keys management --- src/main/libs/clients/PostgreSQLClient.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main/libs/clients/PostgreSQLClient.js b/src/main/libs/clients/PostgreSQLClient.js index 954da69f..7d2cda87 100644 --- a/src/main/libs/clients/PostgreSQLClient.js +++ b/src/main/libs/clients/PostgreSQLClient.js @@ -1066,7 +1066,7 @@ export class PostgreSQLClient extends AntaresCore { // ADD FOREIGN KEYS foreignChanges.additions.forEach(addition => { - alterColumns.push(`ADD CONSTRAINT \`${addition.constraintName}\` FOREIGN KEY (\`${addition.field}\`) REFERENCES \`${addition.refTable}\` (\`${addition.refField}\`) ON UPDATE ${addition.onUpdate} ON DELETE ${addition.onDelete}`); + alterColumns.push(`ADD CONSTRAINT ${addition.constraintName} FOREIGN KEY (${addition.field}) REFERENCES ${addition.refTable} (${addition.refField}) ON UPDATE ${addition.onUpdate} ON DELETE ${addition.onDelete}`); }); // CHANGE FIELDS @@ -1124,8 +1124,8 @@ export class PostgreSQLClient extends AntaresCore { // CHANGE FOREIGN KEYS foreignChanges.changes.forEach(change => { - alterColumns.push(`DROP FOREIGN KEY \`${change.oldName}\``); - alterColumns.push(`ADD CONSTRAINT \`${change.constraintName}\` FOREIGN KEY (\`${change.field}\`) REFERENCES \`${change.refTable}\` (\`${change.refField}\`) ON UPDATE ${change.onUpdate} ON DELETE ${change.onDelete}`); + alterColumns.push(`DROP CONSTRAINT ${change.oldName}`); + alterColumns.push(`ADD CONSTRAINT ${change.constraintName} FOREIGN KEY (${change.field}) REFERENCES ${change.refTable} (${change.refField}) ON UPDATE ${change.onUpdate} ON DELETE ${change.onDelete}`); }); // DROP FIELDS @@ -1143,7 +1143,7 @@ export class PostgreSQLClient extends AntaresCore { // DROP FOREIGN KEYS foreignChanges.deletions.forEach(deletion => { - alterColumns.push(`DROP FOREIGN KEY ${deletion.constraintName}`); + alterColumns.push(`DROP CONSTRAINT ${deletion.constraintName}`); }); if (alterColumns.length) sql += `ALTER TABLE "${table}" ${alterColumns.join(', ')}; `;