Passed
Pull Request — master (#165)
by Mathieu
01:46
created

server/migrations/1606148950249-Invoice.ts   A

Complexity

Total Complexity 2
Complexity/F 1

Size

Lines of Code 27
Function Count 2

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 22
dl 0
loc 27
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 Invoice1606148950249.up 0 9 1
A Invoice1606148950249.down 0 9 1
1
import {MigrationInterface, QueryRunner} from "typeorm";
2
3
export class Invoice1606148950249 implements MigrationInterface {
4
    name = 'Invoice1606148950249'
5
6
    public async up(queryRunner: QueryRunner): Promise<void> {
7
        await queryRunner.query(`CREATE TABLE "invoice_item" ("id" uuid NOT NULL DEFAULT uuid_generate_v4(), "title" character varying NOT NULL, "quantity" integer NOT NULL, "amount" integer NOT NULL, "discount" integer DEFAULT 0, "invoiceId" uuid NOT NULL, CONSTRAINT "PK_621317346abdf61295516f3cb76" PRIMARY KEY ("id"))`);
8
        await queryRunner.query(`CREATE TYPE "invoice_status_enum" AS ENUM('draft', 'sent', 'payed', 'canceled')`);
9
        await queryRunner.query(`CREATE TABLE "invoice" ("id" uuid NOT NULL DEFAULT uuid_generate_v4(), "status" "invoice_status_enum" NOT NULL, "invoiceId" character varying NOT NULL, "createdAt" TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, "expiryDate" TIMESTAMP NOT NULL, "ownerId" uuid NOT NULL, "quoteId" uuid, "customerId" uuid NOT NULL, CONSTRAINT "UQ_c7e255ecd0c1a5ba5cb11e959ae" UNIQUE ("invoiceId"), CONSTRAINT "PK_15d25c200d9bcd8a33f698daf18" PRIMARY KEY ("id"))`);
10
        await queryRunner.query(`ALTER TABLE "invoice_item" ADD CONSTRAINT "FK_553d5aac210d22fdca5c8d48ead" FOREIGN KEY ("invoiceId") REFERENCES "invoice"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`);
11
        await queryRunner.query(`ALTER TABLE "invoice" ADD CONSTRAINT "FK_9909d4616f166cc7d6107553510" FOREIGN KEY ("ownerId") REFERENCES "user"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`);
12
        await queryRunner.query(`ALTER TABLE "invoice" ADD CONSTRAINT "FK_21b159910b14c6b2b5e944c969a" FOREIGN KEY ("quoteId") REFERENCES "quote"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`);
13
        await queryRunner.query(`ALTER TABLE "invoice" ADD CONSTRAINT "FK_925aa26ea12c28a6adb614445ee" FOREIGN KEY ("customerId") REFERENCES "customer"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`);
14
    }
15
16
    public async down(queryRunner: QueryRunner): Promise<void> {
17
        await queryRunner.query(`ALTER TABLE "invoice" DROP CONSTRAINT "FK_925aa26ea12c28a6adb614445ee"`);
18
        await queryRunner.query(`ALTER TABLE "invoice" DROP CONSTRAINT "FK_21b159910b14c6b2b5e944c969a"`);
19
        await queryRunner.query(`ALTER TABLE "invoice" DROP CONSTRAINT "FK_9909d4616f166cc7d6107553510"`);
20
        await queryRunner.query(`ALTER TABLE "invoice_item" DROP CONSTRAINT "FK_553d5aac210d22fdca5c8d48ead"`);
21
        await queryRunner.query(`DROP TABLE "invoice"`);
22
        await queryRunner.query(`DROP TYPE "invoice_status_enum"`);
23
        await queryRunner.query(`DROP TABLE "invoice_item"`);
24
    }
25
26
}
27