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

index 00000000..b7dc5d4a --- /dev/null +++ b/src/database/migration/postgres/1776178642000-Int8PrimaryKeys.ts
@@ -0,0 +1,54 @@ +import { MigrationInterface, QueryRunner } from "typeorm"; + +export class Int8PrimaryKeys1776178642000 implements MigrationInterface { + name = "Int8PrimaryKeys1776178642000"; + + 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) { + // simple changes only + await queryRunner.query(`ALTER TABLE application_commands ALTER COLUMN id TYPE ${to} USING id::${to};`); // varchar + // applications -> separate migration + await queryRunner.query(`ALTER TABLE attachments ALTER COLUMN id TYPE ${to} USING id::${to};`); + await queryRunner.query(`ALTER TABLE audit_logs ALTER COLUMN id TYPE ${to} USING id::${to};`); + await queryRunner.query(`ALTER TABLE automod_rules ALTER COLUMN id TYPE ${to} USING id::${to};`); + await queryRunner.query(`ALTER TABLE backup_codes ALTER COLUMN id TYPE ${to} USING id::${to};`); + await queryRunner.query(`ALTER TABLE badges ALTER COLUMN id TYPE ${to} USING id::${to};`); + await queryRunner.query(`ALTER TABLE bans ALTER COLUMN id TYPE ${to} USING id::${to};`); + await queryRunner.query(`ALTER TABLE categories ALTER COLUMN id TYPE ${to} USING id::${to};`); + // channels -> separate migration + await queryRunner.query(`ALTER TABLE client_release ALTER COLUMN id TYPE ${to} USING id::${to};`); + await queryRunner.query(`ALTER TABLE cloud_attachments ALTER COLUMN id TYPE ${to} USING id::${to};`); + await queryRunner.query(`ALTER TABLE connected_accounts ALTER COLUMN id TYPE ${to} USING id::${to};`); + await queryRunner.query(`ALTER TABLE embed_cache ALTER COLUMN id TYPE ${to} USING id::${to};`); + await queryRunner.query(`ALTER TABLE emojis ALTER COLUMN id TYPE ${to} USING id::${to};`); + // guilds -> separate migration + // instance_bans -> separate migration + // messages -> separate migration + await queryRunner.query(`ALTER TABLE notes ALTER COLUMN id TYPE ${to} USING id::${to};`); + await queryRunner.query(`ALTER TABLE rate_limits ALTER COLUMN id TYPE ${to} USING id::${to};`); + await queryRunner.query(`ALTER TABLE read_states ALTER COLUMN id TYPE ${to} USING id::${to};`); + await queryRunner.query(`ALTER TABLE recipients ALTER COLUMN id TYPE ${to} USING id::${to};`); + await queryRunner.query(`ALTER TABLE relationships ALTER COLUMN id TYPE ${to} USING id::${to};`); + // roles -> separate migration + await queryRunner.query(`ALTER TABLE security_keys ALTER COLUMN id TYPE ${to} USING id::${to};`); + await queryRunner.query(`ALTER TABLE security_settings ALTER COLUMN id TYPE ${to} USING id::${to};`); + // sticker_packs -> separate migration + // stickers -> separate migration + await queryRunner.query(`ALTER TABLE stream_sessions ALTER COLUMN id TYPE ${to} USING id::${to};`); + // streams -> separate migration + await queryRunner.query(`ALTER TABLE tags ALTER COLUMN id TYPE ${to} USING id::${to};`); + await queryRunner.query(`ALTER TABLE team_members ALTER COLUMN id TYPE ${to} USING id::${to};`); + // teams -> separate migration + // templates -> separate migration + // users -> separate migration + await queryRunner.query(`ALTER TABLE voice_states ALTER COLUMN id TYPE ${to} USING id::${to};`); + // webhooks -> separate migration + } +}