]>
Commit | Line | Data |
---|---|---|
954605a8 | 1 | import * as Sequelize from 'sequelize' |
954605a8 C |
2 | |
3 | async function up (utils: { | |
4 | transaction: Sequelize.Transaction, | |
5 | queryInterface: Sequelize.QueryInterface, | |
6 | sequelize: Sequelize.Sequelize, | |
7 | db: any | |
8 | }): Promise<void> { | |
9 | const q = utils.queryInterface | |
10 | ||
11 | await q.renameColumn('Users', 'role', 'oldRole') | |
12 | ||
13 | const data = { | |
14 | type: Sequelize.INTEGER, | |
15 | allowNull: true | |
16 | } | |
17 | await q.addColumn('Users', 'role', data) | |
18 | ||
19 | let query = 'UPDATE "Users" SET "role" = 0 WHERE "oldRole" = \'admin\'' | |
20 | await utils.sequelize.query(query) | |
21 | ||
22 | query = 'UPDATE "Users" SET "role" = 2 WHERE "oldRole" = \'user\'' | |
23 | await utils.sequelize.query(query) | |
24 | ||
25 | data.allowNull = false | |
26 | await q.changeColumn('Users', 'role', data) | |
27 | ||
28 | await q.removeColumn('Users', 'oldRole') | |
29 | } | |
30 | ||
31 | function down (options) { | |
32 | throw new Error('Not implemented.') | |
33 | } | |
34 | ||
35 | export { | |
36 | up, | |
37 | down | |
38 | } |