fix: giftcard-order relation

This commit is contained in:
Sebastian Rindom
2021-06-21 17:10:50 +02:00
parent 9555d8fe6e
commit c88c407096
2 changed files with 21 additions and 2 deletions
@@ -0,0 +1,20 @@
import {MigrationInterface, QueryRunner} from "typeorm";
export class gcRemoveUniqueOrder1624287602631 implements MigrationInterface {
name = 'gcRemoveUniqueOrder1624287602631'
public async up(queryRunner: QueryRunner): Promise<void> {
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<void> {
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`);
}
}
+1 -2
View File
@@ -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