How to implement Multi tenancy in FastAPI, SQLAlchemy and Postgresql? #6056
Replies: 4 comments
-
|
You should create or change schema by using |
Beta Was this translation helpful? Give feedback.
-
|
Depends on how much isolation you want. Let's say you work with SQL, you can either have a column (like @yinziyan1206 suggested), or have a independent table, or have a independent databases all together. For all of the above, you need to have dependency injection. You can on-the-fly determine the database name just before opening a new session (from DI). |
Beta Was this translation helpful? Give feedback.
-
|
I have written a script for onboarding clients but what if I have to made any change in table then what will be the steps? |
Beta Was this translation helpful? Give feedback.
-
|
I would recommend the solution described here https://aws.amazon.com/blogs/database/multi-tenant-data-isolation-with-postgresql-row-level-security/ It's framework agnostic, so you can just use postgres session variables and the SQLAlchemy event listener API |
Beta Was this translation helpful? Give feedback.

Uh oh!
There was an error while loading. Please reload this page.
-
First Check
Commit to Help
Example Code
Description
Found an Article but unable to understand how to implement dynamic schema generation when new client sign up on the portal.
so that any client access like
client1.mysite.com
client2.mysite.com
And schema generation should be on the fly if a new client signup
Operating System
Linux
Operating System Details
No response
FastAPI Version
0.88.0
Python Version
3.10.9
Additional Context
No response
Beta Was this translation helpful? Give feedback.
All reactions