SDK question: Why does DMMF not include any data a...
# orm-help
m
SDK question: Why does DMMF not include any data associated to defined
@@index
Writing a plugin that does versioning to store history of changes on a data model – for each
Datamodel
, would like to define a
DatamodelVersion
model which specifies some fields for storing history and some references to
Datamodel
In addition would like to add
versions: DatamodelVersion
to the original
Datamodel
schema. But in doing so, losing any
@@index
that is defined on the original
Datamodel
schema.
j
I asked a similar question about @db types and finally just wrote my own little parser that I run along side the regular dmmf parsing
m
@Jason Abbott is that a part of an open sourced codebase? 🙏
j
Code isn't currently in a shared location but here's the main bit. Call
parseSqlTypes()
and get back an object that has the db type (like
Varchar(25)
) mapped to fields within models, same as the DMMF. That way, when iterating fields in the DMMF, it's a simple, direct lookup to get the db types. Using the regular generator SDK (which you may not be doing), I make the parse call at the top of
onGenerate
and pass the result through along side the SDK-provided DMMF.
m
Thanks @Jason Abbott, this helps. Seems like this should be added to the Prisma parse / DMMF util exposed by the SDK, wondering what the Prisma team thinks about that?
r
@Moaaz 👋 I would suggest creating a feature request here so that we can look into this 🙂
m
@Ryan thanks! created: https://github.com/prisma/prisma/issues/10302, let me know if any additional input would help!
🙌 1
r
Looks great!