summary refs log tree commit diff
path: root/src/database/migration/postgres/1776178642013-Int8PrimaryKeysWebhooks.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/1776178642013-Int8PrimaryKeysWebhooks.ts
parentFix recursive import in database (diff)
downloadserver-ts-83e60464ad2675f09ddee02f6b166bef22f53f33.tar.xz
Move migrations to database
Diffstat (limited to 'src/database/migration/postgres/1776178642013-Int8PrimaryKeysWebhooks.ts')
-rw-r--r--src/database/migration/postgres/1776178642013-Int8PrimaryKeysWebhooks.ts23
1 files changed, 23 insertions, 0 deletions
diff --git a/src/database/migration/postgres/1776178642013-Int8PrimaryKeysWebhooks.ts b/src/database/migration/postgres/1776178642013-Int8PrimaryKeysWebhooks.ts
new file mode 100644

index 00000000..a5fdfbdf --- /dev/null +++ b/src/database/migration/postgres/1776178642013-Int8PrimaryKeysWebhooks.ts
@@ -0,0 +1,23 @@ +import { MigrationInterface, QueryRunner } from "typeorm"; + +export class Int8PrimaryKeysWebhooks1776178642013 implements MigrationInterface { + name = "Int8PrimaryKeysWebhooks1776178642013"; + + 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) { + // webhooks + // -> messages + await queryRunner.query(`ALTER TABLE messages DROP CONSTRAINT "FK_f83c04bcf1df4e5c0e7a52ed348";`); //webhook_id + await queryRunner.query(`ALTER TABLE messages ALTER COLUMN webhook_id TYPE ${to} USING webhook_id::${to}`); + // and finally, cleanup + await queryRunner.query(`ALTER TABLE webhooks ALTER COLUMN id TYPE ${to} USING id::${to};`); + await queryRunner.query(`ALTER TABLE public.messages ADD CONSTRAINT "FK_f83c04bcf1df4e5c0e7a52ed348" FOREIGN KEY (webhook_id) REFERENCES webhooks(id);`); + } +}