From fecf3085e82c8026a0b415a40b98b8e825ff1466 Mon Sep 17 00:00:00 2001 From: CyberL1 Date: Thu, 23 Oct 2025 09:11:44 +0200 Subject: [PATCH] fix: default `options`, `integration_types` and `contexts` to empty array --- src/util/entities/ApplicationCommand.ts | 6 ++--- ...pplication-commands-arrays-not-nullable.ts | 26 +++++++++++++++++++ 2 files changed, 29 insertions(+), 3 deletions(-) create mode 100644 src/util/migration/postgres/1761203098404-application-commands-arrays-not-nullable.ts diff --git a/src/util/entities/ApplicationCommand.ts b/src/util/entities/ApplicationCommand.ts index 8506d87b..7264555b 100644 --- a/src/util/entities/ApplicationCommand.ts +++ b/src/util/entities/ApplicationCommand.ts @@ -53,7 +53,7 @@ export class ApplicationCommand extends BaseClass { @Column({ nullable: true, type: "simple-json" }) description_localizations?: Record; - @Column({ nullable: true, type: "simple-json" }) + @Column({ type: "simple-json", default: [] }) options?: ApplicationCommandOption[]; @Column({ nullable: true, type: String }) @@ -71,13 +71,13 @@ export class ApplicationCommand extends BaseClass { @Column({ default: false }) nsfw?: boolean; - @Column({ nullable: true, type: "simple-json" }) + @Column({ type: "simple-json", default: [] }) integration_types?: ApplicationIntegrationType[]; @Column({ default: 0 }) global_popularity_rank?: number; - @Column({ nullable: true, type: "simple-json" }) + @Column({ type: "simple-json", default: [] }) contexts?: InteractionContextType[]; @Column({ default: 0 }) diff --git a/src/util/migration/postgres/1761203098404-application-commands-arrays-not-nullable.ts b/src/util/migration/postgres/1761203098404-application-commands-arrays-not-nullable.ts new file mode 100644 index 00000000..be8abd5a --- /dev/null +++ b/src/util/migration/postgres/1761203098404-application-commands-arrays-not-nullable.ts @@ -0,0 +1,26 @@ +import { MigrationInterface, QueryRunner } from "typeorm"; + +export class ApplicationCommandsArraysNotNullable1761203098404 implements MigrationInterface { + name = "ApplicationCommandsArraysNotNullable1761203098404"; + + public async up(queryRunner: QueryRunner): Promise { + await queryRunner.query(`UPDATE "application_commands" SET options = '[]' WHERE options IS NULL`); + await queryRunner.query(`UPDATE "application_commands" SET integration_types = '[]' WHERE integration_types IS NULL`); + await queryRunner.query(`UPDATE "application_commands" SET contexts = '[]' WHERE contexts IS NULL`); + await queryRunner.query(`ALTER TABLE "application_commands" ALTER COLUMN "options" SET NOT NULL`); + await queryRunner.query(`ALTER TABLE "application_commands" ALTER COLUMN "options" SET DEFAULT '[]'`); + await queryRunner.query(`ALTER TABLE "application_commands" ALTER COLUMN "integration_types" SET NOT NULL`); + await queryRunner.query(`ALTER TABLE "application_commands" ALTER COLUMN "integration_types" SET DEFAULT '[]'`); + await queryRunner.query(`ALTER TABLE "application_commands" ALTER COLUMN "contexts" SET NOT NULL`); + await queryRunner.query(`ALTER TABLE "application_commands" ALTER COLUMN "contexts" SET DEFAULT '[]'`); + } + + public async down(queryRunner: QueryRunner): Promise { + await queryRunner.query(`ALTER TABLE "application_commands" ALTER COLUMN "contexts" DROP DEFAULT`); + await queryRunner.query(`ALTER TABLE "application_commands" ALTER COLUMN "contexts" DROP NOT NULL`); + await queryRunner.query(`ALTER TABLE "application_commands" ALTER COLUMN "integration_types" DROP DEFAULT`); + await queryRunner.query(`ALTER TABLE "application_commands" ALTER COLUMN "integration_types" DROP NOT NULL`); + await queryRunner.query(`ALTER TABLE "application_commands" ALTER COLUMN "options" DROP DEFAULT`); + await queryRunner.query(`ALTER TABLE "application_commands" ALTER COLUMN "options" DROP NOT NULL`); + } +}