aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/initializers/migrations
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2021-02-26 14:22:25 +0100
committerChocobozzz <me@florianbigard.com>2021-02-26 14:22:25 +0100
commit8795d6f254bd8f88c385bf77b82cc6f177c94df9 (patch)
tree88f8f4fced9e0c12db5b43dcac6e44bd94eb8b1a /server/initializers/migrations
parent92315d979c3f424d81f8fca3c8831d81e4e2a6d6 (diff)
downloadPeerTube-8795d6f254bd8f88c385bf77b82cc6f177c94df9.tar.gz
PeerTube-8795d6f254bd8f88c385bf77b82cc6f177c94df9.tar.zst
PeerTube-8795d6f254bd8f88c385bf77b82cc6f177c94df9.zip
Fix broken local actors
Some channels can't federate because they don't have public/private keys, maybe because the generation failed for various reasons
Diffstat (limited to 'server/initializers/migrations')
-rw-r--r--server/initializers/migrations/0605-actor-missing-keys.ts34
1 files changed, 34 insertions, 0 deletions
diff --git a/server/initializers/migrations/0605-actor-missing-keys.ts b/server/initializers/migrations/0605-actor-missing-keys.ts
new file mode 100644
index 000000000..72d9b359d
--- /dev/null
+++ b/server/initializers/migrations/0605-actor-missing-keys.ts
@@ -0,0 +1,34 @@
1import * as Sequelize from 'sequelize'
2import { createPrivateKey, getPublicKey } from '../../helpers/core-utils'
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) {
18 const { key } = await createPrivateKey(PRIVATE_RSA_KEY_SIZE)
19 const { publicKey } = await getPublicKey(key)
20
21 const queryUpdate = `UPDATE "actor" SET "publicKey" = '${publicKey}', "privateKey" = '${key}' WHERE id = ${actor.id}`
22 await utils.sequelize.query(queryUpdate)
23 }
24 }
25}
26
27function down (options) {
28 throw new Error('Not implemented.')
29}
30
31export {
32 up,
33 down
34}