Doing multi-tenancy in Websauna

138 views Asked by At

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?

1

There are 1 answers

1
Mikko Ohtamaa On

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 addon

  • Theming: CSS and other assets (logo) can be customized by providing a site/base.html template that is a tenant aware. E.g. it injects css.html in <head> with the ability to define CSS filenames from the database. You would override the default site/base.html in the websauna.tenant addon.

Missing