From: Chocobozzz Date: Fri, 15 Dec 2017 17:44:17 +0000 (+0100) Subject: Add public/private keys generation in migrations X-Git-Tag: v0.0.1-alpha~123 X-Git-Url: https://git.immae.eu/?a=commitdiff_plain;h=555846c99fa43b237814d32bd55d8124405187d3;p=github%2FChocobozzz%2FPeerTube.git Add public/private keys generation in migrations --- diff --git a/server/initializers/migrations/0130-video-channel-actor.ts b/server/initializers/migrations/0130-video-channel-actor.ts index 0b665b0c7..15b67be81 100644 --- a/server/initializers/migrations/0130-video-channel-actor.ts +++ b/server/initializers/migrations/0130-video-channel-actor.ts @@ -1,5 +1,6 @@ import * as Sequelize from 'sequelize' import { DataType } from 'sequelize-typescript' +import { createPrivateAndPublicKeys } from '../../helpers' async function up (utils: { transaction: Sequelize.Transaction, @@ -223,6 +224,18 @@ async function up (utils: { await utils.queryInterface.removeColumn('videoChannel', columnToDelete) } } + + { + const query = 'SELECT * FROM "actor" WHERE "serverId" IS NULL AND "publicKey" IS NULL' + const [ res ] = await utils.sequelize.query(query) + + for (const actor of res) { + const { privateKey, publicKey } = await createPrivateAndPublicKeys() + + const queryUpdate = `UPDATE "actor" SET "publicKey" = '${publicKey}', "privateKey" = '${privateKey}' WHERE id = ${actor.id}` + await utils.sequelize.query(queryUpdate) + } + } } function down (options) {