I’m trying to run database migrations for postgres using drizzle orm, and the migration function requires a path to the migrations folder. The path and migrations work fine locally, but whenever I deploy to production the path obviously isn’t available anymore. I attempted to copy the dir using package.js postbuild script, and while I can see the files in the netlify deploy file browser I still can’t access them from my db.js file during run time.
How am I suppose to execute the following migration function in production on Netlify?
–src/drizzle/db.js–
const db = drizzle(client, {schema})
const runMigrations = async () => { await migrate(db, { migrationsFolder: './src/drizzle'})}
runMigrations()
–package.json–
"scripts": {
"dev": "next dev",
"start": "next start",
"build": "next build",
"postbuild": "mkdir .next/src && cp -r src/drizzle .next/src/drizzle"
}
Folder structure in repo
As far as I know I can only reference paths in next.js by having the file live in the public dir. However, I don’t want to put my migrations in the public dir. What is the best way to solve this issue?