Added migration for adding initial admins

This commit is contained in:
Jori Lallo
2017-12-25 17:17:42 +02:00
parent 0fd30a7313
commit c4d1490d01

View File

@@ -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
},
};