0175-actor-follow-counts.ts 635 B

1234567891011121314151617181920212223
  1. import * as Sequelize from 'sequelize'
  2. async function up (utils: {
  3. transaction: Sequelize.Transaction,
  4. queryInterface: Sequelize.QueryInterface,
  5. sequelize: Sequelize.Sequelize
  6. }): Promise<void> {
  7. const query = 'UPDATE "actor" SET ' +
  8. '"followersCount" = (SELECT COUNT(*) FROM "actorFollow" WHERE "actor"."id" = "actorFollow"."targetActorId"), ' +
  9. '"followingCount" = (SELECT COUNT(*) FROM "actorFollow" WHERE "actor"."id" = "actorFollow"."actorId") ' +
  10. 'WHERE "actor"."serverId" IS NULL'
  11. await utils.sequelize.query(query)
  12. }
  13. function down (options) {
  14. throw new Error('Not implemented.')
  15. }
  16. export {
  17. up,
  18. down
  19. }