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, + }); + } +};