-
Notifications
You must be signed in to change notification settings - Fork 119
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
Prisma shadow database is incompatible with the electric proxy #668
Comments
Raised an issue internally to investigate this |
This may be related to this issue shared on Discord: https://discord.com/channels/933657521581858818/1165673468512182282 As @alco noted there:
Could this be the issue? |
@kevin-dp Prisma never deletes/resets your database when running migrations, the error message which prisma gives may cause you to believe that but that's not what is actually happening. I see there is a misunderstanding on how prisma works under the hood. Let me give you a quick rundown on prisma so you may implement proper electric-proxy support(so prisma migrate dev just works without hacks or a high pain tolerance). Prisma when tasked with generating migrations needs to answer the question "ok what changes do I need to make so the db is in the desired state". The naive approach would be to look at the current migrations and see what changes to the schema were made and generate a new migration based on the difference. This unfortunately has an issue, it doesn't protect you against schema drift. Let's say before generating the migrations i went to the db and added an index on a table and forgot to write an migration for it. Prisma would have no idea that index exists and may generate invalid migrations! This problem is called schema drift. To protect and properly handle schema drift prisma uses a so called shadow database. Before doing anything prisma creates a NEW DATABASE, applies all existing migrations to the shadow database and then dumps the schema from the shadow database and the target database. Those schemas are getting diffed so prisma may detect schema drift and act accordingly. The shadow database is built into prisma and can't be disabled. Half of the prisma commands require it :) Now let's fire up wireshark and see how this works in practice. First set up wireshark to capture traffic on the electric proxy To properly support prisma electric-proxy should understand that when a connection is made to
With regards to https://discord.com/channels/933657521581858818/1165673468512182282 you came to the wrong conclusion there. Electric was created, installed and available in the main database but not in the shadow database. I also had this issue and that's why I had #651 (comment) in my migrations which checked if the electric schema exists before trying to electrify the tables. Otherwise prisma was unable to create the shadow database. |
@gorbak25 Thanks, that's a very clear explanation of how Prisma migrations work and why it fails on the current proxy. |
Sidenote: every push to |
I'm struggling to generate new db migrations using prisma.
The problem is that the electric proxy thinks that the shadow database is the main database. I'm right now trying to find a workaround for generating migrations.
The text was updated successfully, but these errors were encountered: