N
Neon2y ago
fair-rose

Timeouts during Drizzle Migration

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 Drizzle's migrate function and the Neon database 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: './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 or if there's a bug
6 Replies
deep-jade
deep-jade2y ago
Hi. How are you creating a new database? Via the Neon API? If you're doing using the API, it might take a few seconds before the database is available. You need to make that there is no on-going operation. Also, if I get it right, all new user databases share the same schema. Why not just create a branch for each new user?
fascinating-indigo
fascinating-indigo2y ago
l'll add that it's possible to poll Neon API operation status: https://neon.tech/docs/manage/operations#poll-operation-status
Neon
Operations - Neon Docs
An operation is an action performed by the Neon Control Plane on a Neon object or resource. Operations are typically initiated by user actions, such as creating a branch or deleting a database. Other ...
fair-rose
fair-roseOP2y ago
Yea through the API. Ahh so what I'm understanding is that even when it returns, it doesn't necessarily mean the database is ready for running queries/migrations against. Is that right? And yea all new user databases will share the same schema, but there is a limit to the number of branches, while databases are unlimited. What would the benefit be to use branches over databases in this scenario? This seems like what I want to do
fascinating-indigo
fascinating-indigo2y ago
Right. Provisioning a database is fast, but it might take just a little longer than it takes to execute your next action like running a query or migration, so it's best to ensure that the create database operation has finished.
fair-rose
fair-roseOP2y ago
awesome thanks looks like this is working @raoufchebri so it looks like i actually do want to use branches so i can do point in time restores by customer (noticed that the pro plan has unlimited branches). im redoing my logic to check for when the branch is ready to run queries against, which operation should I be polling for on branch creation to check for its status === finished to indicate that its ready to be used? 'create_branch'?
deep-jade
deep-jade2y ago
Techincally, you can create branches from a branch that only contains schema (no data). That will avoid the point in time recovery step.
which operation should I be polling for on branch creation to check for its status === finished to indicate that its ready to be used?
Yes correct.

Did you find this page helpful?