Skip to content

Commit

Permalink
chore(order): align mikroorm <> order module (#8710)
Browse files Browse the repository at this point in the history
what:

- aligns the order module migrations with mikroorm snapshot
  • Loading branch information
riqwan authored Aug 21, 2024
1 parent 2437705 commit 01583ba
Show file tree
Hide file tree
Showing 8 changed files with 2,609 additions and 385 deletions.
2,875 changes: 2,524 additions & 351 deletions packages/modules/order/src/migrations/.snapshot-medusa-order.json

Large diffs are not rendered by default.

43 changes: 43 additions & 0 deletions packages/modules/order/src/migrations/Migration20240821164505.ts
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

0 comments on commit 01583ba

Please sign in to comment.