Drizzle & Planetscale data migration workflow
Tagged as "databases" because there's no Drizzle tag.
I'm running T3 + Drizzle + Planetscale. I've been using a planetscale branch ->
Drizzle-kit claims to be able to do this with
Do I have to implement this myself? Make a migrations table, track which migrations have been run, call the ones that haven't? Is there some other way? I can't be the only one with this issue.
I'm running T3 + Drizzle + Planetscale. I've been using a planetscale branch ->
db:push -> deploy request workflow for managing schema changes, which I like a lot. This doesn't handle modifications to existing data however, so I still need a way to run a set of SQL commands against an existing database exactly once.Drizzle-kit claims to be able to do this with
drizzle-kit generate:mysql --custom, but this doesn't generate an empty SQL file for me like the docs say it will. On first run it creates all the tables in my schema, and subsequently it says there aren't any changes to make and it does nothing. (In other words it seems to ignore the --custom flag).Do I have to implement this myself? Make a migrations table, track which migrations have been run, call the ones that haven't? Is there some other way? I can't be the only one with this issue.
Solution
Update: I figured out a workaround:
- Make a random schema change
- run
drizzle-kit generate, and since drizzle thinks a schema change is needed it will actually generate a SQL file - Discard said schema change
- Replace generated SQL with whatever UPDATE statements I need
- call drizzle's provided migrator function as appropriate
- successPretty sure ignoring the `--custom` flag is a bug, though. I've got an issue open on drizzle-kit's github about it (dont dox me pls)