"drizzle-orm/planetscale-serverless/migrator" in cf workers

Hey guys in cf workers you don't have access to the file system, how hard would it be to provide migrations to the migrate function? something like this:
import {migrate} from "drizzle-orm/planetscale-serverless/migrator";

await migarte(db, `CREATE TABLE...`)
import {migrate} from "drizzle-orm/planetscale-serverless/migrator";

await migarte(db, `CREATE TABLE...`)
5 Replies
Andrii Sherman
Andrii Sherman11mo ago
cc @alexblokh @Dan Kochetov
alexblokh
alexblokh11mo ago
hey, @chronark SQL migrations with D1 are not supposed to be run within worker, those should be run with Wrangler I suppose our current format is interoperable with the one expected by wrangler
chronark
chronarkOP11mo ago
oh I'm not talking about d1, but mysql/pscale but that's not really the point I know I'm hacking here the idea is to offer a docker image of our api (I have it running using workerd and have an api route on it, that would migrate the attached db + seed data basically you'd do
docker run unkey/api:latest
curl http://localhost:8787/v1/seed
docker run unkey/api:latest
curl http://localhost:8787/v1/seed
I know there are other ways to achieve it, but this would be pretty nice the problem is that the migrate function tries to read the migration files from the file system, which is just not really a thing in workerd, but I could embed these during docker build time
baronnoraz
baronnoraz11mo ago
I would love the ability to do something similar, run the migrate programmatically without having to do a generate and migrate. https://discord.com/channels/1043890932593987624/1202633333536718908
alexblokh
alexblokh11mo ago
@chronark I sort of grasp what you're trying to achieve on AWS there's a custom resource lambda which is invoke during deployment which is supposed to run migrations for the serverless environment by having curl http://localhost:8787/v1/seed you sort of mimic that but it will run after the actual infra deployment which can lead to race conditions for your usecase I would say something like what we have for Expo is the potentially the best solution let the bundler pack SQL files into the bundle for this lambda or just pack and expose SQL files in your workerd container if that still doesn't suite your needs - I'd love to hop on the call and groom through potential solutions yeah, that's something we've discussed internally and are aiming to do we didn't prioritise it since we already have push which sort of partially solves the issue for now
Want results from more Discord servers?
Add your server