Initial implementation with just the generate method (#7973)

This commit is contained in:
Harminder Virk
2024-07-09 12:32:02 +05:30
committed by GitHub
parent 366231f658
commit 4b391fc3cf
6 changed files with 594 additions and 13 deletions

View File

@@ -14,13 +14,13 @@ describe("defineMikroOrmCliConfig", () => {
test("should return the correct config", () => {
const config = defineMikroOrmCliConfig(moduleName, {
entities: [{} as any],
databaseName: "medusa-fulfillment",
dbName: "medusa-fulfillment",
})
expect(config).toEqual({
entities: [{}],
clientUrl: "postgres://postgres@localhost/medusa-fulfillment",
type: "postgresql",
dbName: "medusa-fulfillment",
migrations: {
generator: expect.any(Function),
},
@@ -34,8 +34,8 @@ describe("defineMikroOrmCliConfig", () => {
expect(config).toEqual({
entities: [{}],
clientUrl: "postgres://postgres@localhost/medusa-my-test",
type: "postgresql",
dbName: "medusa-my-test",
migrations: {
generator: expect.any(Function),
},

View File

@@ -17,12 +17,10 @@ type Options = Partial<Omit<MikroORMOptions, "entities" | "entitiesTs">> & {
| EntitySchema
| DmlEntity<any, any>
)[]
databaseName?: string
}
type ReturnedOptions = Partial<MikroORMOptions> & {
entities: MikroORMOptions["entities"]
clientUrl: string
type: MikroORMOptions["type"]
migrations: MikroORMOptions["migrations"]
}
@@ -53,17 +51,11 @@ export function defineMikroOrmCliConfig(
) as MikroORMOptions["entities"]
const normalizedModuleName = kebabCase(moduleName.replace("Service", ""))
let databaseName = `medusa-${normalizedModuleName}`
if (options.databaseName) {
databaseName = options.databaseName
// @ts-ignore
delete options.databaseName
}
const databaseName = `medusa-${normalizedModuleName}`
return {
clientUrl: `postgres://postgres@localhost/${databaseName}`,
type: "postgresql",
dbName: databaseName,
...options,
entities,
migrations: {