From 2af337c83905c420b2d9022ee6fd3d6ef5fd1e42 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Tue, 10 Nov 2020 16:29:35 +0100 Subject: Cleanup follows of orphean actors --- .../migrations/0550-actor-follow-cleanup.ts | 27 ++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 server/initializers/migrations/0550-actor-follow-cleanup.ts (limited to 'server/initializers/migrations/0550-actor-follow-cleanup.ts') diff --git a/server/initializers/migrations/0550-actor-follow-cleanup.ts b/server/initializers/migrations/0550-actor-follow-cleanup.ts new file mode 100644 index 000000000..8ba6feec2 --- /dev/null +++ b/server/initializers/migrations/0550-actor-follow-cleanup.ts @@ -0,0 +1,27 @@ +import * as Sequelize from 'sequelize' + +async function up (utils: { + transaction: Sequelize.Transaction + queryInterface: Sequelize.QueryInterface + sequelize: Sequelize.Sequelize +}): Promise { + const query = ` + WITH t AS ( + SELECT actor.id FROM actor + LEFT JOIN "videoChannel" ON "videoChannel"."actorId" = actor.id + LEFT JOIN account ON account."actorId" = "actor"."id" + WHERE "videoChannel".id IS NULL and "account".id IS NULL + ) DELETE FROM "actorFollow" WHERE "actorId" IN (SELECT t.id FROM t) OR "targetActorId" in (SELECT t.id FROM t) + ` + + await utils.sequelize.query(query) +} + +function down (options) { + throw new Error('Not implemented.') +} + +export { + up, + down +} -- cgit v1.2.3