diff --git a/server/migrations/20191119023012-cascade-shares.js b/server/migrations/20191119023012-cascade-shares.js new file mode 100644 index 000000000..bb40d3e25 --- /dev/null +++ b/server/migrations/20191119023012-cascade-shares.js @@ -0,0 +1,22 @@ +const tableName = 'shares'; +const constraintName = 'shares_documentId_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("documentId") 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("documentId") references "documents" ("id") + on delete no action` + ); + }, +}; \ No newline at end of file diff --git a/server/migrations/20191119023013-cascade-backlinks2.js b/server/migrations/20191119023013-cascade-backlinks2.js new file mode 100644 index 000000000..b687a7eb5 --- /dev/null +++ b/server/migrations/20191119023013-cascade-backlinks2.js @@ -0,0 +1,22 @@ +const tableName = 'backlinks'; +const constraintName = 'backlinks_documentId_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("documentId") 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("documentId") references "documents" ("id") + on delete no action` + ); + }, +}; \ No newline at end of file