hi everyone, I have a question regarding migration...
# orm-help
t
hi everyone, I have a question regarding migration. All of the scenario is against my local db. • Let’s say I have a main branch where migration 1 is the latest. • I then create feature 2 branch and make a new migration 2. • When I finish with feature 2, I then go back to main branch and create new branch for feature 3. At this point, my db is having the changes done by migration 2. How can I correctly create a migration 3 for this branch? Currently, whenever I do it, it will ask me to reset db since the number of migration is not similar (migration 2 doesn’t exist on this branch). So a couple of Qs beside that too: • how should I deal with that when this get merged and deploy? Will Prisma asks my prod db to reset too? • Will it be any different if I choose to merge feature 2 before or after feature 3? Remember that feature 2 is done before feature 3, so technically speaking, when both are merged, migration 2 will be before migration 3 • Am I doing this one wrong? I keep having the feeling that I should make a separate branch to update the db and merge it to the main branch asap to allow other branches to have access to the migration, but it doesn’t always feel right to do it.
j
https://www.prisma.io/docs/reference/api-reference/command-reference#examples-11 This might be help you to migrate with some migration files
t
tks but I can't see how it's helping my case. Can you specify more?
j
If I understand correctly, you don't need to run migration at the beginning which enforce you to delete or data right?
t
in my scenario, I would have to create a migration 3 on feature branch 3. This will enforce prisma to run migration AFAIK
j
So you need to run
migrate resolve --applied <YOUR MIGRATION FILE
to apply only migration script that you want
t
so you are saying that after you create the migration file, you then force prisma to run your migration?
but wouldn’t that make the db different from what your schema contains?
j
Could you run
migrate deploy
instead to prevent your lost data?
before run, backup your data
Sorry I misunderstand you question
t
migrate deploy
would just deploy the changes to prod env, right? I have just read through the docs and it mentions that it won’t reset the prod db. Is that what you mean?
j
yes
t
ah okay. I thought you were talking about the multiple migrations on multiple branches. Any ideas on that one though?
j
From my experience I met this situation only one time. my solution at that time was to merge all migration files to one branch, backup data and run migration files