PBL6-informative-system / backend /src /migrations /1729952137958-Change-role-id-string-default.ts
AnhLedger's picture
change role id to string and set default value
c68e5de
raw
history blame
1.34 kB
import { MigrationInterface, QueryRunner } from "typeorm";
export class ChangeRoleIdStringDefault1729952137958 implements MigrationInterface {
name = 'ChangeRoleIdStringDefault1729952137958'
public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`ALTER TABLE "users" DROP CONSTRAINT "FK_a2cecd1a3531c0b041e29ba46e1"`);
await queryRunner.query(`ALTER TABLE "users" ALTER COLUMN "role_id" SET NOT NULL`);
await queryRunner.query(`ALTER TABLE "users" ALTER COLUMN "role_id" SET DEFAULT 'f3750930-48ab-4c30-8681-d50e68e2bda7'`);
await queryRunner.query(`ALTER TABLE "users" ADD CONSTRAINT "FK_a2cecd1a3531c0b041e29ba46e1" FOREIGN KEY ("role_id") REFERENCES "role"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`);
}
public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`ALTER TABLE "users" DROP CONSTRAINT "FK_a2cecd1a3531c0b041e29ba46e1"`);
await queryRunner.query(`ALTER TABLE "users" ALTER COLUMN "role_id" DROP DEFAULT`);
await queryRunner.query(`ALTER TABLE "users" ALTER COLUMN "role_id" DROP NOT NULL`);
await queryRunner.query(`ALTER TABLE "users" ADD CONSTRAINT "FK_a2cecd1a3531c0b041e29ba46e1" FOREIGN KEY ("role_id") REFERENCES "role"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`);
}
}