Skip to content

Automatically copy migration data in PlanetScale branches

Use PlanetScale branching with the database schema migration tools of your choice

Automatically copy migration data in PlanetScale branches

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 throw errors on migration. The migrations table is the missing link for the "how" we got to the current schema by persisting "what" 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 name of your framework or migration tools’ migration table name.

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, walking through doing 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!