]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/initializers/migrations/0605-actor-missing-keys.ts
Add Podcast RSS feeds (#5487)
[github/Chocobozzz/PeerTube.git] / server / initializers / migrations / 0605-actor-missing-keys.ts
CommitLineData
8795d6f2 1import * as Sequelize from 'sequelize'
5d7cb63e 2import { generateRSAKeyPairPromise } from '../../helpers/core-utils'
8795d6f2
C
3import { PRIVATE_RSA_KEY_SIZE } from '../constants'
4
5async function up (utils: {
6 transaction: Sequelize.Transaction
7 queryInterface: Sequelize.QueryInterface
8 sequelize: Sequelize.Sequelize
9 db: any
10}): Promise<void> {
11
12 {
13 const query = 'SELECT * FROM "actor" WHERE "serverId" IS NULL AND "publicKey" IS NULL'
14 const options = { type: Sequelize.QueryTypes.SELECT as Sequelize.QueryTypes.SELECT }
15 const actors = await utils.sequelize.query<any>(query, options)
16
17 for (const actor of actors) {
5d7cb63e 18 const { privateKey, publicKey } = await generateRSAKeyPairPromise(PRIVATE_RSA_KEY_SIZE)
8795d6f2 19
5d7cb63e 20 const queryUpdate = `UPDATE "actor" SET "publicKey" = '${publicKey}', "privateKey" = '${privateKey}' WHERE id = ${actor.id}`
8795d6f2
C
21 await utils.sequelize.query(queryUpdate)
22 }
23 }
24}
25
26function down (options) {
27 throw new Error('Not implemented.')
28}
29
30export {
31 up,
32 down
33}