]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/initializers/migrations/0085-user-role.ts
Support roles with rights and add moderator role
[github/Chocobozzz/PeerTube.git] / server / initializers / migrations / 0085-user-role.ts
CommitLineData
954605a8
C
1import * as Sequelize from 'sequelize'
2import * as uuidv4 from 'uuid/v4'
3
4async function up (utils: {
5 transaction: Sequelize.Transaction,
6 queryInterface: Sequelize.QueryInterface,
7 sequelize: Sequelize.Sequelize,
8 db: any
9}): Promise<void> {
10 const q = utils.queryInterface
11
12 await q.renameColumn('Users', 'role', 'oldRole')
13
14 const data = {
15 type: Sequelize.INTEGER,
16 allowNull: true
17 }
18 await q.addColumn('Users', 'role', data)
19
20 let query = 'UPDATE "Users" SET "role" = 0 WHERE "oldRole" = \'admin\''
21 await utils.sequelize.query(query)
22
23 query = 'UPDATE "Users" SET "role" = 2 WHERE "oldRole" = \'user\''
24 await utils.sequelize.query(query)
25
26 data.allowNull = false
27 await q.changeColumn('Users', 'role', data)
28
29 await q.removeColumn('Users', 'oldRole')
30}
31
32function down (options) {
33 throw new Error('Not implemented.')
34}
35
36export {
37 up,
38 down
39}