Run migration with Drizzle for Neon
Sorry if this is a n00b question, but I'm having some troubles running a migration of a Neon database locally with the env.js.
I'm trying to run this with the command
pnpm run db:migrate
in the terminal
This is the script in package.json: "db:migrate": "tsx ./src/server/db/global/migrate.ts"
This gives me an error about the environment variables, anyone have an idea what I could do to fix this? :
I only need the DATABASE_URL in this migration and this is defined so I'm not sure why I'm getting an error on this.
7 Replies
This is my migration file:
The error you're giving is that you don't have 3 ENV variables defined, not necessarily the migration file
Hmm all these variables are defined in my .env file though
But for some reason they're not picked up when running the scripts
They get picked up at runtime, but just not in this script
@Woet
pnpm/npm/yarn add dotenv
Inside of env js config file at the top
thanks @barry ! that idd did the trick
first time building some with the t3-stack, was expecting it to already take care of the need to import "dotenv/config";
nextjs handles it for you, but as you're outside of next when running the script on your own there's nothing to handle environment variables from .env
makes sense, thanks!