Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(order): align mikroorm <> order module #8710

Merged
merged 3 commits into from
Aug 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2,875 changes: 2,524 additions & 351 deletions packages/modules/order/src/migrations/.snapshot-medusa-order.json

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import { Migration } from "@mikro-orm/migrations"

export class Migration20240821164505 extends Migration {
async up(): Promise<void> {
this.addSql(
'CREATE INDEX IF NOT EXISTS "IDX_order_item_deleted_at" ON "order_item" (deleted_at) WHERE deleted_at IS NOT NULL;'
)

this.addSql(
'CREATE INDEX IF NOT EXISTS "IDX_order_summary_deleted_at" ON "order_summary" (deleted_at) WHERE deleted_at IS NOT NULL;'
)

this.addSql(
'CREATE INDEX IF NOT EXISTS "IDX_order_claim_item_deleted_at" ON "order_claim_item" (deleted_at) WHERE deleted_at IS NOT NULL;'
)

this.addSql(
'CREATE INDEX IF NOT EXISTS "IDX_return_item_deleted_at" ON "return_item" (deleted_at) WHERE deleted_at IS NOT NULL;'
)

this.addSql(
'CREATE INDEX IF NOT EXISTS "IDX_order_shipping_deleted_at" ON "order_shipping" (deleted_at) WHERE deleted_at IS NOT NULL;'
)

this.addSql(
'CREATE INDEX IF NOT EXISTS "IDX_order_transaction_exchange_id" ON "order_transaction" (exchange_id) WHERE exchange_id IS NOT NULL AND deleted_at IS NOT NULL;'
)

this.addSql(
'CREATE INDEX IF NOT EXISTS "IDX_order_transaction_claim_id" ON "order_transaction" (claim_id) WHERE claim_id IS NOT NULL AND deleted_at IS NOT NULL;'
)
}

async down(): Promise<void> {
this.addSql('drop index if exists "IDX_order_item_deleted_at";')
this.addSql('drop index if exists "IDX_order_summary_deleted_at";')
this.addSql('drop index if exists "IDX_order_claim_item_deleted_at";')
this.addSql('drop index if exists "IDX_return_item_deleted_at";')
this.addSql('drop index if exists "IDX_order_shipping_deleted_at";')
this.addSql('drop index if exists "IDX_order_transaction_exchange_id";')
this.addSql('drop index if exists "IDX_order_transaction_claim_id";')
}
}
9 changes: 5 additions & 4 deletions packages/modules/order/src/models/claim-item.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,25 +25,26 @@ import LineItem from "./line-item"

type OptionalLineItemProps = DAL.ModelDateColumns

const tableName = "order_claim_item"
const ClaimIdIndex = createPsqlIndexStatementHelper({
tableName: "order_claim_item",
tableName,
columns: "claim_id",
where: "deleted_at IS NOT NULL",
})

const ItemIdIndex = createPsqlIndexStatementHelper({
tableName: "order_claim_item",
tableName,
columns: "item_id",
where: "deleted_at IS NOT NULL",
})

const DeletedAtIndex = createPsqlIndexStatementHelper({
tableName: "order_claim_item_image",
tableName,
columns: "deleted_at",
where: "deleted_at IS NOT NULL",
})

@Entity({ tableName: "order_claim_item" })
@Entity({ tableName })
export default class OrderClaimItem {
[OptionalProps]?: OptionalLineItemProps

Expand Down
11 changes: 6 additions & 5 deletions packages/modules/order/src/models/order-item.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,31 +20,32 @@ import Order from "./order"

type OptionalLineItemProps = DAL.ModelDateColumns

const tableName = "order_item"
const OrderIdIndex = createPsqlIndexStatementHelper({
tableName: "order_item",
tableName,
columns: ["order_id"],
where: "deleted_at IS NOT NULL",
})

const OrderVersionIndex = createPsqlIndexStatementHelper({
tableName: "order_item",
tableName,
columns: ["version"],
where: "deleted_at IS NOT NULL",
})

const ItemIdIndex = createPsqlIndexStatementHelper({
tableName: "order_item",
tableName,
columns: ["item_id"],
where: "deleted_at IS NOT NULL",
})

const DeletedAtIndex = createPsqlIndexStatementHelper({
tableName: "order",
tableName,
columns: "deleted_at",
where: "deleted_at IS NOT NULL",
})

@Entity({ tableName: "order_item" })
@Entity({ tableName })
export default class OrderItem {
[OptionalProps]?: OptionalLineItemProps

Expand Down
17 changes: 9 additions & 8 deletions packages/modules/order/src/models/order-shipping-method.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,49 +21,50 @@ import ShippingMethod from "./shipping-method"

type OptionalShippingMethodProps = DAL.ModelDateColumns

const tableName = "order_shipping"
const OrderIdIndex = createPsqlIndexStatementHelper({
tableName: "order_shipping",
tableName,
columns: ["order_id"],
where: "deleted_at IS NOT NULL",
})

const ReturnIdIndex = createPsqlIndexStatementHelper({
tableName: "order_shipping",
tableName,
columns: "return_id",
where: "return_id IS NOT NULL AND deleted_at IS NOT NULL",
})

const ExchangeIdIndex = createPsqlIndexStatementHelper({
tableName: "order_shipping",
tableName,
columns: ["exchange_id"],
where: "exchange_id IS NOT NULL AND deleted_at IS NOT NULL",
})

const ClaimIdIndex = createPsqlIndexStatementHelper({
tableName: "order_shipping",
tableName,
columns: ["claim_id"],
where: "claim_id IS NOT NULL AND deleted_at IS NOT NULL",
})

const OrderVersionIndex = createPsqlIndexStatementHelper({
tableName: "order_shipping",
tableName,
columns: ["version"],
where: "deleted_at IS NOT NULL",
})

const ItemIdIndex = createPsqlIndexStatementHelper({
tableName: "order_shipping",
tableName,
columns: ["shipping_method_id"],
where: "deleted_at IS NOT NULL",
})

const DeletedAtIndex = createPsqlIndexStatementHelper({
tableName: "order",
tableName,
columns: "deleted_at",
where: "deleted_at IS NOT NULL",
})

@Entity({ tableName: "order_shipping" })
@Entity({ tableName })
export default class OrderShippingMethod {
[OptionalProps]?: OptionalShippingMethodProps

Expand Down
8 changes: 5 additions & 3 deletions packages/modules/order/src/models/order-summary.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,19 +36,21 @@ type OrderSummaryTotals = {
refunded_total: BigNumber
}

const tableName = "order_summary"

const OrderIdVersionIndex = createPsqlIndexStatementHelper({
tableName: "order_summary",
tableName,
columns: ["order_id", "version"],
where: "deleted_at IS NOT NULL",
})

const DeletedAtIndex = createPsqlIndexStatementHelper({
tableName: "order",
tableName,
columns: "deleted_at",
where: "deleted_at IS NOT NULL",
})

@Entity({ tableName: "order_summary" })
@Entity({ tableName })
@OrderIdVersionIndex.MikroORMIndex()
export default class OrderSummary {
@PrimaryKey({ columnType: "text" })
Expand Down
11 changes: 6 additions & 5 deletions packages/modules/order/src/models/return-item.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,31 +19,32 @@ import ReturnReason from "./return-reason"

type OptionalLineItemProps = DAL.ModelDateColumns

const tableName = "return_item"
const ReturnIdIndex = createPsqlIndexStatementHelper({
tableName: "return_item",
tableName,
columns: "return_id",
where: "deleted_at IS NOT NULL",
})

const ReturnReasonIdIndex = createPsqlIndexStatementHelper({
tableName: "return_item",
tableName,
columns: "reason_id",
where: "deleted_at IS NOT NULL",
})

const ItemIdIndex = createPsqlIndexStatementHelper({
tableName: "return_item",
tableName,
columns: "item_id",
where: "deleted_at IS NOT NULL",
})

const DeletedAtIndex = createPsqlIndexStatementHelper({
tableName: "order_claim_item_image",
tableName,
columns: "deleted_at",
where: "deleted_at IS NOT NULL",
})

@Entity({ tableName: "return_item" })
@Entity({ tableName })
export default class ReturnItem {
[OptionalProps]?: OptionalLineItemProps

Expand Down
20 changes: 11 additions & 9 deletions packages/modules/order/src/models/transaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,55 +24,57 @@ import Return from "./return"

type OptionalLineItemProps = DAL.ModelDateColumns

const tableName = "order_transaction"

const ReferenceIdIndex = createPsqlIndexStatementHelper({
tableName: "order_transaction",
tableName,
columns: "reference_id",
where: "deleted_at IS NOT NULL",
})

const OrderIdIndex = createPsqlIndexStatementHelper({
tableName: "order_transaction",
tableName,
columns: "order_id",
where: "deleted_at IS NOT NULL",
})

const ReturnIdIndex = createPsqlIndexStatementHelper({
tableName: "order_transaction",
tableName,
columns: "return_id",
where: "return_id IS NOT NULL AND deleted_at IS NOT NULL",
})

const ExchangeIdIndex = createPsqlIndexStatementHelper({
tableName: "order_item",
tableName,
columns: ["exchange_id"],
where: "exchange_id IS NOT NULL AND deleted_at IS NOT NULL",
})

const ClaimIdIndex = createPsqlIndexStatementHelper({
tableName: "order_item",
tableName,
columns: ["claim_id"],
where: "claim_id IS NOT NULL AND deleted_at IS NOT NULL",
})

const CurrencyCodeIndex = createPsqlIndexStatementHelper({
tableName: "order_transaction",
tableName,
columns: "currency_code",
where: "deleted_at IS NOT NULL",
})

const DeletedAtIndex = createPsqlIndexStatementHelper({
tableName: "order_transaction",
tableName,
columns: "deleted_at",
where: "deleted_at IS NOT NULL",
})

const OrderIdVersionIndex = createPsqlIndexStatementHelper({
tableName: "order_transaction",
tableName,
columns: ["order_id", "version"],
where: "deleted_at IS NOT NULL",
})

@Entity({ tableName: "order_transaction" })
@Entity({ tableName })
@Filter(DALUtils.mikroOrmSoftDeletableFilterOptions)
@OrderIdVersionIndex.MikroORMIndex()
export default class Transaction {
Expand Down
Loading