Workflow with Planetscale
Hi Guys! I'm just curious what's your usual workflow when working with planetscale and you have schema changes? Because all the data will be lost after db push command. Does this not affect your development? Or do we have some best practices and tips? Thank you!
Btw do you just seed data needed for the app to work?
7 Replies
Don't you do any migrations 😅
hi @Sybatron, it's in the docs in prisma not to use migrations with planetscale. But should I use one? Sorry for the noob question and thanks for answering!
I havent done it yet but i have an Idea how to do it without losing data...
start with something like make a migration script to backup conflicting tables/data so that db push doesnt delete everything... then run db push and maybe afterward make another migration script to another restore and format the backed up data.
Planetscsle doesn’t use migrations.
You have branches. A branch can be a production branch or a dev branch.
You cannot db push on a production branch, it literally won’t let you.
To do schema changes:
1) change your schema file in such a way that data won’t be removed. If you add a new field to a table, add a default value, then go back and fill that value for the rest of the table entires. If you wanna drop a table make sure it’s empty that kind of thing. Do db push if you are running a docker/local db and see if that will warn you data removal. If it doesn’t move to the next step
2) in your env connect to your dev planetscale branch and do a db push
3) go to your planetscale branches, on the dev branch it will show you the changes. Generate a deploy request. It will check if it can do the changes without breaking anything, and if so just click deploy and it’s done
For that dont they need to turn on safe migrations on the production branch
So planetscale ensures we dont do breaking changes
Planetscale is like github but for your database
You develop (make changes) on a separate branch, review, approve, and merge to production when it's ready to deploy.
No I think it‘a like that by default