From 7c083b4bfe0af60504077b4e275fd9a54b3f6d2b Mon Sep 17 00:00:00 2001 From: Tom Moor Date: Thu, 28 Mar 2024 19:50:50 -0600 Subject: [PATCH] chore: Remove `isViewer` and `isAdmin` columns (#6734) --- .../20240329012958-remove-old-role-columns.js | 42 +++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 server/migrations/20240329012958-remove-old-role-columns.js diff --git a/server/migrations/20240329012958-remove-old-role-columns.js b/server/migrations/20240329012958-remove-old-role-columns.js new file mode 100644 index 000000000..270b52b9b --- /dev/null +++ b/server/migrations/20240329012958-remove-old-role-columns.js @@ -0,0 +1,42 @@ +'use strict'; + +module.exports = { + async up(queryInterface) { + await queryInterface.sequelize.transaction(async (transaction) => { + await queryInterface.removeColumn("users", "isAdmin", { transaction }); + await queryInterface.removeColumn("users", "isViewer", { transaction }); + }); + }, + + async down(queryInterface, Sequelize) { + await queryInterface.sequelize.transaction(async (transaction) => { + await queryInterface.addColumn("users", "isAdmin", { + type: Sequelize.BOOLEAN, + allowNull: false, + defaultValue: false, + }); + await queryInterface.addColumn("users", "isViewer", { + type: Sequelize.BOOLEAN, + allowNull: false, + defaultValue: false, + }); + }); + + await queryInterface.sequelize.transaction(async (transaction) => { + await queryInterface.sequelize.query( + `UPDATE users SET "isAdmin" = true WHERE role = 'admin'`, + { + transaction, + type: Sequelize.QueryTypes.UPDATE, + } + ); + await queryInterface.sequelize.query( + `UPDATE users SET "isViewer" = true WHERE role = 'viewer'`, + { + transaction, + type: Sequelize.QueryTypes.UPDATE, + } + ); + }); + } +}; \ No newline at end of file