From 28beebce824b84b166b25a64031b8c59cdcbac32 Mon Sep 17 00:00:00 2001 From: Daniel Bachler Date: Wed, 29 Nov 2023 21:14:56 +0100 Subject: [PATCH] :hammer: fix posts_links FK constraint, add reusable block tombstones --- ...1658-FixPostLinksForeingKeyDeleteClause.ts | 22 +++++++++++++++++++ db/syncPostsToGrapher.ts | 5 ++++- 2 files changed, 26 insertions(+), 1 deletion(-) create mode 100644 db/migration/1701280181658-FixPostLinksForeingKeyDeleteClause.ts diff --git a/db/migration/1701280181658-FixPostLinksForeingKeyDeleteClause.ts b/db/migration/1701280181658-FixPostLinksForeingKeyDeleteClause.ts new file mode 100644 index 00000000000..59785a8dd72 --- /dev/null +++ b/db/migration/1701280181658-FixPostLinksForeingKeyDeleteClause.ts @@ -0,0 +1,22 @@ +import { MigrationInterface, QueryRunner } from "typeorm" + +export class FixPostLinksForeingKeyDeleteClause1701280181658 + implements MigrationInterface +{ + public async up(queryRunner: QueryRunner): Promise { + await queryRunner.query(` + ALTER TABLE posts_links + DROP FOREIGN KEY posts_links_ibfk_1; + `) + await queryRunner.query(` + ALTER TABLE posts_links + ADD CONSTRAINT posts_links_ibfk_1 + FOREIGN KEY (sourceId) + REFERENCES posts(id) + ON UPDATE CASCADE + ON DELETE CASCADE; + `) + } + + public async down(queryRunner: QueryRunner): Promise {} +} diff --git a/db/syncPostsToGrapher.ts b/db/syncPostsToGrapher.ts index 7c8ad2c4b7c..41858cbed75 100644 --- a/db/syncPostsToGrapher.ts +++ b/db/syncPostsToGrapher.ts @@ -53,7 +53,10 @@ function buildReplacerFunction( matches: Record ) => { const block = blocks[matches["id"].toString()] - return block ? block.post_content : "" + return block + ? `` + + block.post_content + : "" } }