From c88c4070960ad1a8126e65b1e9f60d7ba929246a Mon Sep 17 00:00:00 2001 From: Sebastian Rindom Date: Mon, 21 Jun 2021 17:10:50 +0200 Subject: [PATCH 1/2] fix: giftcard-order relation --- .../1624287602631-gc_remove_unique_order.ts | 20 +++++++++++++++++++ packages/medusa/src/models/gift-card.ts | 3 +-- 2 files changed, 21 insertions(+), 2 deletions(-) create mode 100644 packages/medusa/src/migrations/1624287602631-gc_remove_unique_order.ts diff --git a/packages/medusa/src/migrations/1624287602631-gc_remove_unique_order.ts b/packages/medusa/src/migrations/1624287602631-gc_remove_unique_order.ts new file mode 100644 index 0000000000..4b335bb7c6 --- /dev/null +++ b/packages/medusa/src/migrations/1624287602631-gc_remove_unique_order.ts @@ -0,0 +1,20 @@ +import {MigrationInterface, QueryRunner} from "typeorm"; + +export class gcRemoveUniqueOrder1624287602631 implements MigrationInterface { + name = 'gcRemoveUniqueOrder1624287602631' + + public async up(queryRunner: QueryRunner): Promise { + await queryRunner.query(`ALTER TABLE "gift_card" DROP CONSTRAINT "FK_dfc1f02bb0552e79076aa58dbb0"`); + await queryRunner.query(`COMMENT ON COLUMN "gift_card"."order_id" IS NULL`); + await queryRunner.query(`ALTER TABLE "gift_card" DROP CONSTRAINT "REL_dfc1f02bb0552e79076aa58dbb"`); + await queryRunner.query(`ALTER TABLE "gift_card" ADD CONSTRAINT "FK_dfc1f02bb0552e79076aa58dbb0" FOREIGN KEY ("order_id") REFERENCES "order"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`); + } + + public async down(queryRunner: QueryRunner): Promise { + await queryRunner.query(`ALTER TABLE "gift_card" DROP CONSTRAINT "FK_dfc1f02bb0552e79076aa58dbb0"`); + await queryRunner.query(`ALTER TABLE "gift_card" ADD CONSTRAINT "REL_dfc1f02bb0552e79076aa58dbb" UNIQUE ("order_id")`); + await queryRunner.query(`COMMENT ON COLUMN "gift_card"."order_id" IS NULL`); + await queryRunner.query(`ALTER TABLE "gift_card" ADD CONSTRAINT "FK_dfc1f02bb0552e79076aa58dbb0" FOREIGN KEY ("order_id") REFERENCES "order"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`); + } + +} diff --git a/packages/medusa/src/models/gift-card.ts b/packages/medusa/src/models/gift-card.ts index 2fff7d4199..8b763b2dcc 100644 --- a/packages/medusa/src/models/gift-card.ts +++ b/packages/medusa/src/models/gift-card.ts @@ -8,7 +8,6 @@ import { Column, PrimaryColumn, ManyToOne, - OneToOne, JoinColumn, } from "typeorm" import { ulid } from "ulid" @@ -43,7 +42,7 @@ export class GiftCard { @Column({ nullable: true }) order_id: string - @OneToOne(() => Order) + @ManyToOne(() => Order) @JoinColumn({ name: "order_id" }) order: Order From 58295505178209d511046089d736395d121b9732 Mon Sep 17 00:00:00 2001 From: Sebastian Rindom Date: Mon, 21 Jun 2021 17:13:42 +0200 Subject: [PATCH 2/2] fix: lint --- .../1624287602631-gc_remove_unique_order.ts | 41 ++++++++++++------- 1 file changed, 26 insertions(+), 15 deletions(-) diff --git a/packages/medusa/src/migrations/1624287602631-gc_remove_unique_order.ts b/packages/medusa/src/migrations/1624287602631-gc_remove_unique_order.ts index 4b335bb7c6..21a0ae3a6c 100644 --- a/packages/medusa/src/migrations/1624287602631-gc_remove_unique_order.ts +++ b/packages/medusa/src/migrations/1624287602631-gc_remove_unique_order.ts @@ -1,20 +1,31 @@ -import {MigrationInterface, QueryRunner} from "typeorm"; +import { MigrationInterface, QueryRunner } from "typeorm" export class gcRemoveUniqueOrder1624287602631 implements MigrationInterface { - name = 'gcRemoveUniqueOrder1624287602631' + name = "gcRemoveUniqueOrder1624287602631" - public async up(queryRunner: QueryRunner): Promise { - await queryRunner.query(`ALTER TABLE "gift_card" DROP CONSTRAINT "FK_dfc1f02bb0552e79076aa58dbb0"`); - await queryRunner.query(`COMMENT ON COLUMN "gift_card"."order_id" IS NULL`); - await queryRunner.query(`ALTER TABLE "gift_card" DROP CONSTRAINT "REL_dfc1f02bb0552e79076aa58dbb"`); - await queryRunner.query(`ALTER TABLE "gift_card" ADD CONSTRAINT "FK_dfc1f02bb0552e79076aa58dbb0" FOREIGN KEY ("order_id") REFERENCES "order"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`); - } - - public async down(queryRunner: QueryRunner): Promise { - await queryRunner.query(`ALTER TABLE "gift_card" DROP CONSTRAINT "FK_dfc1f02bb0552e79076aa58dbb0"`); - await queryRunner.query(`ALTER TABLE "gift_card" ADD CONSTRAINT "REL_dfc1f02bb0552e79076aa58dbb" UNIQUE ("order_id")`); - await queryRunner.query(`COMMENT ON COLUMN "gift_card"."order_id" IS NULL`); - await queryRunner.query(`ALTER TABLE "gift_card" ADD CONSTRAINT "FK_dfc1f02bb0552e79076aa58dbb0" FOREIGN KEY ("order_id") REFERENCES "order"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`); - } + public async up(queryRunner: QueryRunner): Promise { + await queryRunner.query( + `ALTER TABLE "gift_card" DROP CONSTRAINT "FK_dfc1f02bb0552e79076aa58dbb0"` + ) + await queryRunner.query(`COMMENT ON COLUMN "gift_card"."order_id" IS NULL`) + await queryRunner.query( + `ALTER TABLE "gift_card" DROP CONSTRAINT "REL_dfc1f02bb0552e79076aa58dbb"` + ) + await queryRunner.query( + `ALTER TABLE "gift_card" ADD CONSTRAINT "FK_dfc1f02bb0552e79076aa58dbb0" FOREIGN KEY ("order_id") REFERENCES "order"("id") ON DELETE NO ACTION ON UPDATE NO ACTION` + ) + } + public async down(queryRunner: QueryRunner): Promise { + await queryRunner.query( + `ALTER TABLE "gift_card" DROP CONSTRAINT "FK_dfc1f02bb0552e79076aa58dbb0"` + ) + await queryRunner.query( + `ALTER TABLE "gift_card" ADD CONSTRAINT "REL_dfc1f02bb0552e79076aa58dbb" UNIQUE ("order_id")` + ) + await queryRunner.query(`COMMENT ON COLUMN "gift_card"."order_id" IS NULL`) + await queryRunner.query( + `ALTER TABLE "gift_card" ADD CONSTRAINT "FK_dfc1f02bb0552e79076aa58dbb0" FOREIGN KEY ("order_id") REFERENCES "order"("id") ON DELETE NO ACTION ON UPDATE NO ACTION` + ) + } }