summary refs log tree commit diff
path: root/src/database/migration/postgres/1752321571508-RoleColors.ts
blob: 0a1cbc9bf7e5f9f4738d82af5ba6a4c6cd2b660c (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
import { MigrationInterface, QueryRunner } from "typeorm";

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

    public async up(queryRunner: QueryRunner): Promise<void> {
        await queryRunner.query(`ALTER TABLE "roles" ADD "colors" text`);
        await queryRunner.query(`UPDATE "roles" SET "colors" = jsonb_build_object('primary_color', "color") WHERE "colors" IS NULL`);
        await queryRunner.query(`ALTER TABLE "roles" ALTER COLUMN "colors" SET NOT NULL`);
    }

    public async down(queryRunner: QueryRunner): Promise<void> {
        await queryRunner.query(`ALTER TABLE "roles" DROP COLUMN "colors"`);
    }
}