From ee59ee7e1cf4c5b9ae749745471a1f98053c3c58 Mon Sep 17 00:00:00 2001 From: Puyodead1 Date: Sun, 14 Apr 2024 14:02:22 -0400 Subject: Fix message flags being null --- .../postgres/1713116476900-messageFlagsNotNull.ts | 23 ++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 src/util/migration/postgres/1713116476900-messageFlagsNotNull.ts (limited to 'src/util/migration/postgres') diff --git a/src/util/migration/postgres/1713116476900-messageFlagsNotNull.ts b/src/util/migration/postgres/1713116476900-messageFlagsNotNull.ts new file mode 100644 index 00000000..026b069b --- /dev/null +++ b/src/util/migration/postgres/1713116476900-messageFlagsNotNull.ts @@ -0,0 +1,23 @@ +import { MigrationInterface, QueryRunner } from "typeorm"; + +export class MessageFlagsNotNull1713116476900 implements MigrationInterface { + name = "MessageFlagsNotNull1713116476900"; + + public async up(queryRunner: QueryRunner): Promise { + await queryRunner.query( + "ALTER TABLE messages RENAME COLUMN flags TO flags_old;", + ); + await queryRunner.query( + "ALTER TABLE messages ADD COLUMN flags integer NOT NULL DEFAULT 0;", + ); + await queryRunner.query( + "UPDATE messages SET flags = COALESCE(flags_old, 0);", + ); + await queryRunner.query("ALTER TABLE messages DROP COLUMN flags_old;"); + } + + public async down(): Promise { + // dont care + throw new Error("Migration down is not implemented."); + } +} -- cgit 1.5.1