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