NeonN
Neon16mo ago
28 replies
spotty-amber

Preview deployments on tenants?

Hi, I have being working for a while on migrating our current database into a database per tenant architecture on Vercel and I'm almost done.

For preview deployment, we use the Vercel integration but what happend for tenant databases?
I have a script for migrations very similar to this one: https://github.com/neondatabase/db-per-tenant/blob/main/migrate.ts

The only difference is that when there is the env variable VERCEL_BRANCH_URL, then I want to create a branch with that name and apply the migrations to that branch. If there is not, then the migrations are applied to the main branch.

The only issue is that the current neon api (v2) doesn't allow to specify a branch name or a branch id, so now I'm kinda lost and I don't know how to proceed.

 const branch = await neonApiClient.POST("/projects/{project_id}/branches", {
  params: {
    path: {
      project_id: neonDatabaseId,
    },
    // Not possible :(
    query: {
      branch_name: process.env.VERCEL_BRANCH_URL,
    }
  },
})
GitHub
Example chat-with-pdf app showing how to provision a dedicated database instance for each user. In this app, every database uses pgvector for similarity search. Powered by Neon - neondatabase/db-pe...
db-per-tenant/migrate.ts at main · neondatabase/db-per-tenant
Was this page helpful?