0605-actor-missing-keys.ts 1003 B

123456789101112131415161718192021222324252627282930313233
  1. import * as Sequelize from 'sequelize'
  2. import { generateRSAKeyPairPromise } from '../../helpers/core-utils.js'
  3. import { PRIVATE_RSA_KEY_SIZE } from '../constants.js'
  4. async function up (utils: {
  5. transaction: Sequelize.Transaction
  6. queryInterface: Sequelize.QueryInterface
  7. sequelize: Sequelize.Sequelize
  8. db: any
  9. }): Promise<void> {
  10. {
  11. const query = 'SELECT * FROM "actor" WHERE "serverId" IS NULL AND "publicKey" IS NULL'
  12. const options = { type: Sequelize.QueryTypes.SELECT as Sequelize.QueryTypes.SELECT }
  13. const actors = await utils.sequelize.query<any>(query, options)
  14. for (const actor of actors) {
  15. const { privateKey, publicKey } = await generateRSAKeyPairPromise(PRIVATE_RSA_KEY_SIZE)
  16. const queryUpdate = `UPDATE "actor" SET "publicKey" = '${publicKey}', "privateKey" = '${privateKey}' WHERE id = ${actor.id}`
  17. await utils.sequelize.query(queryUpdate)
  18. }
  19. }
  20. }
  21. function down (options) {
  22. throw new Error('Not implemented.')
  23. }
  24. export {
  25. up,
  26. down
  27. }