summary refs log tree commit diff
path: root/src/database/migration/postgres/1776178642008-Int8PrimaryKeysStickers.ts
diff options
context:
space:
mode:
authorRory& <root@rory.gay>2026-06-11 23:18:02 +0200
committerRory& <root@rory.gay>2026-06-12 17:58:18 +0200
commit83e60464ad2675f09ddee02f6b166bef22f53f33 (patch)
tree9e12033c00c8420166f52c397b461cad288277fe /src/database/migration/postgres/1776178642008-Int8PrimaryKeysStickers.ts
parentFix recursive import in database (diff)
downloadserver-ts-83e60464ad2675f09ddee02f6b166bef22f53f33.tar.xz
Move migrations to database
Diffstat (limited to 'src/database/migration/postgres/1776178642008-Int8PrimaryKeysStickers.ts')
-rw-r--r--src/database/migration/postgres/1776178642008-Int8PrimaryKeysStickers.ts29
1 files changed, 29 insertions, 0 deletions
diff --git a/src/database/migration/postgres/1776178642008-Int8PrimaryKeysStickers.ts b/src/database/migration/postgres/1776178642008-Int8PrimaryKeysStickers.ts
new file mode 100644

index 00000000..4f52a570 --- /dev/null +++ b/src/database/migration/postgres/1776178642008-Int8PrimaryKeysStickers.ts
@@ -0,0 +1,29 @@ +import { MigrationInterface, QueryRunner } from "typeorm"; + +export class Int8PrimaryKeysStickers1776178642008 implements MigrationInterface { + name = "Int8PrimaryKeysStickers1776178642008"; + + 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) { + // stickers + // -> message_stickers + await queryRunner.query(`ALTER TABLE message_stickers DROP CONSTRAINT "FK_e22a70819d07659c7a71c112a1f";`); //stickersId + await queryRunner.query(`ALTER TABLE message_stickers ALTER COLUMN "stickersId" TYPE ${to} USING "stickersId"::${to}`); + // -> sticker_packs + await queryRunner.query(`ALTER TABLE sticker_packs DROP CONSTRAINT "FK_448fafba4355ee1c837bbc865f1";`); //coverStickerId + await queryRunner.query(`ALTER TABLE sticker_packs ALTER COLUMN "coverStickerId" TYPE ${to} USING "coverStickerId"::${to}`); + // and finally, cleanup + await queryRunner.query(`ALTER TABLE stickers ALTER COLUMN id TYPE ${to} USING id::${to};`); + await queryRunner.query( + `ALTER TABLE public.message_stickers ADD CONSTRAINT "FK_e22a70819d07659c7a71c112a1f" FOREIGN KEY ("stickersId") REFERENCES stickers(id) ON UPDATE CASCADE ON DELETE CASCADE;`, + ); + await queryRunner.query(`ALTER TABLE public.sticker_packs ADD CONSTRAINT "FK_448fafba4355ee1c837bbc865f1" FOREIGN KEY ("coverStickerId") REFERENCES stickers (id);`); + } +}