Migration timing out in Next.js Route

I am building an app where I am provisioning user's their own databases in Neon. I am currently running into an issue where after I create the user's database and connect to it, I try and run the migrate function and it just times out. Not sure if I'm doing it incorrectly or not. I tried with two variations of the path to the migrations folder:
await migrate(userDb, {
migrationsFolder: path.join(process.cwd(), 'drizzle/user/migrations'),
});
await migrate(userDb, {
migrationsFolder: path.join(process.cwd(), 'drizzle/user/migrations'),
});
await migrate(userDb, {
migrationsFolder: './drizzle/user/migrations'
});
await migrate(userDb, {
migrationsFolder: './drizzle/user/migrations'
});
Neither have worked. I know this isn't a typical use case but I'm not sure if I'm doing something wrong, it's not supported or if there are any workarounds?
4 Replies
energistic
energistic12mo ago
I find my migrations succeed but never really end. I added a process.exit(0) at the end and that seems to work. I also close the db connection but not sure if that's really necessary
Bardia
BardiaOP12mo ago
@energistic im a bit confused, so you await the migration and then run process.exit(0) or do you run it without awaiting and then process.exit(0)? And are you using pg? If so, how do you close the db connection, doesn't seem to be an option to from the docs
energistic
energistic12mo ago
here's my migration file:
import 'dotenv/config'
import { migrate } from 'drizzle-orm/postgres-js/migrator'
import postgres from 'postgres'
import { db } from './db2.server.ts'
export const connection = postgres(process.env.DATABASE_URL)
// This will run migrations on the database, skipping the ones already applied
await migrate(db, { migrationsFolder: './drizzle/migrations' })
connection.end()
process.exit(0)
import 'dotenv/config'
import { migrate } from 'drizzle-orm/postgres-js/migrator'
import postgres from 'postgres'
import { db } from './db2.server.ts'
export const connection = postgres(process.env.DATABASE_URL)
// This will run migrations on the database, skipping the ones already applied
await migrate(db, { migrationsFolder: './drizzle/migrations' })
connection.end()
process.exit(0)
Bardia
BardiaOP12mo ago
ahh im using node postgres, which doesnt seem to have the same methods available
Want results from more Discord servers?
Add your server