diff --git a/packages/payment/src/migrations/.snapshot-medusa-payment.json b/packages/payment/src/migrations/.snapshot-medusa-payment.json index 9a30897f1a..4b2793cfca 100644 --- a/packages/payment/src/migrations/.snapshot-medusa-payment.json +++ b/packages/payment/src/migrations/.snapshot-medusa-payment.json @@ -717,6 +717,15 @@ "name": "capture", "schema": "public", "indexes": [ + { + "columnNames": [ + "payment_id" + ], + "composite": false, + "keyName": "IDX_capture_payment_id", + "primary": false, + "unique": false + }, { "keyName": "capture_pkey", "columnNames": [ @@ -797,6 +806,15 @@ "name": "refund", "schema": "public", "indexes": [ + { + "columnNames": [ + "payment_id" + ], + "composite": false, + "keyName": "IDX_refund_payment_id", + "primary": false, + "unique": false + }, { "keyName": "refund_pkey", "columnNames": [ diff --git a/packages/payment/src/migrations/Migration20240112104455.ts b/packages/payment/src/migrations/Migration20240112130209.ts similarity index 95% rename from packages/payment/src/migrations/Migration20240112104455.ts rename to packages/payment/src/migrations/Migration20240112130209.ts index 0f42c7fe69..54c4e1933a 100644 --- a/packages/payment/src/migrations/Migration20240112104455.ts +++ b/packages/payment/src/migrations/Migration20240112130209.ts @@ -1,6 +1,6 @@ import { Migration } from "@mikro-orm/migrations" -export class Migration20240112104455 extends Migration { +export class Migration20240112130209 extends Migration { async up(): Promise { this.addSql( 'create table if not exists "payment-collection" ("id" text not null, "currency_code" text null, "amount" numeric not null, "authorized_amount" numeric null, "refunded_amount" numeric null, "region_id" text null, "created_at" timestamptz not null default now(), "updated_at" timestamptz not null default now(), "deleted_at" timestamptz null, "completed_at" timestamptz null, "status" text check ("status" in (\'not_paid\', \'awaiting\', \'authorized\', \'partially_authorized\', \'canceled\')) not null default \'not_paid\', constraint "payment-collection_pkey" primary key ("id"));' @@ -38,10 +38,16 @@ export class Migration20240112104455 extends Migration { this.addSql( 'create table if not exists "capture" ("id" text not null, "amount" numeric not null, "payment_id" text not null, "created_at" timestamptz not null default now(), "created_by" text null, constraint "capture_pkey" primary key ("id"));' ) + this.addSql( + 'create index "IDX_capture_payment_id" on "capture" ("payment_id");' + ) this.addSql( 'create table if not exists "refund" ("id" text not null, "amount" numeric not null, "payment_id" text not null, "created_at" timestamptz not null default now(), "created_by" text null, constraint "refund_pkey" primary key ("id"));' ) + this.addSql( + 'create index "IDX_refund_payment_id" on "refund" ("payment_id");' + ) this.addSql( 'alter table "payment-collection_payment_providers" add constraint "payment-collection_payment_providers_payment_coll_6b015_foreign" foreign key ("payment_collection_id") references "payment-collection" ("id") on update cascade on delete cascade;' diff --git a/packages/payment/src/models/capture.ts b/packages/payment/src/models/capture.ts index 1c8b399744..8f6de9e116 100644 --- a/packages/payment/src/models/capture.ts +++ b/packages/payment/src/models/capture.ts @@ -27,6 +27,7 @@ export default class Capture { amount: number @ManyToOne(() => Payment, { + onDelete: "cascade", index: "IDX_capture_payment_id", fieldName: "payment_id", }) diff --git a/packages/payment/src/models/refund.ts b/packages/payment/src/models/refund.ts index 52528f25a9..6da06d2c16 100644 --- a/packages/payment/src/models/refund.ts +++ b/packages/payment/src/models/refund.ts @@ -27,6 +27,7 @@ export default class Refund { amount: number @ManyToOne(() => Payment, { + onDelete: "cascade", index: "IDX_refund_payment_id", fieldName: "payment_id", })