summary refs log tree commit diff
diff options
context:
space:
mode:
authorRory& <root@rory.gay>2026-04-15 22:42:15 +0200
committerRory& <root@rory.gay>2026-04-18 18:26:34 +0200
commit19f4f4724ab8d433cc5473c4136faf4a587726f0 (patch)
tree9f7935b64c1f311ded339be6b44d22cda9f5db93
parentFix attachments 2 (diff)
downloadserver-ts-19f4f4724ab8d433cc5473c4136faf4a587726f0.tar.xz
Fix missed relations
-rw-r--r--src/util/migration/postgres/1776283923000-Int8Fixes.ts39
1 files changed, 39 insertions, 0 deletions
diff --git a/src/util/migration/postgres/1776283923000-Int8Fixes.ts b/src/util/migration/postgres/1776283923000-Int8Fixes.ts
new file mode 100644

index 00000000..6983db5f --- /dev/null +++ b/src/util/migration/postgres/1776283923000-Int8Fixes.ts
@@ -0,0 +1,39 @@ +import { MigrationInterface, QueryRunner } from "typeorm"; + +export class Int8Fixes1776283923000 implements MigrationInterface { + name = "Int8Fixes1776283923000"; + + 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) { + await queryRunner.query(`ALTER TABLE application_commands ALTER COLUMN "version" SET DEFAULT 0::int8;`); + await queryRunner.query(`ALTER TABLE application_commands ALTER COLUMN application_id TYPE ${to} USING application_id::${to}`); + // missing relation + await queryRunner.query( + `ALTER TABLE application_commands ADD CONSTRAINT application_commands_applications_fk FOREIGN KEY (application_id) REFERENCES applications(id) ON DELETE CASCADE;`, + ); + await queryRunner.query(`ALTER TABLE application_commands ALTER COLUMN version TYPE ${to} USING version::${to}`); + await queryRunner.query(`ALTER TABLE automod_rules ALTER COLUMN guild_id TYPE ${to} USING guild_id::${to}`); + // missing relation + await queryRunner.query(`ALTER TABLE automod_rules ADD CONSTRAINT automod_rules_guilds_fk FOREIGN KEY (guild_id) REFERENCES guilds(id) ON DELETE CASCADE;`); + await queryRunner.query(`ALTER TABLE channels ALTER COLUMN last_message_id TYPE ${to} USING last_message_id::${to}`); + await queryRunner.query(`ALTER TABLE guilds ALTER COLUMN primary_category_id TYPE ${to} USING primary_category_id::${to}`); + // missing relation + await queryRunner.query(`ALTER TABLE guilds ADD CONSTRAINT guilds_categories_fk FOREIGN KEY (primary_category_id) REFERENCES categories(id) ON DELETE SET NULL;`); + await queryRunner.query(`ALTER TABLE instance_bans ALTER COLUMN user_id TYPE ${to} USING user_id::${to}`); + await queryRunner.query(`ALTER TABLE members ALTER COLUMN last_message_id TYPE ${to} USING last_message_id::${to}`); + // oops + await queryRunner.query(`UPDATE read_states SET last_message_id = NULL WHERE last_message_id = 'null' OR last_message_id = 'undefined';`); + await queryRunner.query(`ALTER TABLE read_states ALTER COLUMN last_message_id TYPE ${to} USING last_message_id::${to}`); + await queryRunner.query(`ALTER TABLE read_states ALTER COLUMN last_acked_id TYPE ${to} USING last_acked_id::${to}`); + await queryRunner.query(`ALTER TABLE security_settings ALTER COLUMN guild_id TYPE ${to} USING guild_id::${to}`); + await queryRunner.query(`ALTER TABLE security_settings ALTER COLUMN channel_id TYPE ${to} USING channel_id::${to}`); + await queryRunner.query(`ALTER TABLE tags ALTER COLUMN emoji_id TYPE ${to} USING emoji_id::${to}`); + } +}