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 -> 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...
Jump to solution
4 Replies
Solution
traches
traches13mo ago
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 - success Pretty 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)
dollahane23033
dollahane2303313mo ago
I’m reading this out of interest, were you having issues updating an existing drizzle schema ?
traches
traches13mo ago
I over-abstracted and added an association where I really only needed a boolean. Updating the schema is easy enough with db:push, but I also need to update all the existing records in prod - set new boolean column to the value of whatever the association is. That’s where my trouble was.
Dari
Dari10mo ago
the --custom flag worked for me. But how do you call drizzle's provided migrator function appropriately? Because im getting an ERR_UNKNOWN_FILE_EXTENSION error
Want results from more Discord servers?
Add your server