mirror of
https://github.com/Fabio286/antares.git
synced 2025-03-09 16:00:17 +01:00
feat(PostgreSQL): foreign keys management
This commit is contained in:
parent
21728a663d
commit
fe4c8e12b3
@ -1066,7 +1066,7 @@ export class PostgreSQLClient extends AntaresCore {
|
|||||||
|
|
||||||
// ADD FOREIGN KEYS
|
// ADD FOREIGN KEYS
|
||||||
foreignChanges.additions.forEach(addition => {
|
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
|
// CHANGE FIELDS
|
||||||
@ -1124,8 +1124,8 @@ export class PostgreSQLClient extends AntaresCore {
|
|||||||
|
|
||||||
// CHANGE FOREIGN KEYS
|
// CHANGE FOREIGN KEYS
|
||||||
foreignChanges.changes.forEach(change => {
|
foreignChanges.changes.forEach(change => {
|
||||||
alterColumns.push(`DROP FOREIGN KEY \`${change.oldName}\``);
|
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}`);
|
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
|
// DROP FIELDS
|
||||||
@ -1143,7 +1143,7 @@ export class PostgreSQLClient extends AntaresCore {
|
|||||||
|
|
||||||
// DROP FOREIGN KEYS
|
// DROP FOREIGN KEYS
|
||||||
foreignChanges.deletions.forEach(deletion => {
|
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(', ')}; `;
|
if (alterColumns.length) sql += `ALTER TABLE "${table}" ${alterColumns.join(', ')}; `;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user