From 2677c964a5eb58cd539658b25e60efbbb1011fc4 Mon Sep 17 00:00:00 2001 From: Tom Moor Date: Sun, 23 Jul 2023 19:51:42 -0400 Subject: [PATCH] chore: Improve constraints on file_operations table --- ...23231806-fix-file-operation-constraints.js | 57 +++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 server/migrations/20230723231806-fix-file-operation-constraints.js diff --git a/server/migrations/20230723231806-fix-file-operation-constraints.js b/server/migrations/20230723231806-fix-file-operation-constraints.js new file mode 100644 index 000000000..aece89168 --- /dev/null +++ b/server/migrations/20230723231806-fix-file-operation-constraints.js @@ -0,0 +1,57 @@ +'use strict'; + +module.exports = { + up: async (queryInterface, Sequelize) => { + await queryInterface.sequelize.transaction(async (transaction) => { + await queryInterface.removeConstraint("file_operations", "file_operations_collectionId_fkey", { transaction }); + await queryInterface.changeColumn("file_operations", "collectionId", { + type: Sequelize.UUID, + allowNull: true, + onDelete: "cascade", + references: { + model: "collections", + }, + }, { + transaction, + }); + + await queryInterface.removeConstraint("file_operations", "file_operations_teamId_fkey", { transaction }); + await queryInterface.changeColumn("file_operations", "teamId", { + type: Sequelize.UUID, + allowNull: false, + onDelete: "cascade", + references: { + model: "teams", + }, + }, { + transaction + }); + }); + }, + + down: async (queryInterface, Sequelize) => { + await queryInterface.sequelize.transaction(async (transaction) => { + await queryInterface.removeConstraint("file_operations", "file_operations_collectionId_fkey", { transaction }); + await queryInterface.changeColumn("file_operations", "collectionId", { + type: Sequelize.UUID, + allowNull: true, + references: { + model: "collections", + }, + }, { + transaction, + }); + + await queryInterface.removeConstraint("file_operations", "file_operations_teamId_fkey", { transaction }); + await queryInterface.changeColumn("file_operations", "teamId", { + type: Sequelize.UUID, + allowNull: false, + references: { + model: "teams", + }, + }, { + transaction, + }); + }); + } +};