`no such table: user` in production with drizzle + sqlite + next.js?
i have 2 sqlite databases:
1.
example.dev.sqlite
- for development
2. example.prod.sqlite
- for production
i know how to use drizzle in development but i'm having a problem in production.
in development, i do pnpm db:generate
to generate migrations & pnpm db:push
to create tables.
what should i do in production to generate tables? do i have to run the same pnpm db:push
script?
my sqlite file is in docker swarm so the location is a bit different.
my drizzle.config.ts
file looks like:
would i need to change DATABASE_PATH
. im confused here as i am unable to get it to work in production?
my goal is to simply get the production sqlite database working. if anyone has done it before, lmk what's the process? google didn't help much.3 Replies
alright, i was able to make it work through my code search skills. i searched for
context:global migrate AND drizzle lang:TypeScript -repo:^github\.com/drizzle-team/drizzle-orm$
on https://sourcegraph.com
this repo answered it -> https://sourcegraph.com/github.com/ixartz/Next-js-Boilerplate@9845272ef4ea729f0101e035262b4be8c0082303/-/blob/scripts/dbMigrate.ts
i've only managed to get it working locally on production build ,i.e, next build
& next start
(which builds for production in case you don't use next.js) but i think i can manage it on vps too.
so i made a scripts/drizzle-migrate.ts
file:
i added that to my package.json
:
in development, i run db:migrate:dev
script & i run db:migrate:prod
in production.
maybe i can consolidate it with NODE_ENV
but then i'll have to hardcode database name in code.
one way i can think of is using:
Sourcegraph
Sourcegraph | Code Intelligence Platform
Sourcegraph’s code intelligence platform makes it easy for devs to write, fix, and maintain code with Cody, the AI coding assistant, and Code Search.
i tried this method:
but it was not better than my original answer.
here's my scripts:
and some explanation i wrote:
1.
pnpm db:generate
(dev) - Generate src/app/db/migrations
2. pnpm db:push
(dev) - Pushes the schema to database & creates example.dev.sqlite
file. Only use it when developing schema locally as it is never to be used in production.
3. pmpm db:migrate
(dev/prod) - Works in both environments
4. pnpm dev
- Runs pnpm db:migrate
with NODE_ENV=development
5. pnpm build
- Runs pnpm db:migrate
with NODE_ENV=production
Any script that contains drizzle.config.ts
file is only for development.
drizzle.config.ts
scripts/drizzle-migrate.ts
@Andrew Sherman i think this should be in the docs of running sqlite in development & production with drizzle orm. lmk if i made any mistakes.better solution using docker -> https://stackoverflow.com/a/78034626/6141587
Stack Overflow
Cannot find package 'drizzle-orm' in Docker Container even though I...
I install all my dependencies in Dockerfile using npm ci below.
Dockerfile
FROM node:20-alpine AS base
1. Install dependencies only when needed
FROM base AS deps
Check https://github.com/nodejs/