Guidance on Creating a Multi-Tenant Application with PostgreSQL Schemas
Hi friends,
I’m working on creating a multi-tenant application where each tenant is assigned a separate PostgreSQL schema. I have a few questions and would greatly appreciate your insights:
What is the best approach to implement this kind of multi-tenancy?
I’m considering using an environment variable to manage the list of tenants. My goal is to ensure that when I run drizzle push, it modifies the schemas for all tenants automatically.
Is this approach feasible? Unfortunately, I couldn’t find much information online, so any advice or resources you could share would be immensely helpful.
Thank you very much for your time and support!
Best regards,
Montgomery Burns
6 Replies
Hi @Montgomery Burns , have you made any progress on this effort? I'm about to go down the same journey and curious as to what you found / did thus far?
In the context of Drizzle, I don't see how you could manage this automatically. Drizzle-kit needs to know about your schemas to push (schemaFilters config options). And you need to pass your schemas to the drizzle initializer to query.
In the context of postgres, schema-level tenacy very much a thing people do a lot and I just recommend you search the web for implementing that with native Postgres or maybe some other ORM can handle it.
Maybe I'm wrong but I don't think so
Also maybe open a issue and see if this is something others want
I was doing some research earlier today and stumbled upon Nile Postgres. I actually use Better Auth with Drizzle and there is a Nile plugin for Better Auth that adds a lot of this multi-tenant capabilities.
Citus Data
Download Citus Open Source to use PostgreSQL at any scale
Download Citus open source to distribute your Postgres tables and parallelize your queries. Start small on a single node or scale to a large cluster. Useful for multi-tenant SaaS, real-time analytics dashboards, & time series. Also available as a managed service with Azure Cosmos DB for PostgreSQL.
Oh, Nile actually looks interesting.
Yeah, I'm hoping that combination will provide the solution that people are looking for in this matter: https://www.thenile.dev/blog/better-auth-nile
Introducing Nile plugin for Better-Auth - community edition
Build multi-tenant applications with Better Auth and Nile, using a plugin contributed by the Nile community