Blazing fast NVMe drives with unlimited IOPS now available. Read about PlanetScale Metal
Navigation

Blog|Product

Automatically copy migration data in PlanetScale branches

By Taylor Barnett |

Never accidentally reapply a past migration again! We've removed another barrier to using PlanetScale branches with the framework or migration tool of your choice. Now, you can automatically persist schema changes in your migration table across database branches.

Many frameworks and migration tools keep track of database schema changes in a migration table that includes data about what migrations have been applied and in what order. Without that migrations table data, many tools will incorrectly try to reapply previous migrations, which would cause errors during migration. The migrations table is the missing link that shows how we arrived at the current schema by recording which schema migrations were applied.

In PlanetScale, you can now turn on the ability to automatically copy migration data from these tables any time you open a deploy request or make a new database branch. There are built-in options for Rails, Phoenix, Django, .NET, Prisma, Sequelize, or you can specify the migration table name used by your framework or migration tool.

You may ask yourself, "How does this fit into my existing workflow?" Good question! Here's an example workflow from PlanetScale Software Engineer, Iheanyi Ekechukwu, demonstrating a schema migration with Prisma in a TypeScript application:

While this demo is using Prisma, many frameworks and migration tools will use a similar workflow. You can see our migration tutorials with Prisma and Ruby on Rails in the docs.

Update: We now recommend using prisma db push instead of prisma migrate dev with a shadow branch. Read more in our documentation about prisma db push and PlanetScale.

Give it a try, and let us know what you think!