From f8c09569ed21f3b845cc18497371fb02be1ebc35 Mon Sep 17 00:00:00 2001 From: Ole-Martin Bratteng <1681525+omBratteng@users.noreply.github.com> Date: Thu, 6 Nov 2025 11:50:57 +0100 Subject: [PATCH] fix: set user source posts to ghost source --- src/common/user.ts | 7 ++++ src/common/utils.ts | 2 ++ .../1762425247562-GhostUserSource.ts | 32 +++++++++++++++++++ 3 files changed, 41 insertions(+) create mode 100644 src/migration/1762425247562-GhostUserSource.ts diff --git a/src/common/user.ts b/src/common/user.ts index a6e303c1ab..a73354d8ee 100644 --- a/src/common/user.ts +++ b/src/common/user.ts @@ -96,6 +96,13 @@ export const deleteUser = async ( await entityManager .getRepository(ArticlePost) .update({ authorId: userId }, { authorId: null }); + // Manually set user source posts to ghost user + await entityManager + .getRepository(Post) + .update( + { authorId: userId, sourceId: userId }, + { authorId: ghostUser.id, sourceId: ghostUser.id }, + ); // Manually set shared post to 404 dummy user await entityManager .getRepository(Post) diff --git a/src/common/utils.ts b/src/common/utils.ts index d216b5f8a6..cf06da9b3b 100644 --- a/src/common/utils.ts +++ b/src/common/utils.ts @@ -19,6 +19,8 @@ export const ghostUser = { id: '404', username: 'ghost', name: 'Deleted user', + image: + 'https://media.daily.dev/image/upload/s--hNIUzLiO--/f_auto/v1705327420/public/ghost_vlftth', }; export const deletedPost = { diff --git a/src/migration/1762425247562-GhostUserSource.ts b/src/migration/1762425247562-GhostUserSource.ts new file mode 100644 index 0000000000..ecde1df65d --- /dev/null +++ b/src/migration/1762425247562-GhostUserSource.ts @@ -0,0 +1,32 @@ +import { MigrationInterface, QueryRunner } from "typeorm"; +import { ghostUser } from "../common"; + +export class GhostUserSource1762425247562 implements MigrationInterface { + public async up(queryRunner: QueryRunner): Promise { + await queryRunner.query(/* sql */ ` + INSERT INTO "public"."source" ( + "id", + "name", + "image", + "handle", + "type", + "userId" + ) + VALUES ( + '${ghostUser.id}', + '${ghostUser.name}', + '${ghostUser.image}', + '${ghostUser.id}', + 'user', + '${ghostUser.id}' + ) + `); + } + + public async down(queryRunner: QueryRunner): Promise { + await queryRunner.query(/* sql */ ` + DELETE FROM "public"."source" + WHERE "id" = '${ghostUser.id}' + `); + } +}