From 5b501fa8da8fcd081d48f3cd2ad7eba9b4a2f302 Mon Sep 17 00:00:00 2001 From: Rory& Date: Wed, 15 Apr 2026 19:02:01 +0200 Subject: No attachment URLs --- .../1776270346000-DontStoreAttachmentUrls.ts | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 src/util/migration/postgres/1776270346000-DontStoreAttachmentUrls.ts (limited to 'src/util/migration/postgres') diff --git a/src/util/migration/postgres/1776270346000-DontStoreAttachmentUrls.ts b/src/util/migration/postgres/1776270346000-DontStoreAttachmentUrls.ts new file mode 100644 index 000000000..674a3e54d --- /dev/null +++ b/src/util/migration/postgres/1776270346000-DontStoreAttachmentUrls.ts @@ -0,0 +1,21 @@ +import { MigrationInterface, QueryRunner } from "typeorm"; + +export class DontStoreAttachmentUrls1776270346000 implements MigrationInterface { + name = "DontStoreAttachmentUrls1776270346000"; + + public async up(queryRunner: QueryRunner): Promise { + await this.convertPks(queryRunner, "jsonb"); + } + + public async down(queryRunner: QueryRunner): Promise { + await this.convertPks(queryRunner, "varchar"); + } + + private async convertPks(queryRunner: QueryRunner, to: string) { + await queryRunner.query(`ALTER TABLE attachments ADD channel_id int8 NULL;`); + await queryRunner.query(`ALTER TABLE attachments ADD CONSTRAINT attachments_channels_fk FOREIGN KEY (channel_id) REFERENCES public.channels(id) ON DELETE CASCADE;`); + await queryRunner.query(`UPDATE attachments att SET channel_id = (SELECT channel_id FROM messages WHERE id = att.message_id) WHERE message_id IS NOT NULL;`); + await queryRunner.query(`ALTER TABLE attachments DROP COLUMN url;`); + await queryRunner.query(`ALTER TABLE attachments DROP COLUMN proxy_url;`); + } +} -- cgit 1.5.1