Local Testing for D1?

before, to test locally with drizzle and d1:
"gen-local-db": "npx drizzle-kit generate:sqlite",
"init-local-db": "npx wrangler d1 execute clients --local --file=$(ls ./drizzle/*.sql| head -1)"
"gen-local-db": "npx drizzle-kit generate:sqlite",
"init-local-db": "npx wrangler d1 execute clients --local --file=$(ls ./drizzle/*.sql| head -1)"
i used to do this, i am aware :sqlite is deprecated since we have a config file. but initializing a local db no longer works: ✘ [ERROR] near ")": syntax error at offset 57: SQLITE_ERROR I looked into the push command but it looks like it directly applies changes to the production database? What is the correct way to create a local database now.
5 Replies
Angelelz
Angelelz5w ago
This seems to be a syntax error. Maybe that shell is not producing the result you're expecting? I've worked in projects where we have different config files that you can pass to drizzle-kit cli with the --config option
Hearse
HearseOP5w ago
Prod vs dev config, the only thing is, how would i make a local database that i can use for d1 local development
Angelelz
Angelelz5w ago
Not familiar with d1, maybe someone else can help
Hearse
HearseOP5w ago
Unfortunately there are not enough people to help I will try to figure it out man Found out the issue, when using wrangler to apply migrations to the local database. the migration file included an empty table that i defined and forgot about:
CREATE TABLE `subscriptions` (

);
CREATE TABLE `subscriptions` (

);
maybe there should be a warning shown when generating tables that are empty? I am not sure, but if this is intended behavior, my apologies SOLVED
Timbolicious
Timbolicious3w ago
Maybe also check this dynamic config for d1 this other thread: https://discord.com/channels/1043890932593987624/1265077849002475571 I have these scripts added to my package.json:
{
"scripts": {
// other scripts
"db:local": "wrangler d1 execute remix-test --local --command='SELECT 1'",
"db:reset-local": "rm -r .wrangler && bun db:local",
"db:studio": "drizzle-kit studio",
"db:push": "drizzle-kit push"
}
}
{
"scripts": {
// other scripts
"db:local": "wrangler d1 execute remix-test --local --command='SELECT 1'",
"db:reset-local": "rm -r .wrangler && bun db:local",
"db:studio": "drizzle-kit studio",
"db:push": "drizzle-kit push"
}
}
db:local is needed to create the local DB if it not yet exists in the .wrangler directory db:reset is needed to use push when the table already exists. I don't like this though. Is there another way you know about? Would be nice if push would use CREATE TABLE IF NOT EXIST to prevent such errors.
Want results from more Discord servers?
Add your server