From 678800511578a72bfdf4c77fed205fc0b6d01deb Mon Sep 17 00:00:00 2001 From: Tom Moor Date: Fri, 11 Nov 2022 09:40:52 -0800 Subject: [PATCH] Add missing team->user constraint (#4411) * Add missing team->user constraint * fix: teamPermanentDeleter cannot complete when team has domains --- server/commands/teamPermanentDeleter.ts | 7 ------- .../20221111171828-fix-user-constraints.js | 19 +++++++++++++++++++ 2 files changed, 19 insertions(+), 7 deletions(-) create mode 100644 server/migrations/20221111171828-fix-user-constraints.js diff --git a/server/commands/teamPermanentDeleter.ts b/server/commands/teamPermanentDeleter.ts index be99053a7..cd47aad13 100644 --- a/server/commands/teamPermanentDeleter.ts +++ b/server/commands/teamPermanentDeleter.ts @@ -175,13 +175,6 @@ async function teamPermanentDeleter(team: Team) { force: true, transaction, }); - await User.destroy({ - where: { - teamId, - }, - force: true, - transaction, - }); await team.destroy({ force: true, transaction, diff --git a/server/migrations/20221111171828-fix-user-constraints.js b/server/migrations/20221111171828-fix-user-constraints.js new file mode 100644 index 000000000..8e5ca0b4d --- /dev/null +++ b/server/migrations/20221111171828-fix-user-constraints.js @@ -0,0 +1,19 @@ +'use strict'; + +module.exports = { + up: async (queryInterface, Sequelize) => { + await queryInterface.changeColumn("users", "teamId", { + type: Sequelize.UUID, + onDelete: "cascade", + references: { + model: "teams", + }, + }); + }, + + down: async (queryInterface, Sequelize) => { + await queryInterface.changeColumn("users", "teamId", { + type: Sequelize.UUID, + }); + } +};