summary refs log tree commit diff
path: root/src/util/migration/postgres/1713116476900-messageFlagsNotNull.ts
blob: 57948bc3d094f46f036c0cc207639e479f799df6 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
import { MigrationInterface, QueryRunner } from "typeorm";

export class MessageFlagsNotNull1713116476900 implements MigrationInterface {
    name = "MessageFlagsNotNull1713116476900";

    public async up(queryRunner: QueryRunner): Promise<void> {
        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(queryRunner: QueryRunner): Promise<void> {
        await queryRunner.query("ALTER TABLE messages RENAME COLUMN flags TO flags_new;");
        await queryRunner.query("ALTER TABLE messages ADD COLUMN flags integer;");
        await queryRunner.query("UPDATE messages SET flags = flags_new;");
        await queryRunner.query("ALTER TABLE messages DROP COLUMN flags_new;");
    }
}