2021-02-26 08:22:25 -05:00
|
|
|
import * as Sequelize from 'sequelize'
|
2022-07-12 04:54:21 -04:00
|
|
|
import { generateRSAKeyPairPromise } from '../../helpers/core-utils'
|
2021-02-26 08:22:25 -05:00
|
|
|
import { PRIVATE_RSA_KEY_SIZE } from '../constants'
|
|
|
|
|
|
|
|
async function up (utils: {
|
|
|
|
transaction: Sequelize.Transaction
|
|
|
|
queryInterface: Sequelize.QueryInterface
|
|
|
|
sequelize: Sequelize.Sequelize
|
|
|
|
db: any
|
|
|
|
}): Promise<void> {
|
|
|
|
|
|
|
|
{
|
|
|
|
const query = 'SELECT * FROM "actor" WHERE "serverId" IS NULL AND "publicKey" IS NULL'
|
|
|
|
const options = { type: Sequelize.QueryTypes.SELECT as Sequelize.QueryTypes.SELECT }
|
|
|
|
const actors = await utils.sequelize.query<any>(query, options)
|
|
|
|
|
|
|
|
for (const actor of actors) {
|
2022-07-12 04:54:21 -04:00
|
|
|
const { privateKey, publicKey } = await generateRSAKeyPairPromise(PRIVATE_RSA_KEY_SIZE)
|
2021-02-26 08:22:25 -05:00
|
|
|
|
2022-07-12 04:54:21 -04:00
|
|
|
const queryUpdate = `UPDATE "actor" SET "publicKey" = '${publicKey}', "privateKey" = '${privateKey}' WHERE id = ${actor.id}`
|
2021-02-26 08:22:25 -05:00
|
|
|
await utils.sequelize.query(queryUpdate)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function down (options) {
|
|
|
|
throw new Error('Not implemented.')
|
|
|
|
}
|
|
|
|
|
|
|
|
export {
|
|
|
|
up,
|
|
|
|
down
|
|
|
|
}
|