diff options
Diffstat (limited to 'server/initializers/migrations')
-rw-r--r-- | server/initializers/migrations/0530-user-feed-token.ts | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/server/initializers/migrations/0530-user-feed-token.ts b/server/initializers/migrations/0530-user-feed-token.ts new file mode 100644 index 000000000..421016b11 --- /dev/null +++ b/server/initializers/migrations/0530-user-feed-token.ts | |||
@@ -0,0 +1,40 @@ | |||
1 | import * as Sequelize from 'sequelize' | ||
2 | import { v4 as uuidv4 } from 'uuid' | ||
3 | |||
4 | async 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 | // Create uuid column for users | ||
13 | const userFeedTokenUUID = { | ||
14 | type: Sequelize.UUID, | ||
15 | defaultValue: Sequelize.UUIDV4, | ||
16 | allowNull: true | ||
17 | } | ||
18 | await q.addColumn('user', 'feedToken', userFeedTokenUUID) | ||
19 | |||
20 | // Set UUID to previous users | ||
21 | { | ||
22 | const query = 'SELECT * FROM "user" WHERE "feedToken" IS NULL' | ||
23 | const options = { type: Sequelize.QueryTypes.SELECT as Sequelize.QueryTypes.SELECT } | ||
24 | const users = await utils.sequelize.query<any>(query, options) | ||
25 | |||
26 | for (const user of users) { | ||
27 | const queryUpdate = `UPDATE "user" SET "feedToken" = '${uuidv4()}' WHERE id = ${user.id}` | ||
28 | await utils.sequelize.query(queryUpdate) | ||
29 | } | ||
30 | } | ||
31 | } | ||
32 | |||
33 | function down (options) { | ||
34 | throw new Error('Not implemented.') | ||
35 | } | ||
36 | |||
37 | export { | ||
38 | up, | ||
39 | down | ||
40 | } | ||