Passed
Push — master ( 16eb79...13846a )
by
unknown
04:07
created

server/migrations/1699290758562-dropAddress.ts   A

Complexity

Total Complexity 2
Complexity/F 1

Size

Lines of Code 22
Function Count 2

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

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

2 Functions

Rating   Name   Duplication   Size   Complexity  
A DropAddress1699290758562.down 0 7 1
A DropAddress1699290758562.up 0 7 1
1
import { MigrationInterface, QueryRunner } from "typeorm";
2
3
export class DropAddress1699290758562 implements MigrationInterface {
4
    name = 'DropAddress1699290758562'
5
6
    public async up(queryRunner: QueryRunner): Promise<void> {
7
        await queryRunner.query(`ALTER TABLE "customer" DROP CONSTRAINT "FK_7697a356e1f4b79ab3819839e95"`);
8
        await queryRunner.query(`ALTER TABLE "cooperative" DROP CONSTRAINT "FK_76076f95b4afaa794ca4a974661"`);
9
        await queryRunner.query(`ALTER TABLE "customer" DROP COLUMN "addressId"`);
10
        await queryRunner.query(`ALTER TABLE "cooperative" DROP COLUMN "addressId"`);
11
        await queryRunner.query(`DROP TABLE "address"`);
12
    }
13
14
    public async down(queryRunner: QueryRunner): Promise<void> {
15
        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"))`);
16
        await queryRunner.query(`ALTER TABLE "cooperative" ADD "addressId" uuid NOT NULL`);
17
        await queryRunner.query(`ALTER TABLE "customer" ADD "addressId" uuid`);
18
        await queryRunner.query(`ALTER TABLE "cooperative" ADD CONSTRAINT "FK_76076f95b4afaa794ca4a974661" FOREIGN KEY ("addressId") REFERENCES "address"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`);
19
        await queryRunner.query(`ALTER TABLE "customer" ADD CONSTRAINT "FK_7697a356e1f4b79ab3819839e95" FOREIGN KEY ("addressId") REFERENCES "address"("id") ON DELETE SET NULL ON UPDATE NO ACTION`);
20
    }
21
}
22