Support for schema definitions that are not overwritten by a prisma db pull #9571
Labels
kind/feature
A request for a new feature.
team/schema
Issue for team Schema.
topic: prisma db pull
CLI: prisma db pull
topic: relationMode
formerly `referentialIntegrity`
topic: schema metadata
Metadata to allow advanced commenting or protection of certain parts of a schemas
topic: weak relations
Based on discussion started here.
This is an idea for an enhancement to
prisma db pull
. I realize that this is not Prisma's main use-case, but:I am accessing a database via Prisma for which I don't own the DB schema and so I can't modify it. I would like to be able to "compensate" for certain deficiencies in the DB schema at the Prisma schema level. Here is an example,
The DB defines a user_group_membership relational table that generates a Prisma schema like so:
The DB schema did not define group_id as a foreign key and so the Prisma schema does not include the relationship to the group table. However, I can modify the Prisma schema to include that relationship recognizing that queries will be non-optimal since no index exists on group_id. That's OK for my use case. By doing that, I can then create Prisma queries with
include: group
.Even though I can't modify the DB schema for existing tables, I can add my own tables. For reasons I don't want to go into here, I'm using Knex migrations to manage this. So my workflow has been:
create Knex migration -> execute migration -> prisma db pull -> prisma generate
The problem is that this will overwrite the manual changes that I made to the Prisma schema.
To solve this, I'm imagining some sort of new annotation (let's say
@keep
or@protected
) that identifies certain declarations in the schema.prisma that should be carried forward and not overwritten during prisma db pull.If there's some other way for me to go about this without an enhancement to Prisma, please let me know. Otherwise, I wonder if this could be considered as a viable future enhancement. Where "future" == "not too far in the future" ;-)
The text was updated successfully, but these errors were encountered: