summary refs log tree commit diff
path: root/src/util/migration/postgres/1776178642007-Int8PrimaryKeysStickerPacks.ts
diff options
context:
space:
mode:
authorRory& <root@rory.gay>2026-04-14 23:46:44 +0200
committerRory& <root@rory.gay>2026-04-18 18:26:34 +0200
commitc7b01a2fed8d607f80abe4223b77a5e40ced150e (patch)
tree95fa5ac5eb4528f7297ab729d7917b16bc50fbf2 /src/util/migration/postgres/1776178642007-Int8PrimaryKeysStickerPacks.ts
parentAdd media1.tenor.com explicitly as image handler (diff)
downloadserver-ts-c7b01a2fed8d607f80abe4223b77a5e40ced150e.tar.xz
int8 primary keys
Diffstat (limited to 'src/util/migration/postgres/1776178642007-Int8PrimaryKeysStickerPacks.ts')
-rw-r--r--src/util/migration/postgres/1776178642007-Int8PrimaryKeysStickerPacks.ts25
1 files changed, 25 insertions, 0 deletions
diff --git a/src/util/migration/postgres/1776178642007-Int8PrimaryKeysStickerPacks.ts b/src/util/migration/postgres/1776178642007-Int8PrimaryKeysStickerPacks.ts
new file mode 100644

index 000000000..fbde54f0a --- /dev/null +++ b/src/util/migration/postgres/1776178642007-Int8PrimaryKeysStickerPacks.ts
@@ -0,0 +1,25 @@ +import { MigrationInterface, QueryRunner } from "typeorm"; + +export class Int8PrimaryKeysStickerPacks1776178642007 implements MigrationInterface { + name = "Int8PrimaryKeysStickerPacks1776178642007"; + + public async up(queryRunner: QueryRunner): Promise<void> { + await this.convertPks(queryRunner, "int8"); + } + + public async down(queryRunner: QueryRunner): Promise<void> { + await this.convertPks(queryRunner, "varchar"); + } + + private async convertPks(queryRunner: QueryRunner, to: string) { + // sticker_packs + // -> stickers + await queryRunner.query(`ALTER TABLE stickers DROP CONSTRAINT "FK_e7cfa5cefa6661b3fb8fda8ce69";`); //pack_id + await queryRunner.query(`ALTER TABLE stickers ALTER COLUMN pack_id TYPE ${to} USING pack_id::${to}`); + // and finally, cleanup + await queryRunner.query(`ALTER TABLE sticker_packs ALTER COLUMN id TYPE ${to} USING id::${to};`); + await queryRunner.query( + `ALTER TABLE public.stickers ADD CONSTRAINT "FK_e7cfa5cefa6661b3fb8fda8ce69" FOREIGN KEY (pack_id) REFERENCES sticker_packs(id) ON DELETE CASCADE;`, + ); + } +}