aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/initializers/migrations/0560-user-feed-token.ts
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2020-11-25 11:04:18 +0100
committerChocobozzz <chocobozzz@cpy.re>2020-11-25 11:07:56 +0100
commit18490b07650d77d7fe376970b749af5a8c672fd6 (patch)
tree89741e63e34c2659487c9afa8309755064cb0c39 /server/initializers/migrations/0560-user-feed-token.ts
parent5beb89f223539f1e415a976ff104f772526b4d20 (diff)
downloadPeerTube-18490b07650d77d7fe376970b749af5a8c672fd6.tar.gz
PeerTube-18490b07650d77d7fe376970b749af5a8c672fd6.tar.zst
PeerTube-18490b07650d77d7fe376970b749af5a8c672fd6.zip
Fix migration and test
Diffstat (limited to 'server/initializers/migrations/0560-user-feed-token.ts')
-rw-r--r--server/initializers/migrations/0560-user-feed-token.ts51
1 files changed, 51 insertions, 0 deletions
diff --git a/server/initializers/migrations/0560-user-feed-token.ts b/server/initializers/migrations/0560-user-feed-token.ts
new file mode 100644
index 000000000..7c61def17
--- /dev/null
+++ b/server/initializers/migrations/0560-user-feed-token.ts
@@ -0,0 +1,51 @@
1import * as Sequelize from 'sequelize'
2import { v4 as uuidv4 } from 'uuid'
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 {
13 // Create uuid column for users
14 const userFeedTokenUUID = {
15 type: Sequelize.UUID,
16 defaultValue: Sequelize.UUIDV4,
17 allowNull: true
18 }
19 await q.addColumn('user', 'feedToken', userFeedTokenUUID)
20 }
21
22 // Set UUID to previous users
23 {
24 const query = 'SELECT * FROM "user" WHERE "feedToken" IS NULL'
25 const options = { type: Sequelize.QueryTypes.SELECT as Sequelize.QueryTypes.SELECT }
26 const users = await utils.sequelize.query<any>(query, options)
27
28 for (const user of users) {
29 const queryUpdate = `UPDATE "user" SET "feedToken" = '${uuidv4()}' WHERE id = ${user.id}`
30 await utils.sequelize.query(queryUpdate)
31 }
32 }
33
34 {
35 const userFeedTokenUUID = {
36 type: Sequelize.UUID,
37 defaultValue: Sequelize.UUIDV4,
38 allowNull: false
39 }
40 await q.changeColumn('user', 'feedToken', userFeedTokenUUID)
41 }
42}
43
44function down (options) {
45 throw new Error('Not implemented.')
46}
47
48export {
49 up,
50 down
51}