refactor: use module name as the snapshot name (#11802)
Fixes: FRMW-2930 This PR updates the MikroORM config to use the module name as the snapshot name when generating migration files. Otherwise, MikroORM defaults to the database name and every time you update the database name, it will create a new snapshot. Also, we migrate existing snapshot files to be same the new file name to avoid breaking changes.
This commit is contained in:
@@ -26,6 +26,7 @@ describe("defineMikroOrmCliConfig", () => {
|
||||
dbName: "medusa-fulfillment",
|
||||
migrations: {
|
||||
generator: expect.any(Function),
|
||||
snapshotName: ".snapshot-medusa-my-test",
|
||||
},
|
||||
})
|
||||
})
|
||||
@@ -44,6 +45,7 @@ describe("defineMikroOrmCliConfig", () => {
|
||||
password: "",
|
||||
migrations: {
|
||||
generator: expect.any(Function),
|
||||
snapshotName: ".snapshot-medusa-my-test",
|
||||
},
|
||||
})
|
||||
})
|
||||
|
||||
@@ -3,6 +3,7 @@ import { mikroOrmCreateConnection } from "../../dal"
|
||||
import { loadDatabaseConfig } from "../load-module-database-config"
|
||||
import { Migrations } from "../../migrations"
|
||||
import { toMikroOrmEntities } from "../../dml"
|
||||
import { kebabCase } from "../../common/to-kebab-case"
|
||||
|
||||
const TERMINAL_SIZE = process.stdout.columns
|
||||
|
||||
@@ -42,7 +43,12 @@ export function buildGenerateMigrationScript({
|
||||
|
||||
const normalizedModels = toMikroOrmEntities(models)
|
||||
const orm = await mikroOrmCreateConnection(
|
||||
dbData,
|
||||
{
|
||||
...dbData,
|
||||
snapshotName: `.snapshot-${kebabCase(
|
||||
moduleName.replace("Service", "")
|
||||
)}`,
|
||||
},
|
||||
normalizedModels,
|
||||
pathToMigrations
|
||||
)
|
||||
|
||||
@@ -61,6 +61,7 @@ export function defineMikroOrmCliConfig(
|
||||
...(options as any),
|
||||
entities: entities.filter(Boolean),
|
||||
migrations: {
|
||||
snapshotName: `.snapshot-${databaseName}`,
|
||||
generator: CustomTsMigrationGenerator,
|
||||
...options.migrations,
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user