My approach to develop a multi-tenant i.e. Shared Database, Separate Schemas ideally on PostgreSQL. One database for all tenants, but one schema per tenant similar to django tenant schemas. Is there a guide or addon to achieve this on websauna?
My approach to develop a multi-tenant i.e. Shared Database, Separate Schemas ideally on PostgreSQL. One database for all tenants, but one schema per tenant similar to django tenant schemas. Is there a guide or addon to achieve this on websauna?
Here is what there is and there isn't
Already there
SQLAlchemy supports PostgreSQL tenancy. You can set this by overriding the database session factory when subclassing
websauna.system.Initializer
for your application. See configure_database that leads you to the path that allows to override create_dbsession. Your database session factory would look the properties of the HTTP request (domain) and configure session to point to the corresponding schema accordingly.Add-on architecture that could provide a pluggable
websauna.tenant
addonTheming: CSS and other assets (logo) can be customized by providing a
site/base.html
template that is a tenant aware. E.g. it injectscss.html
in<head>
with the ability to define CSS filenames from the database. You would override the defaultsite/base.html
in thewebsauna.tenant
addon.Missing
Alembic migration supports PSQL schemas, but not sure how complete this support is
There isn't
Tenant
model e.g. to track the subscriber billing status