Skip to content

Commit

Permalink
revert mikro orm v6 upgrade
Browse files Browse the repository at this point in the history
  • Loading branch information
olivermrbl committed Jan 10, 2024
1 parent 9523b91 commit e403a2c
Show file tree
Hide file tree
Showing 8 changed files with 60 additions and 185 deletions.
6 changes: 3 additions & 3 deletions packages/cart/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,9 @@
"@medusajs/modules-sdk": "^1.12.5",
"@medusajs/types": "^1.11.9",
"@medusajs/utils": "^1.11.2",
"@mikro-orm/core": "^6.0.1",
"@mikro-orm/migrations": "^6.0.1",
"@mikro-orm/postgresql": "^6.0.1",
"@mikro-orm/core": "5.9.7",
"@mikro-orm/migrations": "5.9.7",
"@mikro-orm/postgresql": "5.9.7",
"awilix": "^8.0.0",
"dotenv": "^16.1.4",
"knex": "2.4.2"
Expand Down
14 changes: 10 additions & 4 deletions packages/cart/src/models/address.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,21 @@
import { DAL } from "@medusajs/types"
import { generateEntityId } from "@medusajs/utils"
import {
BeforeCreate,
Entity,
OnInit,
Opt,
OptionalProps,
PrimaryKey,
Property,
Property
} from "@mikro-orm/core"


type OptionalAddressProps = DAL.EntityDateColumns // TODO: To be revisited when more clear

@Entity({ tableName: "cart_address" })
export default class Address {
[OptionalProps]: OptionalAddressProps

@PrimaryKey({ columnType: "text" })
id!: string

Expand Down Expand Up @@ -54,15 +60,15 @@ export default class Address {
columnType: "timestamptz",
defaultRaw: "now()",
})
created_at: Opt<Date>
created_at: Date

@Property({
onCreate: () => new Date(),
onUpdate: () => new Date(),
columnType: "timestamptz",
defaultRaw: "now()",
})
updated_at: Opt<Date>
updated_at: Date

@BeforeCreate()
onCreate() {
Expand Down
11 changes: 8 additions & 3 deletions packages/cart/src/models/adjustment-line.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
import { Opt, PrimaryKey, Property } from "@mikro-orm/core"
import { DAL } from "@medusajs/types"
import { OptionalProps, PrimaryKey, Property } from "@mikro-orm/core"

type OptionalAdjustmentLineProps = DAL.EntityDateColumns // TODO: To be revisited when more clear

/**
* As per the Mikro ORM docs, superclasses should use the abstract class definition
* Source: https://mikro-orm.io/docs/inheritance-mapping
*/
export default abstract class AdjustmentLine {
[OptionalProps]: OptionalAdjustmentLineProps

@PrimaryKey({ columnType: "text" })
id: string

Expand All @@ -28,13 +33,13 @@ export default abstract class AdjustmentLine {
columnType: "timestamptz",
defaultRaw: "now()",
})
created_at: Opt<Date>
created_at: Date

@Property({
onCreate: () => new Date(),
onUpdate: () => new Date(),
columnType: "timestamptz",
defaultRaw: "now()",
})
updated_at: Opt<Date>
updated_at: Date
}
18 changes: 13 additions & 5 deletions packages/cart/src/models/cart.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { DAL } from "@medusajs/types"
import { generateEntityId } from "@medusajs/utils"
import {
BeforeCreate,
Expand All @@ -7,16 +8,23 @@ import {
OnInit,
OneToMany,
OneToOne,
Opt,
OptionalProps,
PrimaryKey,
Property,
} from "@mikro-orm/core"
import Address from "./address"
import LineItem from "./line-item"
import ShippingMethod from "./shipping-method"

type OptionalCartProps =
| "shipping_address"
| "billing_address"
| DAL.EntityDateColumns // TODO: To be revisited when more clear

@Entity({ tableName: "cart" })
export default class Cart {
[OptionalProps]?: OptionalCartProps

@PrimaryKey({ columnType: "text" })
id: string

Expand Down Expand Up @@ -45,15 +53,15 @@ export default class Cart {
cascade: [Cascade.REMOVE],
nullable: true,
})
shipping_address?: Opt<Address | null>
shipping_address?: Address | null

@OneToOne({
entity: () => Address,
joinColumn: "billing_address_id",
cascade: [Cascade.REMOVE],
nullable: true,
})
billing_address?: Opt<Address | null>
billing_address?: Address | null

@Property({ columnType: "jsonb", nullable: true })
metadata?: Record<string, unknown> | null
Expand Down Expand Up @@ -107,15 +115,15 @@ export default class Cart {
columnType: "timestamptz",
defaultRaw: "now()",
})
created_at: Opt<Date>
created_at: Date

@Property({
onCreate: () => new Date(),
onUpdate: () => new Date(),
columnType: "timestamptz",
defaultRaw: "now()",
})
updated_at: Opt<Date>
updated_at: Date

@BeforeCreate()
onCreate() {
Expand Down
1 change: 0 additions & 1 deletion packages/cart/src/models/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,3 @@ export { default as LineItemTaxLine } from "./line-item-tax-line"
export { default as ShippingMethod } from "./shipping-method"
export { default as ShippingMethodAdjustmentLine } from "./shipping-method-adjustment-line"
export { default as ShippingMethodTaxLine } from "./shipping-method-tax-line"

26 changes: 18 additions & 8 deletions packages/cart/src/models/line-item.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { DAL } from "@medusajs/types"
import { generateEntityId } from "@medusajs/utils"
import {
BeforeCreate,
Expand All @@ -8,21 +9,30 @@ import {
ManyToOne,
OnInit,
OneToMany,
Opt,
OptionalProps,
PrimaryKey,
Property,
} from "@mikro-orm/core"
import Cart from "./cart"
import LineItemAdjustmentLine from "./line-item-adjustment-line"
import LineItemTaxLine from "./line-item-tax-line"

type OptionalLineItemProps =
| "is_discoutable"
| "is_tax_inclusive"
| "compare_at_unit_price"
| "requires_shipping"
| DAL.EntityDateColumns

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

@PrimaryKey({ columnType: "text" })
id: string

@ManyToOne(() => Cart, {
cascade: [Cascade.REMOVE],
onDelete: "cascade",
index: "IDX_line_item_cart_id",
fieldName: "cart_id",
})
Expand Down Expand Up @@ -81,16 +91,16 @@ export default class LineItem {
variant_option_values?: Record<string, unknown> | null

@Property({ columnType: "boolean" })
requires_shipping: Opt<boolean> = true
requires_shipping = true

@Property({ columnType: "boolean" })
is_discountable: Opt<boolean> = true
is_discountable = true

@Property({ columnType: "boolean" })
is_tax_inclusive: Opt<boolean> = false
is_tax_inclusive = false

@Property({ columnType: "numeric", nullable: true })
compare_at_unit_price?: Opt<number>
compare_at_unit_price?: number

@Property({ columnType: "numeric", serializer: Number })
@Check({ expression: "unit_price >= 0" }) // TODO: Validate that numeric types work with the expression
Expand Down Expand Up @@ -137,15 +147,15 @@ export default class LineItem {
columnType: "timestamptz",
defaultRaw: "now()",
})
created_at: Opt<Date>
created_at: Date

@Property({
onCreate: () => new Date(),
onUpdate: () => new Date(),
columnType: "timestamptz",
defaultRaw: "now()",
})
updated_at: Opt<Date>
updated_at: Date

@BeforeCreate()
onCreate() {
Expand Down
9 changes: 4 additions & 5 deletions packages/cart/src/models/shipping-method.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import {
ManyToOne,
OnInit,
OneToMany,
Opt,
PrimaryKey,
Property,
} from "@mikro-orm/core"
Expand All @@ -22,7 +21,7 @@ export default class ShippingMethod {
id: string

@ManyToOne(() => Cart, {
cascade: [Cascade.REMOVE],
onDelete: "cascade",
index: "IDX_shipping_method_cart_id",
fieldName: "cart_id",
})
Expand All @@ -39,7 +38,7 @@ export default class ShippingMethod {
amount: number

@Property({ columnType: "boolean" })
is_tax_inclusive: Opt<boolean> = false
is_tax_inclusive = false

@Property({ columnType: "text", nullable: true })
shipping_option_id?: string | null
Expand Down Expand Up @@ -87,15 +86,15 @@ export default class ShippingMethod {
columnType: "timestamptz",
defaultRaw: "now()",
})
created_at: Opt<Date>
created_at: Date

@Property({
onCreate: () => new Date(),
onUpdate: () => new Date(),
columnType: "timestamptz",
defaultRaw: "now()",
})
updated_at: Opt<Date>
updated_at: Date

@BeforeCreate()
onCreate() {
Expand Down
Loading

0 comments on commit e403a2c

Please sign in to comment.