20250116 - Use DMMF for Prisma Schema Parsing
Status
- Proposed
- Accepted
- Rejected
- Deprecated
- Superseded
Context
We need to parse Prisma schema files to extract database structure information. Several approaches were considered:
- JavaScript parsers (e.g., Acorn, Babel)
- Custom parsers using parser generators (e.g., PEG.js)
- DMMF (Data Model Meta Format) from @prisma/internals
Each approach has different implications for maintenance, accuracy, and development effort. JavaScript parsers were immediately ruled out as they are designed for parsing JavaScript code, not Prisma's custom schema format.
Decision
We will use DMMF from @prisma/internals to parse Prisma schema files. DMMF is Prisma's internal representation format used for schema parsing and validation. Using DMMF is more reliable and accurate for parsing Prisma schema files compared to custom parsers.
Key factors in this decision:
- Official support from Prisma team
- Comprehensive parsing of models, fields, and relationships
- Built-in validation and type safety
- Automatic compatibility with future Prisma updates
- De facto stability demonstrated by widespread usage in the Prisma ecosystem
Consequences
Positive
- Reliable and accurate parsing of Prisma schemas
- Reduced development and maintenance effort (no need to implement custom parsers)
- Future-proof against Prisma syntax changes
- Proven stability through widespread usage in other tools
Negative
- Additional dependency on @prisma/internals
- No official recommendation to use @prisma/internals
Neutral
- Need to transform DMMF output to match our internal database structure format
- Learning curve for working with DMMF API