feat(utils,currency): Migrate currency to use DML (#7807)
This commit is contained in:
@@ -1,8 +1,7 @@
|
||||
import { defineMikroOrmCliConfig } from "@medusajs/utils"
|
||||
import * as entities from "./src/models"
|
||||
|
||||
module.exports = {
|
||||
export default defineMikroOrmCliConfig({
|
||||
entities: Object.values(entities),
|
||||
schema: "public",
|
||||
clientUrl: "postgres://postgres@localhost/medusa-currency",
|
||||
type: "postgresql",
|
||||
}
|
||||
databaseName: "medusa-currency",
|
||||
})
|
||||
|
||||
@@ -5,7 +5,12 @@ import {
|
||||
Modules,
|
||||
} from "@medusajs/utils"
|
||||
|
||||
export const joinerConfig = defineJoinerConfig(Modules.CURRENCY)
|
||||
export const joinerConfig = defineJoinerConfig(Modules.CURRENCY, {
|
||||
primaryKeys: ["code"],
|
||||
linkableKeys: {
|
||||
currency_code: "currency",
|
||||
},
|
||||
})
|
||||
|
||||
export const entityNameToLinkableKeysMap: MapToConfig =
|
||||
buildEntitiesNameToLinkableKeysMap(joinerConfig.linkableKeys)
|
||||
|
||||
@@ -14,7 +14,7 @@ export default async ({
|
||||
const logger =
|
||||
container.resolve<Logger>(ContainerRegistrationKeys.LOGGER) ?? console
|
||||
const { currencyService_ } = container.resolve<{
|
||||
currencyService_: ModulesSdkTypes.IMedusaInternalService<Currency>
|
||||
currencyService_: ModulesSdkTypes.IMedusaInternalService<typeof Currency>
|
||||
}>(ModuleRegistrationName.CURRENCY)
|
||||
|
||||
try {
|
||||
|
||||
@@ -42,7 +42,7 @@
|
||||
},
|
||||
"decimal_digits": {
|
||||
"name": "decimal_digits",
|
||||
"type": "int",
|
||||
"type": "integer",
|
||||
"unsigned": false,
|
||||
"autoincrement": false,
|
||||
"primary": false,
|
||||
@@ -90,6 +90,16 @@
|
||||
"length": 6,
|
||||
"default": "now()",
|
||||
"mappedType": "datetime"
|
||||
},
|
||||
"deleted_at": {
|
||||
"name": "deleted_at",
|
||||
"type": "timestamptz",
|
||||
"unsigned": false,
|
||||
"autoincrement": false,
|
||||
"primary": false,
|
||||
"nullable": true,
|
||||
"length": 6,
|
||||
"mappedType": "datetime"
|
||||
}
|
||||
},
|
||||
"name": "currency",
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
import { Migration } from "@mikro-orm/migrations"
|
||||
|
||||
export class Migration20240624082354 extends Migration {
|
||||
async up(): Promise<void> {
|
||||
this.addSql(
|
||||
'alter table if exists "currency" add column if not exists "deleted_at" timestamptz null;'
|
||||
)
|
||||
}
|
||||
|
||||
async down(): Promise<void> {
|
||||
this.addSql(
|
||||
'alter table if exists "currency" drop column if exists "deleted_at";'
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -1,50 +1,10 @@
|
||||
import { BigNumberRawValue } from "@medusajs/types"
|
||||
import {
|
||||
BigNumber,
|
||||
MikroOrmBigNumberProperty,
|
||||
Searchable,
|
||||
} from "@medusajs/utils"
|
||||
import { Entity, PrimaryKey, Property } from "@mikro-orm/core"
|
||||
import { model } from "@medusajs/utils"
|
||||
|
||||
@Entity({ tableName: "currency" })
|
||||
class Currency {
|
||||
@Searchable()
|
||||
@PrimaryKey({ columnType: "text" })
|
||||
code!: string
|
||||
|
||||
@Property({ columnType: "text" })
|
||||
symbol: string
|
||||
|
||||
@Property({ columnType: "text" })
|
||||
symbol_native: string
|
||||
|
||||
@Searchable()
|
||||
@Property({ columnType: "text" })
|
||||
name: string
|
||||
|
||||
@Property({ columnType: "int", default: 0 })
|
||||
decimal_digits: number
|
||||
|
||||
@MikroOrmBigNumberProperty({ default: 0 })
|
||||
rounding: BigNumber | number
|
||||
|
||||
@Property({ columnType: "jsonb" })
|
||||
raw_rounding: BigNumberRawValue
|
||||
|
||||
@Property({
|
||||
onCreate: () => new Date(),
|
||||
columnType: "timestamptz",
|
||||
defaultRaw: "now()",
|
||||
})
|
||||
created_at: Date
|
||||
|
||||
@Property({
|
||||
onCreate: () => new Date(),
|
||||
onUpdate: () => new Date(),
|
||||
columnType: "timestamptz",
|
||||
defaultRaw: "now()",
|
||||
})
|
||||
updated_at: Date
|
||||
}
|
||||
|
||||
export default Currency
|
||||
export default model.define("currency", {
|
||||
code: model.text().primaryKey(),
|
||||
symbol: model.text(),
|
||||
symbol_native: model.text(),
|
||||
name: model.text(),
|
||||
decimal_digits: model.number().default(0),
|
||||
rounding: model.bigNumber().default(0),
|
||||
})
|
||||
|
||||
@@ -11,9 +11,9 @@ import {
|
||||
ModulesSdkTypes,
|
||||
} from "@medusajs/types"
|
||||
|
||||
import { MedusaService } from "@medusajs/utils"
|
||||
import { Currency } from "@models"
|
||||
import { entityNameToLinkableKeysMap, joinerConfig } from "../joiner-config"
|
||||
import { MedusaService } from "@medusajs/utils"
|
||||
|
||||
type InjectedDependencies = {
|
||||
baseRepository: DAL.RepositoryService
|
||||
@@ -27,7 +27,9 @@ export default class CurrencyModuleService
|
||||
implements ICurrencyModuleService
|
||||
{
|
||||
protected baseRepository_: DAL.RepositoryService
|
||||
protected readonly currencyService_: ModulesSdkTypes.IMedusaInternalService<Currency>
|
||||
protected readonly currencyService_: ModulesSdkTypes.IMedusaInternalService<
|
||||
typeof Currency
|
||||
>
|
||||
|
||||
constructor(
|
||||
{ baseRepository, currencyService }: InjectedDependencies,
|
||||
|
||||
Reference in New Issue
Block a user