From c4d1490d0133e68fe0df4ea900298645b7d8d1c3 Mon Sep 17 00:00:00 2001 From: Jori Lallo Date: Mon, 25 Dec 2017 17:17:42 +0200 Subject: [PATCH] Added migration for adding initial admins --- .../migrations/20171225143838-set-admins.js | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 server/migrations/20171225143838-set-admins.js diff --git a/server/migrations/20171225143838-set-admins.js b/server/migrations/20171225143838-set-admins.js new file mode 100644 index 000000000..cd4893ac7 --- /dev/null +++ b/server/migrations/20171225143838-set-admins.js @@ -0,0 +1,23 @@ +module.exports = { + up: async (queryInterface, Sequelize) => { + const [teams, metaData] = await queryInterface.sequelize.query(`SELECT * FROM teams`); + const teamIds = teams.map(team => team.id); + await Promise.all(teamIds.map(async teamId => { + await queryInterface.sequelize.query(` + update users + set "isAdmin" = true + where id in ( + select id + from users + where "teamId" = '${teamId}' + order by "createdAt" asc + limit 1 + ); + `); + })); + }, + + down: async (queryInterface, Sequelize) => { + // no-op + }, +};