fix: Additional SQL cascades required
This commit is contained in:
22
server/migrations/20191119023011-cascade-parent-documents.js
Normal file
22
server/migrations/20191119023011-cascade-parent-documents.js
Normal file
@@ -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`
|
||||
);
|
||||
},
|
||||
};
|
||||
Reference in New Issue
Block a user