Migrating a local Cloudflare D1 database

I have a Cloudflare Worker with a few environments and databases. I've figured out how to migrate my staging and prod databases via this guide: https://orm.drizzle.team/learn/guides/d1-http-with-drizzle-kit. What I want to do now, is also run those migrations on my local database. This script allows me to access my local database, for example: yarn run wrangler d1 execute staging_db_1 --env=dev --local --file=./drop_tables.sql. How can I invoke drizzle-kit commands to run against my local database? I've tried removing the driver and dbCredentials values from the config in drizzle.config.ts, but I get Error Please provide required params: [x] url: undefined. I don't konw what URL I'd be expected to use if I'm drizzle-kit migrating a local database.
2 Replies
Jarrett
JarrettOP3mo ago
Is the current process just to use wrangler d1 execute for applying migration files to a local database? I don't see any examples online of using drizzle-kit migrate for local workers.
Magical.Puffin
Magical.Puffin3mo ago
Cloudflare D1 uses a local .sqlite file in .wrangler/state, one option is to just treat it like any other sqlite database and use better-sqlite3. The other option would be to use wrangler for managing all migrations.
Want results from more Discord servers?
Add your server