DT
Drizzle Team•10mo ago
x03

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?
No description
18 Replies
x03
x03OP•10mo ago
still dont have a solution 😭 bumping this thread
Startup Spells 🪄 Newsletter Guy
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 up
Sandvich
Sandvich•10mo ago
Drizzle can make raw sql migration files. Can't you just apply those to your database without going through cloudflare?
x03
x03OP•10mo ago
That's what gets generated when you do drizzle-kit generate:pg right? How would I go about applying those migrations?
Sandvich
Sandvich•10mo ago
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
x03
x03OP•10mo ago
Interesting. I use postgres-js, I'll read into their docs later to see if they have a native migration tool.
Sandvich
Sandvich•10mo ago
Wait ur using postgres-js client and Drizzle ORM? I meant your hosting provider, like Neon or supabase idk
x03
x03OP•10mo ago
self hosted on a VPS
Sandvich
Sandvich•10mo ago
oh ok, yeah you should be able to run any sql migrations you want by ssh'ing in
x03
x03OP•10mo ago
Yep, manual migrations are super easy. I was looking for a way to automate it from my backend, which is on cloudflare workers
Sandvich
Sandvich•10mo ago
oh so maybe a github action to connect direct to the VPS and run drizzle migrate push in that?
x03
x03OP•10mo ago
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 😅
x03
x03OP•10mo ago
GitHub
GitHub - porsager/postgres-shift: A simple forwards only migration ...
A simple forwards only migration solution for postgres.js - porsager/postgres-shift
x03
x03OP•10mo ago
might try this out reading some issues from the postgres.js github, people seem to be sharing some of their migration libraries
Sandvich
Sandvich•10mo ago
If you're pushing to github and then cloudflare watches that, you could still run your own GH actions in your repo right?
x03
x03OP•10mo ago
Actually yeah, I think so. I've never tried it but it makes sense
Sandvich
Sandvich•10mo ago
I get it's not ideal, and there's no out of the box solution which sucks
x03
x03OP•10mo ago
I'll definitely look into that, thanks for the suggestion.
Want results from more Discord servers?
Add your server