How do I apply migrations on cloudflare workers?
I have a sveltekit cloudflare pages project, and everything works fine until I try to apply migrations.
I use the postgres-js adapter.
The issue is that certain node libraries cannot be used with cloudflare workers, and the postgres-js migrator seems to include node:fs, which is not supported. (image attached below of the build error)
Is there any alternative way to apply migrations that work on cloudflare workers?
18 Replies
still dont have a solution 😠bumping this thread
this probably means cloudflare doesnt have
node:fs
right? find the equivalent of node:fs
in cloudflare. i think since it is in node_modules
, then you'll have to use patch-project dependency & patch it yourself. dont know how other cloudflare people do it. maybe search on sourcegraph drizzle AND cloudflare lang:TypeScript
to see if anything shows upDrizzle can make raw sql migration files. Can't you just apply those to your database without going through cloudflare?
That's what gets generated when you do
drizzle-kit generate:pg
right? How would I go about applying those migrations?Depends on what postgres provider you're using but I'd hope they'd have some way of connecting to the database so you can run migrations
Interesting. I use postgres-js, I'll read into their docs later to see if they have a native migration tool.
Wait ur using postgres-js client and Drizzle ORM? I meant your hosting provider, like Neon or supabase idk
self hosted
on a VPS
oh ok, yeah you should be able to run any sql migrations you want by ssh'ing in
Yep, manual migrations are super easy. I was looking for a way to automate it from my backend, which is on cloudflare workers
oh so maybe a github action to connect direct to the VPS and run drizzle migrate push in that?
I wish it was that easy, but sadly CloudFlare pages does not use github workflows, and instead has their own build system
and if I was to do a custom setup using github actions, I would be trading off the dashboard features that cloudflare provides with their integration
CloudFlare Pages is sort-of limiting, and I hope that can change soon 😅
GitHub
GitHub - porsager/postgres-shift: A simple forwards only migration ...
A simple forwards only migration solution for postgres.js - porsager/postgres-shift
might try this out
reading some issues from the postgres.js github, people seem to be sharing some of their migration libraries
If you're pushing to github and then cloudflare watches that, you could still run your own GH actions in your repo right?
Actually yeah, I think so. I've never tried it but it makes sense
I get it's not ideal, and there's no out of the box solution which sucks
I'll definitely look into that, thanks for the suggestion.