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

Validation error when shadowDatabaseUrl is identical to url (or directUrl) #16628

Closed
janpio opened this issue Dec 5, 2022 · 9 comments · Fixed by prisma/prisma-engines#4831
Closed
Labels
good first issue Always wanted to get involved in an open source project but don’t know where to begin? Welcome! kind/improvement An improvement to existing feature and code. team/schema Issue for team Schema. topic: error topic: prisma migrate dev CLI: prisma migrate dev topic: prisma validate CLI: prisma validate topic: schema validation topic: shadow database
Milestone

Comments

@janpio
Copy link
Member

janpio commented Dec 5, 2022

prisma/docs#4188 raised a valid point that it is bad to use the same database for shadowDatabaseUrl as you are using for url - your database will be overwritten and you will lose data. The PR adds a warning into the docs, but we can actually do one better and just fail validation of the schema in this case.

Internal discussion: https://prisma-company.slack.com/archives/CGMCB82N8/p1670232135999259

@janpio janpio added kind/improvement An improvement to existing feature and code. topic: error team/schema Issue for team Schema. topic: prisma migrate dev CLI: prisma migrate dev labels Dec 5, 2022
@andrew-walford-prisma
Copy link

Because this is a potentially serious issue if the user doesn't use separate databases, I'm going to approve the docs PR as an interim measure. We can remove the warning from the docs when this work is done.

@janpio
Copy link
Member Author

janpio commented Aug 25, 2023

Another case that could have been prevented by this: #20842

@janpio janpio added the good first issue Always wanted to get involved in an open source project but don’t know where to begin? Welcome! label Aug 25, 2023
@janpio janpio changed the title Error when shadowDatabaseUrl is identical to url (or directUrl) Validation error when shadowDatabaseUrl is identical to url (or directUrl) Aug 25, 2023
@tomhoule
Copy link
Contributor

We already check that url ≠ shadow database url (https://github.com/prisma/prisma-engines/blob/d7eca61ec34d27473cb990402ce406299191[…]ed/schema-engine/connectors/sql-schema-connector/src/flavour.rs — and in the submodules to see where that is used). That wasn't implemented for directUrl when directUrl was added.

@Dean-Coakley
Copy link

@tomhoule Can you provide some more guidance on what approach I can take to try resolve this issue?

@tomhoule
Copy link
Contributor

The gist of the change would be that if directUrl is defined, we would need to compare (in the function linked above) the directUrl with the shadowDatabaseUrl, and otherwise keep the existing comparison (between url and shadowDatabaseUrl).

@zlimez
Copy link

zlimez commented Dec 10, 2023

@tomhoule I am keen on contributing to this issue, but from what I understand you are saying that this validation should be performed at the engine side right therefore this issue belong to the engine repo? As I see the current client implementation also just feeds the entire schema as a string to the engine, so to perform validation at client side would require some parsing which I assume you think is not the best approach?

@tomhoule
Copy link
Contributor

Hi @zlimez — I don't work at Prisma anymore so I'm not responsible for the direction. It could be done either way, the TS code has access to some of the engines parser API.

@zlimez
Copy link

zlimez commented Dec 11, 2023

Oh okok thank you I understand @janpio may I know what would be the desired approach adding to the engine backend check or validate before passing the schema to the engine

@janpio
Copy link
Member Author

janpio commented Dec 11, 2023

Yes, this should happen in the engine.
We track all issues in this repository.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Always wanted to get involved in an open source project but don’t know where to begin? Welcome! kind/improvement An improvement to existing feature and code. team/schema Issue for team Schema. topic: error topic: prisma migrate dev CLI: prisma migrate dev topic: prisma validate CLI: prisma validate topic: schema validation topic: shadow database
Projects
None yet
6 participants