Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for schema definitions that are not overwritten by a prisma db pull #9571

Open
Tracked by #11441
blevine opened this issue Oct 3, 2021 · 1 comment
Open
Tracked by #11441
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

Comments

@blevine
Copy link

blevine commented Oct 3, 2021

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:

model user_group_membership {
  group_id    String      @db.VarChar(36)
  user_id     String      @db.VarChar(36)
  user_entity user_entity @relation(fields: [user_id], references: [id], onDelete: NoAction, onUpdate: NoAction, map: "fk_user_group_user")

  @@id([group_id, user_id], map: "constraint_user_group")
  @@index([user_id], map: "idx_user_group_mapping")
}

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" ;-)

@pantharshit00 pantharshit00 added kind/feature A request for a new feature. team/schema Issue for team Schema. topic: prisma db pull CLI: prisma db pull labels Oct 4, 2021
@do4gr do4gr assigned do4gr and floelhoeffel and unassigned do4gr Oct 21, 2021
@tomhoule tomhoule added the topic: relationMode formerly `referentialIntegrity` label Nov 4, 2021
@floelhoeffel floelhoeffel added the topic: schema metadata Metadata to allow advanced commenting or protection of certain parts of a schemas label Jan 26, 2022
@floelhoeffel
Copy link

Thanks for the detailed issue @blevine - we have categorized it but its unfortunately unlikely that we will get to this short/mid-term. We are going to look into schemas in 2022 and will consider your feedback though!

@floelhoeffel floelhoeffel removed their assignment Jan 26, 2022
@janpio janpio mentioned this issue Jul 1, 2022
35 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
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
Projects
None yet
Development

No branches or pull requests

6 participants