Passed
Pull Request — master (#436)
by Mathieu
02:36
created

CreateNotificationTable1717147942177   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 23
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 2
eloc 13
dl 0
loc 23
rs 10
c 0
b 0
f 0

2 Functions

Rating   Name   Duplication   Size   Complexity  
A down 0 7 1
A up 0 10 1
1
import { MigrationInterface, QueryRunner } from 'typeorm';
2
3
export class CreateNotificationTable1717147942177
4
  implements MigrationInterface {
5
  name = 'CreateNotificationTable1717147942177';
6
7
  public async up(queryRunner: QueryRunner): Promise<void> {
8
    await queryRunner.query(
9
      `CREATE TYPE "public"."notification_type_enum" AS ENUM('post', 'comment', 'reaction')`
10
    );
11
    await queryRunner.query(
12
      `CREATE TABLE "notification" ("id" uuid NOT NULL DEFAULT uuid_generate_v4(), "type" "public"."notification_type_enum" NOT NULL, "resourceId" character varying NOT NULL, "message" character varying NOT NULL, "createdAt" TIMESTAMP NOT NULL DEFAULT now(), "leaveRequestId" uuid, CONSTRAINT "PK_705b6c7cdf9b2c2ff7ac7872cb7" PRIMARY KEY ("id"))`
13
    );
14
    await queryRunner.query(
15
      `ALTER TABLE "notification" ADD CONSTRAINT "FK_d7dcd7fa90cc4542719b880bc7f" FOREIGN KEY ("leaveRequestId") REFERENCES "leave_request"("id") ON DELETE SET NULL ON UPDATE NO ACTION`
16
    );
17
  }
18
19
  public async down(queryRunner: QueryRunner): Promise<void> {
20
    await queryRunner.query(
21
      `ALTER TABLE "notification" DROP CONSTRAINT "FK_d7dcd7fa90cc4542719b880bc7f"`
22
    );
23
    await queryRunner.query(`DROP TABLE "notification"`);
24
    await queryRunner.query(`DROP TYPE "public"."notification_type_enum"`);
25
  }
26
}
27