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

server/migrations/1586800890370-Address.ts   A

Complexity

Total Complexity 2
Complexity/F 1

Size

Lines of Code 19
Function Count 2

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

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

2 Functions

Rating   Name   Duplication   Size   Complexity  
A Address1586800890370.up 0 5 1
A Address1586800890370.down 0 5 1
1
import {MigrationInterface, QueryRunner} from "typeorm";
2
3
export class Address1586800890370 implements MigrationInterface {
4
    name = 'Address1586800890370'
5
6
    public async up(queryRunner: QueryRunner): Promise<any> {
7
        await queryRunner.query(`CREATE TABLE "address" ("id" uuid NOT NULL DEFAULT uuid_generate_v4(), "street" character varying NOT NULL, "city" character varying NOT NULL, "zipCode" character varying(6) NOT NULL, "country" character varying(2) NOT NULL, CONSTRAINT "PK_d92de1f82754668b5f5f5dd4fd5" PRIMARY KEY ("id"))`, undefined);
8
        await queryRunner.query(`ALTER TABLE "customer" ADD "addressId" uuid NOT NULL`, undefined);
9
        await queryRunner.query(`ALTER TABLE "customer" ADD CONSTRAINT "FK_7697a356e1f4b79ab3819839e95" FOREIGN KEY ("addressId") REFERENCES "address"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`, undefined);
10
    }
11
12
    public async down(queryRunner: QueryRunner): Promise<any> {
13
        await queryRunner.query(`ALTER TABLE "customer" DROP CONSTRAINT "FK_7697a356e1f4b79ab3819839e95"`, undefined);
14
        await queryRunner.query(`ALTER TABLE "customer" DROP COLUMN "addressId"`, undefined);
15
        await queryRunner.query(`DROP TABLE "address"`, undefined);
16
    }
17
18
}
19