Add public/private keys generation in migrations

pull/161/head
Chocobozzz 2017-12-15 18:44:17 +01:00
parent 39fdb3c032
commit 555846c99f
No known key found for this signature in database
GPG Key ID: 583A612D890159BE
1 changed files with 13 additions and 0 deletions

View File

@ -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) {