W
Wasp4mo ago
Conspyre

General Q: on every branch switch, wasp/prisma wants to make a new migration, is this the right way?

If I have a feature branch B and I switch back to branch A, it seems that prisma wants to create a migration to get the database back to the state which is A. When I switch back to feature branch B, it seems that prisma wants to create a migration to get back to that state. [repeats] Is this the usual development paradigm? Creating new migrations each time we bounce to a different branch, or have I missed the proper workflow here?
3 Replies
kapa.ai
kapa.ai4mo ago
Hi @Conspyre. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave: ---------------------- Yes, this is the expected behavior when using Wasp with Prisma. When you switch between branches, if there are changes in the schema (entities), Prisma detects these changes and wants to create a new migration to align the database with the current state of the schema. This is done using the wasp db migrate-dev command, which generates a new migration and applies any pending migrations to the database source (https://wasp-lang.dev/docs/general/cli#database-commands). This behavior ensures that your database schema is always in sync with your application's schema, which is crucial for the correct functioning of your application. However, it's important to note that this is primarily a development workflow. In production, you would typically apply migrations manually or as part of a deployment process to ensure control over when and how schema changes are applied. If you find this workflow cumbersome, you might want to consider structuring your work in a way that minimizes the number of times you need to switch between branches with different schemas. ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ---------------------- Sorry @Conspyre, I seem to be having a bit of trouble. Don't worry though, I've pinged my support and they will try to fix me up! :technologist: Perhaps try again in 15mins?
miho
miho4mo ago
Bot gave a good answer. If you have different entities in those two branches - the only way to get the DB to the shape it needs to be for your app to work properly is to do migrations. If you want to develop two different apps, maybe it's better to have two different apps instead of two different branches. If you are developing two different versions like v1 and v2, in development it's normal to have to change the DB on each branch change. One trick I can offer is: clone the repo twice and have v1 in one folder and v2 in a second folder. This way the Wasp development DB will be different (becasue it's tied to the location on disk) and you won't need to change the DB constantly.
martinsos
martinsos4mo ago
Interesting question @Conspyre ! What Miho said, or, have two different dev databases, and on each branch make sure you connect to the corresponding branch! This means you wouldn't use wasp start db, but instead you would run these databases on your own, and you would have to make sure to set DATABASE_URL correctly as you switch branches, that is a bit tricky maybe though hm. You could have a script for each branch that does that. What could be super cool is if, when doing wasp start db, you could pass a "name", so that you can create a named database in that fashion. That means that you could do wasp start db "branch1" and then wasp start db "branch2" and you would be using different databases. Ha that sounds great. We don't offer this yet but wouldn't be super hard, I think. Here is the issue we have for this, I added this convo to it: https://github.com/wasp-lang/wasp/issues/1972
Want results from more Discord servers?
Add your server