From a7f74bdfb8a369168f7d3221a7ae2e2244ac8816 Mon Sep 17 00:00:00 2001 From: fPolic Date: Fri, 12 Jan 2024 14:10:56 +0100 Subject: [PATCH] fix: add missing indexes --- .../migrations/.snapshot-medusa-payment.json | 18 ++++++++++++++++++ ...112130209.ts => Migration20240112131027.ts} | 8 +++++++- packages/payment/src/models/payment-session.ts | 1 + packages/payment/src/models/payment.ts | 1 + 4 files changed, 27 insertions(+), 1 deletion(-) rename packages/payment/src/migrations/{Migration20240112130209.ts => Migration20240112131027.ts} (94%) diff --git a/packages/payment/src/migrations/.snapshot-medusa-payment.json b/packages/payment/src/migrations/.snapshot-medusa-payment.json index 4b2793cfca..2522b71b85 100644 --- a/packages/payment/src/migrations/.snapshot-medusa-payment.json +++ b/packages/payment/src/migrations/.snapshot-medusa-payment.json @@ -425,6 +425,15 @@ "name": "payment-session", "schema": "public", "indexes": [ + { + "columnNames": [ + "payment_collection_id" + ], + "composite": false, + "keyName": "IDX_payment_session_payment_collection_id", + "primary": false, + "unique": false + }, { "keyName": "payment-session_pkey", "columnNames": [ @@ -617,6 +626,15 @@ "primary": false, "unique": false }, + { + "columnNames": [ + "payment_collection_id" + ], + "composite": false, + "keyName": "IDX_payment_payment_collection_id", + "primary": false, + "unique": false + }, { "columnNames": [ "session_id" diff --git a/packages/payment/src/migrations/Migration20240112130209.ts b/packages/payment/src/migrations/Migration20240112131027.ts similarity index 94% rename from packages/payment/src/migrations/Migration20240112130209.ts rename to packages/payment/src/migrations/Migration20240112131027.ts index 54c4e1933a..cc588e5207 100644 --- a/packages/payment/src/migrations/Migration20240112130209.ts +++ b/packages/payment/src/migrations/Migration20240112131027.ts @@ -1,6 +1,6 @@ import { Migration } from "@mikro-orm/migrations" -export class Migration20240112130209 extends Migration { +export class Migration20240112131027 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"));' @@ -24,6 +24,9 @@ export class Migration20240112130209 extends Migration { this.addSql( 'create table if not exists "payment-session" ("id" text not null, "currency_code" text null, "amount" numeric not null, "provider_id" text not null, "data" jsonb null, "status" text check ("status" in (\'authorized\', \'pending\', \'requires_more\', \'error\', \'canceled\')) not null, "is_selected" boolean null, "authorised_at" timestamptz null, "payment_collection_id" text not null, constraint "payment-session_pkey" primary key ("id"));' ) + this.addSql( + 'create index "IDX_payment_session_payment_collection_id" on "payment-session" ("payment_collection_id");' + ) this.addSql( 'create table if not exists "payment" ("id" text not null, "amount" numeric not null, "authorized_amount" numeric null, "currency_code" text not null, "provider_id" text not null, "cart_id" text null, "order_id" text null, "customer_id" text null, "data" jsonb null, "created_at" timestamptz not null default now(), "updated_at" timestamptz not null default now(), "deleted_at" timestamptz null, "captured_at" timestamptz null, "canceled_at" timestamptz null, "payment_collection_id" text not null, "session_id" text not null, constraint "payment_pkey" primary key ("id"));' @@ -31,6 +34,9 @@ export class Migration20240112130209 extends Migration { this.addSql( 'create index "IDX_payment_deleted_at" on "payment" ("deleted_at");' ) + this.addSql( + 'create index "IDX_payment_payment_collection_id" on "payment" ("payment_collection_id");' + ) this.addSql( 'alter table "payment" add constraint "payment_session_id_unique" unique ("session_id");' ) diff --git a/packages/payment/src/models/payment-session.ts b/packages/payment/src/models/payment-session.ts index 3ad850a1c6..e86c02dc91 100644 --- a/packages/payment/src/models/payment-session.ts +++ b/packages/payment/src/models/payment-session.ts @@ -87,6 +87,7 @@ export default class PaymentSession { authorised_at: Date | null @ManyToOne({ + index: "IDX_payment_session_payment_collection_id", fieldName: "payment_collection_id", }) payment_collection!: PaymentCollection diff --git a/packages/payment/src/models/payment.ts b/packages/payment/src/models/payment.ts index 8fa2009378..05e3c64f22 100644 --- a/packages/payment/src/models/payment.ts +++ b/packages/payment/src/models/payment.ts @@ -113,6 +113,7 @@ export default class Payment { captures = new Collection(this) @ManyToOne({ + index: "IDX_payment_payment_collection_id", fieldName: "payment_collection_id", }) payment_collection!: PaymentCollection