Multi-tenancy with one db schema per tenant

We have a SasS project with a multi-tenant setup, so each tenant has its own postgres database, but hosted on the same server.
What is the best way to provide them access to the data, in terms of data source configuration?

Hi @lirimici
Have you looked at this?
https://www.metabase.com/learn/permissions/multi-tenant-permissions

Hi @flamber, I slipped a mistake in my initial message. We have a database per tenant.
I assume we need to create a datasource per tenant.
Our end goal is to provide access to the same dashboards, but only the databases would differ for each tenant.

Also, is there an api to do this programatically, as we can constantly add new tenants on the fly?

@lirimici The easiest way would be to consolidate all your databases in one warehouse, but otherwise yes, you would have to create a connection for each.

There's Serialization to duplicate environments more easily:
https://www.metabase.com/docs/latest/enterprise-guide/serialization.html

And there's an API to do everything you can do in the Metabase interface:
https://www.metabase.com/docs/latest/api-documentation.html

Continuing the discussion from Multi-tenancy with one db schema per tenant:

pip install multischema-metabase-dashboard-helper
to use this you must modify your dashboard template's cards to SQL query via the ui option or however
can be used like this
from metabase_api.metabase_api.api_client import MetabaseAPIClient

api_url = "https://your.metabase.url.com"
username = "username@username.com"
password = "password"
database_id = 2
api_client = MetabaseAPIClient(api_url, username, password, database_id)
from_dashboard_id = 39 # Replace with the actual dashboard ID you want to use as a template
collection_id = 29 # Replace with the actual collection ID you want to output the dashboards to
collection_position = 1
is_deep_copy = True
old_schema = "the existing dashboard "from_dashboard_id"'s db-schema name you want to find and replace"

api_client.update_dashboards_for_schemas(from_dashboard_id, collection_id, collection_position, is_deep_copy, old_schema)

I wouldn’t solve this like this but rather using a unified schema and then use sandboxing, it’s more sustainable in the long term

1 Like

Please Can you share steps to full-fill, i just move on here so exploring right way. what should i do implement multi-tenant for SaaS product.
i'm running metabase in my server can i implement multi-tenant with that?
so that users will see their dashboards with their ones, no-one can sees others data
how can i do that can you explain.

check Embedding overview

1 Like

hi Luiggi, where database level privacy is required and all dashboards & queries are same, isnt the idea suggest by 3mawy correct? Also, can you please elabore or share some link to your idea of "unified schema and then use sandboxing"?

I should have check the example first and i just gone through it at the following links:

These seems good for the granular control at the data. but this will not get self service flexibility i.e. same dashboards are shared accross multiple users, who are able to see the dashboard data extracted from the database meant for him.