fix(medusa): prevent plugin:db:generate crash when model files export…#14718
Open
shubhamchoudhary-2003 wants to merge 2 commits intomedusajs:developfrom
Open
fix(medusa): prevent plugin:db:generate crash when model files export…#14718shubhamchoudhary-2003 wants to merge 2 commits intomedusajs:developfrom
shubhamchoudhary-2003 wants to merge 2 commits intomedusajs:developfrom
Conversation
… enums MetadataStorage.getMetadataFromDecorator() returns a truthy EntityMetadata for any input with a .name property, causing TypeScript enums to be incorrectly treated as database entities. This crashes MikroORM when it tries to process them during migration generation. Replace the MetadataStorage check with typeof === "function", which correctly identifies MikroORM class entities while rejecting enum objects. This matches the proven pattern already used in load-internal.ts cleanupResources for the regular db:generate path.
|
|
@shubhamchoudhary-2003 is attempting to deploy a commit to the medusajs Team on Vercel. A member of the Team first needs to authorize it. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
fix(medusa): prevent plugin:db:generate crash when model files export enums
MetadataStorage.getMetadataFromDecorator()returns a truthyEntityMetadatafor any input with a.nameproperty, causing TypeScript enums to be incorrectly treated as database entities. This crashes MikroORM when it tries to process them during migration generation.Replace the
MetadataStoragecheck withtypeof === "function", which correctly identifies MikroORM class entities while rejecting enum objects. This matches the proven pattern already used inload-internal.tscleanupResourcesfor the regulardb:generatepath.Summary
What — Fix entity detection in
plugin:db:generateto prevent TypeScript enums from being treated as MikroORM entities.Why — When model files export enums, MikroORM crashes during migration generation because enums are mistakenly identified as database entities.
MetadataStorage.getMetadataFromDecorator()returns truthy for anything with a.nameproperty, which includes compiled TypeScript enums.How — Replaced the
MetadataStorage.getMetadataFromDecorator()check withtypeof potentialEntity === "function"in the entity filter insidegetEntitiesForModule()(packages/medusa/src/commands/plugin/db/generate.ts). Class constructors are functions; enum objects are not — so this correctly filters out enums while keeping real entities. This aligns with the same pattern already used inload-internal.tscleanupResources.Testing — Create a plugin with a model file that exports both a MikroORM entity and a TypeScript enum, then run
npx medusa plugin:db:generate. Before this fix the command crashes; after it generates migrations correctly.Examples
Checklist
yarn changesetand follow the promptsAdditional Context
The regular (non-plugin)
db:generatepath inload-internal.tsalready uses the sametypeof === "function"pattern in itscleanupResourcesfunction. This PR aligns the plugin path with that existing approach.Note
Low Risk
Small, localized change to entity filtering for the plugin migration generator; primary risk is inadvertently skipping edge-case entity exports that aren’t functions.
Overview
Prevents
plugin:db:generatefrom crashing when plugin model files export non-entity values (e.g., TypeScript enums) by tightening entity detection.In
commands/plugin/db/generate.ts, the entity filter no longer relies onMetadataStorage.getMetadataFromDecorator()and instead treats only DML entities or function exports (class constructors) as MikroORM entities, avoiding misclassification of enum objects during migration generation.Written by Cursor Bugbot for commit b2bc415. This will update automatically on new commits. Configure here.