From 5c77b10fa64d28c315e5196da1c9608c1c0a2ab7 Mon Sep 17 00:00:00 2001 From: Leonardo Benini Date: Thu, 2 Oct 2025 14:05:40 +0200 Subject: [PATCH] fix(medusa): plugin:db:generate skip modules with no data models (#13652) Currently the plugin:db:generate command panics if one of the modules doesn't define any data models. This makes it impossible to generate migrations if you have a mix of modules with and without data models. I added a simple check to skip these modules when creating the migrations. Steps to repro: ``` npx create-medusa-app --plugin cd my-medusa-plugin # create a module with an empty service and no data models npx medusa db:plugin:generate ``` Full error: ``` info: Generating migrations... info: Generating migrations for module postmarkModuleService... info: ---------------------------------------------------------------------------- error: defineMikroOrmCliConfig failed with: entities is required Error: defineMikroOrmCliConfig failed with: entities is required at defineMikroOrmCliConfig (/Users/leonardo/dev/medusa-plugin-postmark/node_modules/@medusajs/utils/src/modules-sdk/mikro-orm-cli-config-builder.ts:41:11) at generateMigrations (/Users/leonardo/dev/medusa-plugin-postmark/node_modules/@medusajs/medusa/src/commands/plugin/db/generate.ts:124:26) at main (/Users/leonardo/dev/medusa-plugin-postmark/node_modules/@medusajs/medusa/src/commands/plugin/db/generate.ts:49:11) at processTicksAndRejections (node:internal/process/task_queues:105:5) ``` I didnt bother with writing an issue since I had the fix ready and it's very small, but lmk if I should in the future --- .changeset/funny-sheep-vanish.md | 5 +++++ packages/medusa/src/commands/plugin/db/generate.ts | 4 ++++ 2 files changed, 9 insertions(+) create mode 100644 .changeset/funny-sheep-vanish.md diff --git a/.changeset/funny-sheep-vanish.md b/.changeset/funny-sheep-vanish.md new file mode 100644 index 0000000000..714480adf5 --- /dev/null +++ b/.changeset/funny-sheep-vanish.md @@ -0,0 +1,5 @@ +--- +"@medusajs/medusa": patch +--- + +fix(medusa): plugin:db:generate skip modules with no data models diff --git a/packages/medusa/src/commands/plugin/db/generate.ts b/packages/medusa/src/commands/plugin/db/generate.ts index febd95b831..b0d352680e 100644 --- a/packages/medusa/src/commands/plugin/db/generate.ts +++ b/packages/medusa/src/commands/plugin/db/generate.ts @@ -114,6 +114,10 @@ async function generateMigrations( logger.info( `Generating migrations for module ${moduleDescriptor.serviceName}...` ) + if (moduleDescriptor.entities.length === 0) { + logger.info(`No entities found for module ${moduleDescriptor.serviceName}, skipping...`) + continue + } const mikroOrmConfig = defineMikroOrmCliConfig( moduleDescriptor.serviceName,