From 3ea79dd31ad773c19b35818d9a1735d372ea0512 Mon Sep 17 00:00:00 2001 From: Tom Moor Date: Mon, 18 Nov 2019 19:49:33 -0800 Subject: [PATCH] fix: Additional SQL cascades required --- .../20191119023010-cascade-backlinks.js | 22 +++++++++++++++++++ ...20191119023011-cascade-parent-documents.js | 22 +++++++++++++++++++ 2 files changed, 44 insertions(+) create mode 100644 server/migrations/20191119023010-cascade-backlinks.js create mode 100644 server/migrations/20191119023011-cascade-parent-documents.js diff --git a/server/migrations/20191119023010-cascade-backlinks.js b/server/migrations/20191119023010-cascade-backlinks.js new file mode 100644 index 000000000..8b2ed5222 --- /dev/null +++ b/server/migrations/20191119023010-cascade-backlinks.js @@ -0,0 +1,22 @@ +const tableName = 'backlinks'; +const constraintName = 'backlinks_reverseDocumentId_fkey'; + +module.exports = { + up: async (queryInterface, Sequelize) => { + await queryInterface.sequelize.query(`alter table "${tableName}" drop constraint "${constraintName}"`) + await queryInterface.sequelize.query( + `alter table "${tableName}" + add constraint "${constraintName}" foreign key("reverseDocumentId") references "documents" ("id") + on delete cascade` + ); + }, + + down: async (queryInterface, Sequelize) => { + await queryInterface.sequelize.query(`alter table "${tableName}" drop constraint "${constraintName}"`) + await queryInterface.sequelize.query( + `alter table "${tableName}"\ + add constraint "${constraintName}" foreign key("reverseDocumentId") references "documents" ("id") + on delete no action` + ); + }, +}; \ No newline at end of file diff --git a/server/migrations/20191119023011-cascade-parent-documents.js b/server/migrations/20191119023011-cascade-parent-documents.js new file mode 100644 index 000000000..68999d257 --- /dev/null +++ b/server/migrations/20191119023011-cascade-parent-documents.js @@ -0,0 +1,22 @@ +const tableName = 'documents'; +const constraintName = 'documents_parentDocumentId_fkey'; + +module.exports = { + up: async (queryInterface, Sequelize) => { + await queryInterface.sequelize.query(`alter table "${tableName}" drop constraint "${constraintName}"`) + await queryInterface.sequelize.query( + `alter table "${tableName}" + add constraint "${constraintName}" foreign key("parentDocumentId") references "documents" ("id") + on delete cascade` + ); + }, + + down: async (queryInterface, Sequelize) => { + await queryInterface.sequelize.query(`alter table "${tableName}" drop constraint "${constraintName}"`) + await queryInterface.sequelize.query( + `alter table "${tableName}"\ + add constraint "${constraintName}" foreign key("parentDocumentId") references "documents" ("id") + on delete no action` + ); + }, +}; \ No newline at end of file