Passed
Pull Request — master (#146)
by Mathieu
02:09
created

server/migrations/1587124202585-FairCalendarEvent.ts   A

Complexity

Total Complexity 2
Complexity/F 1

Size

Lines of Code 23
Function Count 2

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
wmc 2
eloc 18
mnd 0
bc 0
fnc 2
dl 0
loc 23
rs 10
bpm 0
cpm 1
noi 0
c 0
b 0
f 0

2 Functions

Rating   Name   Duplication   Size   Complexity  
A FairCalendarEvent1587124202585.up 0 7 1
A FairCalendarEvent1587124202585.down 0 7 1
1
import {MigrationInterface, QueryRunner} from "typeorm";
2
3
export class FairCalendarEvent1587124202585 implements MigrationInterface {
4
    name = 'FairCalendarEvent1587124202585'
5
6
    public async up(queryRunner: QueryRunner): Promise<any> {
7
        await queryRunner.query(`CREATE TYPE "event_type_enum" AS ENUM('mission', 'support', 'dojo', 'holiday', 'formationConference', 'medicalLeave', 'other')`, undefined);
8
        await queryRunner.query(`CREATE TABLE "event" ("id" uuid NOT NULL DEFAULT uuid_generate_v4(), "type" "event_type_enum" NOT NULL, "time" integer NOT NULL, "date" date NOT NULL, "summary" character varying, "projectId" uuid, "taskId" uuid, "userId" uuid NOT NULL, CONSTRAINT "PK_30c2f3bbaf6d34a55f8ae6e4614" PRIMARY KEY ("id"))`, undefined);
9
        await queryRunner.query(`ALTER TABLE "event" ADD CONSTRAINT "FK_3dde39f7b276bbc735a0f762ead" FOREIGN KEY ("projectId") REFERENCES "project"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`, undefined);
10
        await queryRunner.query(`ALTER TABLE "event" ADD CONSTRAINT "FK_56b239fecbe385af3a3186acab0" FOREIGN KEY ("taskId") REFERENCES "task"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`, undefined);
11
        await queryRunner.query(`ALTER TABLE "event" ADD CONSTRAINT "FK_01cd2b829e0263917bf570cb672" FOREIGN KEY ("userId") REFERENCES "user"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`, undefined);
12
    }
13
14
    public async down(queryRunner: QueryRunner): Promise<any> {
15
        await queryRunner.query(`ALTER TABLE "event" DROP CONSTRAINT "FK_01cd2b829e0263917bf570cb672"`, undefined);
16
        await queryRunner.query(`ALTER TABLE "event" DROP CONSTRAINT "FK_56b239fecbe385af3a3186acab0"`, undefined);
17
        await queryRunner.query(`ALTER TABLE "event" DROP CONSTRAINT "FK_3dde39f7b276bbc735a0f762ead"`, undefined);
18
        await queryRunner.query(`DROP TABLE "event"`, undefined);
19
        await queryRunner.query(`DROP TYPE "event_type_enum"`, undefined);
20
    }
21
22
}
23