AnhLedger commited on
Commit
c68e5de
·
1 Parent(s): 12a1d2c

change role id to string and set default value

Browse files
backend/src/migrations/1729952137958-Change-role-id-string-default.ts ADDED
@@ -0,0 +1,20 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import { MigrationInterface, QueryRunner } from "typeorm";
2
+
3
+ export class ChangeRoleIdStringDefault1729952137958 implements MigrationInterface {
4
+ name = 'ChangeRoleIdStringDefault1729952137958'
5
+
6
+ public async up(queryRunner: QueryRunner): Promise<void> {
7
+ await queryRunner.query(`ALTER TABLE "users" DROP CONSTRAINT "FK_a2cecd1a3531c0b041e29ba46e1"`);
8
+ await queryRunner.query(`ALTER TABLE "users" ALTER COLUMN "role_id" SET NOT NULL`);
9
+ await queryRunner.query(`ALTER TABLE "users" ALTER COLUMN "role_id" SET DEFAULT 'f3750930-48ab-4c30-8681-d50e68e2bda7'`);
10
+ 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`);
11
+ }
12
+
13
+ public async down(queryRunner: QueryRunner): Promise<void> {
14
+ await queryRunner.query(`ALTER TABLE "users" DROP CONSTRAINT "FK_a2cecd1a3531c0b041e29ba46e1"`);
15
+ await queryRunner.query(`ALTER TABLE "users" ALTER COLUMN "role_id" DROP DEFAULT`);
16
+ await queryRunner.query(`ALTER TABLE "users" ALTER COLUMN "role_id" DROP NOT NULL`);
17
+ 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`);
18
+ }
19
+
20
+ }