fix(medusa): remove unique cart on payments to allow canceled payments to exist (#1854)
Fixes CORE-321 Co-authored-by: Adrien de Peretti <25098370+adrien2p@users.noreply.github.com> Co-authored-by: Oliver Windall Juhl <59018053+olivermrbl@users.noreply.github.com>
This commit is contained in:
4 files changed
+193
-6
No files matched your search
@@ -0,0 +1,25 @@
|
||||
import { MigrationInterface, QueryRunner } from "typeorm"
|
||||
|
||||
export class multiPaymentCart1661345741249 implements MigrationInterface {
|
||||
name = "multiPaymentCart1661345741249"
|
||||
|
||||
public async up(queryRunner: QueryRunner): Promise<void> {
|
||||
await queryRunner.query(
|
||||
`ALTER TABLE "payment" DROP CONSTRAINT "REL_4665f17abc1e81dd58330e5854"`
|
||||
)
|
||||
await queryRunner.query(
|
||||
`CREATE UNIQUE INDEX "UniquePaymentActive" ON "payment" ("cart_id") WHERE canceled_at IS NULL`
|
||||
)
|
||||
await queryRunner.query(
|
||||
`CREATE INDEX "IDX_aac4855eadda71aa1e4b6d7684" ON "payment" ("cart_id") WHERE canceled_at IS NOT NULL`
|
||||
)
|
||||
}
|
||||
|
||||
public async down(queryRunner: QueryRunner): Promise<void> {
|
||||
await queryRunner.query(`DROP INDEX "IDX_aac4855eadda71aa1e4b6d7684"`)
|
||||
await queryRunner.query(`DROP INDEX "UniquePaymentActive"`)
|
||||
await queryRunner.query(
|
||||
`ALTER TABLE "payment" ADD CONSTRAINT "REL_4665f17abc1e81dd58330e5854" UNIQUE ("cart_id")`
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -16,6 +16,8 @@ import { Order } from "./order"
|
||||
import { Swap } from "./swap"
|
||||
import { generateEntityId } from "../utils/generate-entity-id"
|
||||
|
||||
@Index(["cart_id"], { where: "canceled_at IS NOT NULL" })
|
||||
@Index("UniquePaymentActive", ["cart_id"], { where: "canceled_at IS NULL", unique: true, })
|
||||
@Entity()
|
||||
export class Payment extends BaseEntity {
|
||||
@Index()
|
||||
@@ -30,7 +32,7 @@ export class Payment extends BaseEntity {
|
||||
@Column({ nullable: true })
|
||||
cart_id: string
|
||||
|
||||
@OneToOne(() => Cart)
|
||||
@ManyToOne(() => Cart)
|
||||
@JoinColumn({ name: "cart_id" })
|
||||
cart: Cart
|
||||
|
||||
@@ -38,7 +40,10 @@ export class Payment extends BaseEntity {
|
||||
@Column({ nullable: true })
|
||||
order_id: string
|
||||
|
||||
@ManyToOne(() => Order, (order) => order.payments)
|
||||
@ManyToOne(
|
||||
() => Order,
|
||||
(order) => order.payments
|
||||
)
|
||||
@JoinColumn({ name: "order_id" })
|
||||
order: Order
|
||||
|
||||
|
||||
Reference in new issue
Block a user