summary refs log tree commit diff
path: root/src/util/migration/postgres
diff options
context:
space:
mode:
authorRory& <root@rory.gay>2026-04-15 19:02:01 +0200
committerRory& <root@rory.gay>2026-04-18 18:26:34 +0200
commit5b501fa8da8fcd081d48f3cd2ad7eba9b4a2f302 (patch)
treefe2f6ec5001b188559e9aa4192d8585d9d3da35e /src/util/migration/postgres
parentjsonb (diff)
downloadserver-ts-5b501fa8da8fcd081d48f3cd2ad7eba9b4a2f302.tar.xz
No attachment URLs
Diffstat (limited to 'src/util/migration/postgres')
-rw-r--r--src/util/migration/postgres/1776270346000-DontStoreAttachmentUrls.ts21
1 files changed, 21 insertions, 0 deletions
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<void> { + await this.convertPks(queryRunner, "jsonb"); + } + + public async down(queryRunner: QueryRunner): Promise<void> { + 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;`); + } +}