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

what:

- aligns the order module migrations with mikroorm snapshot
This commit is contained in:
Riqwan Thamir
2024-08-21 17:37:17 +00:00
committed by GitHub
parent 24377053f0
commit 01583baf6d
8 changed files with 2469 additions and 245 deletions
File diff suppressed because it is too large Load Diff
@@ -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";')
}
}
@@ -25,25 +25,26 @@ import LineItem from "./line-item"
type OptionalLineItemProps = DAL.ModelDateColumns type OptionalLineItemProps = DAL.ModelDateColumns
const tableName = "order_claim_item"
const ClaimIdIndex = createPsqlIndexStatementHelper({ const ClaimIdIndex = createPsqlIndexStatementHelper({
tableName: "order_claim_item", tableName,
columns: "claim_id", columns: "claim_id",
where: "deleted_at IS NOT NULL", where: "deleted_at IS NOT NULL",
}) })
const ItemIdIndex = createPsqlIndexStatementHelper({ const ItemIdIndex = createPsqlIndexStatementHelper({
tableName: "order_claim_item", tableName,
columns: "item_id", columns: "item_id",
where: "deleted_at IS NOT NULL", where: "deleted_at IS NOT NULL",
}) })
const DeletedAtIndex = createPsqlIndexStatementHelper({ const DeletedAtIndex = createPsqlIndexStatementHelper({
tableName: "order_claim_item_image", tableName,
columns: "deleted_at", columns: "deleted_at",
where: "deleted_at IS NOT NULL", where: "deleted_at IS NOT NULL",
}) })
@Entity({ tableName: "order_claim_item" }) @Entity({ tableName })
export default class OrderClaimItem { export default class OrderClaimItem {
[OptionalProps]?: OptionalLineItemProps [OptionalProps]?: OptionalLineItemProps
@@ -20,31 +20,32 @@ import Order from "./order"
type OptionalLineItemProps = DAL.ModelDateColumns type OptionalLineItemProps = DAL.ModelDateColumns
const tableName = "order_item"
const OrderIdIndex = createPsqlIndexStatementHelper({ const OrderIdIndex = createPsqlIndexStatementHelper({
tableName: "order_item", tableName,
columns: ["order_id"], columns: ["order_id"],
where: "deleted_at IS NOT NULL", where: "deleted_at IS NOT NULL",
}) })
const OrderVersionIndex = createPsqlIndexStatementHelper({ const OrderVersionIndex = createPsqlIndexStatementHelper({
tableName: "order_item", tableName,
columns: ["version"], columns: ["version"],
where: "deleted_at IS NOT NULL", where: "deleted_at IS NOT NULL",
}) })
const ItemIdIndex = createPsqlIndexStatementHelper({ const ItemIdIndex = createPsqlIndexStatementHelper({
tableName: "order_item", tableName,
columns: ["item_id"], columns: ["item_id"],
where: "deleted_at IS NOT NULL", where: "deleted_at IS NOT NULL",
}) })
const DeletedAtIndex = createPsqlIndexStatementHelper({ const DeletedAtIndex = createPsqlIndexStatementHelper({
tableName: "order", tableName,
columns: "deleted_at", columns: "deleted_at",
where: "deleted_at IS NOT NULL", where: "deleted_at IS NOT NULL",
}) })
@Entity({ tableName: "order_item" }) @Entity({ tableName })
export default class OrderItem { export default class OrderItem {
[OptionalProps]?: OptionalLineItemProps [OptionalProps]?: OptionalLineItemProps
@@ -21,49 +21,50 @@ import ShippingMethod from "./shipping-method"
type OptionalShippingMethodProps = DAL.ModelDateColumns type OptionalShippingMethodProps = DAL.ModelDateColumns
const tableName = "order_shipping"
const OrderIdIndex = createPsqlIndexStatementHelper({ const OrderIdIndex = createPsqlIndexStatementHelper({
tableName: "order_shipping", tableName,
columns: ["order_id"], columns: ["order_id"],
where: "deleted_at IS NOT NULL", where: "deleted_at IS NOT NULL",
}) })
const ReturnIdIndex = createPsqlIndexStatementHelper({ const ReturnIdIndex = createPsqlIndexStatementHelper({
tableName: "order_shipping", tableName,
columns: "return_id", columns: "return_id",
where: "return_id IS NOT NULL AND deleted_at IS NOT NULL", where: "return_id IS NOT NULL AND deleted_at IS NOT NULL",
}) })
const ExchangeIdIndex = createPsqlIndexStatementHelper({ const ExchangeIdIndex = createPsqlIndexStatementHelper({
tableName: "order_shipping", tableName,
columns: ["exchange_id"], columns: ["exchange_id"],
where: "exchange_id IS NOT NULL AND deleted_at IS NOT NULL", where: "exchange_id IS NOT NULL AND deleted_at IS NOT NULL",
}) })
const ClaimIdIndex = createPsqlIndexStatementHelper({ const ClaimIdIndex = createPsqlIndexStatementHelper({
tableName: "order_shipping", tableName,
columns: ["claim_id"], columns: ["claim_id"],
where: "claim_id IS NOT NULL AND deleted_at IS NOT NULL", where: "claim_id IS NOT NULL AND deleted_at IS NOT NULL",
}) })
const OrderVersionIndex = createPsqlIndexStatementHelper({ const OrderVersionIndex = createPsqlIndexStatementHelper({
tableName: "order_shipping", tableName,
columns: ["version"], columns: ["version"],
where: "deleted_at IS NOT NULL", where: "deleted_at IS NOT NULL",
}) })
const ItemIdIndex = createPsqlIndexStatementHelper({ const ItemIdIndex = createPsqlIndexStatementHelper({
tableName: "order_shipping", tableName,
columns: ["shipping_method_id"], columns: ["shipping_method_id"],
where: "deleted_at IS NOT NULL", where: "deleted_at IS NOT NULL",
}) })
const DeletedAtIndex = createPsqlIndexStatementHelper({ const DeletedAtIndex = createPsqlIndexStatementHelper({
tableName: "order", tableName,
columns: "deleted_at", columns: "deleted_at",
where: "deleted_at IS NOT NULL", where: "deleted_at IS NOT NULL",
}) })
@Entity({ tableName: "order_shipping" }) @Entity({ tableName })
export default class OrderShippingMethod { export default class OrderShippingMethod {
[OptionalProps]?: OptionalShippingMethodProps [OptionalProps]?: OptionalShippingMethodProps
@@ -36,19 +36,21 @@ type OrderSummaryTotals = {
refunded_total: BigNumber refunded_total: BigNumber
} }
const tableName = "order_summary"
const OrderIdVersionIndex = createPsqlIndexStatementHelper({ const OrderIdVersionIndex = createPsqlIndexStatementHelper({
tableName: "order_summary", tableName,
columns: ["order_id", "version"], columns: ["order_id", "version"],
where: "deleted_at IS NOT NULL", where: "deleted_at IS NOT NULL",
}) })
const DeletedAtIndex = createPsqlIndexStatementHelper({ const DeletedAtIndex = createPsqlIndexStatementHelper({
tableName: "order", tableName,
columns: "deleted_at", columns: "deleted_at",
where: "deleted_at IS NOT NULL", where: "deleted_at IS NOT NULL",
}) })
@Entity({ tableName: "order_summary" }) @Entity({ tableName })
@OrderIdVersionIndex.MikroORMIndex() @OrderIdVersionIndex.MikroORMIndex()
export default class OrderSummary { export default class OrderSummary {
@PrimaryKey({ columnType: "text" }) @PrimaryKey({ columnType: "text" })
@@ -19,31 +19,32 @@ import ReturnReason from "./return-reason"
type OptionalLineItemProps = DAL.ModelDateColumns type OptionalLineItemProps = DAL.ModelDateColumns
const tableName = "return_item"
const ReturnIdIndex = createPsqlIndexStatementHelper({ const ReturnIdIndex = createPsqlIndexStatementHelper({
tableName: "return_item", tableName,
columns: "return_id", columns: "return_id",
where: "deleted_at IS NOT NULL", where: "deleted_at IS NOT NULL",
}) })
const ReturnReasonIdIndex = createPsqlIndexStatementHelper({ const ReturnReasonIdIndex = createPsqlIndexStatementHelper({
tableName: "return_item", tableName,
columns: "reason_id", columns: "reason_id",
where: "deleted_at IS NOT NULL", where: "deleted_at IS NOT NULL",
}) })
const ItemIdIndex = createPsqlIndexStatementHelper({ const ItemIdIndex = createPsqlIndexStatementHelper({
tableName: "return_item", tableName,
columns: "item_id", columns: "item_id",
where: "deleted_at IS NOT NULL", where: "deleted_at IS NOT NULL",
}) })
const DeletedAtIndex = createPsqlIndexStatementHelper({ const DeletedAtIndex = createPsqlIndexStatementHelper({
tableName: "order_claim_item_image", tableName,
columns: "deleted_at", columns: "deleted_at",
where: "deleted_at IS NOT NULL", where: "deleted_at IS NOT NULL",
}) })
@Entity({ tableName: "return_item" }) @Entity({ tableName })
export default class ReturnItem { export default class ReturnItem {
[OptionalProps]?: OptionalLineItemProps [OptionalProps]?: OptionalLineItemProps
@@ -24,55 +24,57 @@ import Return from "./return"
type OptionalLineItemProps = DAL.ModelDateColumns type OptionalLineItemProps = DAL.ModelDateColumns
const tableName = "order_transaction"
const ReferenceIdIndex = createPsqlIndexStatementHelper({ const ReferenceIdIndex = createPsqlIndexStatementHelper({
tableName: "order_transaction", tableName,
columns: "reference_id", columns: "reference_id",
where: "deleted_at IS NOT NULL", where: "deleted_at IS NOT NULL",
}) })
const OrderIdIndex = createPsqlIndexStatementHelper({ const OrderIdIndex = createPsqlIndexStatementHelper({
tableName: "order_transaction", tableName,
columns: "order_id", columns: "order_id",
where: "deleted_at IS NOT NULL", where: "deleted_at IS NOT NULL",
}) })
const ReturnIdIndex = createPsqlIndexStatementHelper({ const ReturnIdIndex = createPsqlIndexStatementHelper({
tableName: "order_transaction", tableName,
columns: "return_id", columns: "return_id",
where: "return_id IS NOT NULL AND deleted_at IS NOT NULL", where: "return_id IS NOT NULL AND deleted_at IS NOT NULL",
}) })
const ExchangeIdIndex = createPsqlIndexStatementHelper({ const ExchangeIdIndex = createPsqlIndexStatementHelper({
tableName: "order_item", tableName,
columns: ["exchange_id"], columns: ["exchange_id"],
where: "exchange_id IS NOT NULL AND deleted_at IS NOT NULL", where: "exchange_id IS NOT NULL AND deleted_at IS NOT NULL",
}) })
const ClaimIdIndex = createPsqlIndexStatementHelper({ const ClaimIdIndex = createPsqlIndexStatementHelper({
tableName: "order_item", tableName,
columns: ["claim_id"], columns: ["claim_id"],
where: "claim_id IS NOT NULL AND deleted_at IS NOT NULL", where: "claim_id IS NOT NULL AND deleted_at IS NOT NULL",
}) })
const CurrencyCodeIndex = createPsqlIndexStatementHelper({ const CurrencyCodeIndex = createPsqlIndexStatementHelper({
tableName: "order_transaction", tableName,
columns: "currency_code", columns: "currency_code",
where: "deleted_at IS NOT NULL", where: "deleted_at IS NOT NULL",
}) })
const DeletedAtIndex = createPsqlIndexStatementHelper({ const DeletedAtIndex = createPsqlIndexStatementHelper({
tableName: "order_transaction", tableName,
columns: "deleted_at", columns: "deleted_at",
where: "deleted_at IS NOT NULL", where: "deleted_at IS NOT NULL",
}) })
const OrderIdVersionIndex = createPsqlIndexStatementHelper({ const OrderIdVersionIndex = createPsqlIndexStatementHelper({
tableName: "order_transaction", tableName,
columns: ["order_id", "version"], columns: ["order_id", "version"],
where: "deleted_at IS NOT NULL", where: "deleted_at IS NOT NULL",
}) })
@Entity({ tableName: "order_transaction" }) @Entity({ tableName })
@Filter(DALUtils.mikroOrmSoftDeletableFilterOptions) @Filter(DALUtils.mikroOrmSoftDeletableFilterOptions)
@OrderIdVersionIndex.MikroORMIndex() @OrderIdVersionIndex.MikroORMIndex()
export default class Transaction { export default class Transaction {