aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/initializers/migrations/0530-user-feed-token.ts
diff options
context:
space:
mode:
authorRigel Kent <sendmemail@rigelk.eu>2020-08-13 15:07:23 +0200
committerChocobozzz <chocobozzz@cpy.re>2020-11-25 11:07:56 +0100
commitafff310e50f2fa8419bb4242470cbde46ab54463 (patch)
tree34efda2daf8f7cdfd89ef6616a79e2222082f93a /server/initializers/migrations/0530-user-feed-token.ts
parentf619de0e435f7ac3abad2ec772397486358b56e7 (diff)
downloadPeerTube-afff310e50f2fa8419bb4242470cbde46ab54463.tar.gz
PeerTube-afff310e50f2fa8419bb4242470cbde46ab54463.tar.zst
PeerTube-afff310e50f2fa8419bb4242470cbde46ab54463.zip
allow private syndication feeds via a user feedToken
Diffstat (limited to 'server/initializers/migrations/0530-user-feed-token.ts')
-rw-r--r--server/initializers/migrations/0530-user-feed-token.ts40
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 @@
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 // 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
33function down (options) {
34 throw new Error('Not implemented.')
35}
36
37export {
38 up,
39 down
40}