Too many Prisma migration files
Asked Answered
P

3

6

I'm currently working on a project that we are using Prisma 2 and postgreSQL as database support. From my understanding, whenever I made changes to the schema.prisma file and I want to migrate the changes to the database, I run prisma migrate dev locally. Then I will push the auto created migration files under migration folder to Github, and then our repo will run prisma migrate deploy to the staging or production server.

So, my concern is, each time I run prisma migrate dev, a new migration file will be created in migrations folder. So, there will be a lot of migration files under the migration folder with the development of the project. Is that what supposed to happen? Or is there a better way?

Thank you for your help. I'm pretty new to Prisma 2 and still trying to find the correct way to work with it. BTW I think Prisma 1 was easier to use :)

Pituri answered 20/10, 2021 at 17:16 Comment(1)
If the number of files ever becomes an issue, you could reset by replacing all of the migration files with one file that is the output of pg_dump or equivalent. prisma.io/docs/guides/database/developing-with-prisma-migrate/…Warty
D
9

I’d recommend using prisma db push while developing locally and generating the migration with prisma migrate dev only when you think the schema changes are good to go. More at https://www.prisma.io/docs/guides/database/prototyping-schema-db-push

Damicke answered 13/11, 2021 at 6:19 Comment(1)
Ohhh... I'm misusing it while developing. Thank you!Covey
F
3

So, there will be a lot of migration files under the migration folder with the development of the project. Is that what supposed to happen?

Yes, this is exactly what's supposed to happen. The migration file contains the history of all changess to your Prisma schema (and underlying database tables/configuration), so they all need to be retained.

I'm not sure if you could go around this somehow, but it's certainly not the recommended way to be using migrate.

You can find a list of best practices regarding migration in the Prisma migrate article in the docs.

Factor answered 21/10, 2021 at 1:20 Comment(0)
W
0

It's been a very long time since the question is asked, but i want to warn about something:

As you may notice a table named _prisma_migrations is created by prisma automaticly and every time you add a new migration you are able to see the new migration's data over there. So any manual change made in migrations folder can cause problems since it breaks the relations between folder names and _prisma_migrations table.

Also docs for "squashing migrations": https://www.prisma.io/docs/guides/database/developing-with-prisma-migrate/squashing-migrations

Wolpert answered 24/1, 2023 at 19:59 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.