Metabase for SaaS

We’re looking into using Metabase integrated with our SaaS solution for customers to have a deeper look into their data. Each of our customers have a unique database so we need to be able to dynamically change the data-source for Metabase. Is this possible? Has anyone achieved using Metabase in a SaaS?

If you’re a Metabase expert available for hire for this project, I’d love to hear from you too :slight_smile:

1 Like

Do you mean one installation, one set of questions/dashboards, but change the connection on the fly? If so, then No.
If you mean a separate installation for each customer, then you could use the API to dynamically create the questions and connections (bit beyond my abilities at the moment).
You could just have multiple metabase databases (one for each customer) with their question in. Not difficult to clone, then edit.
Alternatively, just use the source database security to use a different schema depending upon the database username.

Yes, I’m available for hire, though my Clojure skills aren’t up to modifying metabase yet.

1 Like

Hi Andrew. Yeah, we want to have one installation and one set of questions/dashboards but change the input on the fly. With multiple installations, I suppose it would end up being quite heavy on our servers to run 2000 installations of Metabase.

1 Like

It’s not out of the box, however:
If you’re embedding (rather than allowing users to login to Metabase), you can set a filter parameter based upon the user. This can be used to filter the query so that only a single customer’s data is retrieved.
If multiple databases, you need to use the filter to select the database schema, but that varies by database and limits you to using custom queries.

1 Like

Hi Andrew, great comments. I have the same issue and have been trying to explore the route to filter the database to select the Schema based on the tenant (customer), but seems like maybe Metabase has disabled that as a possibility? Was trying to use the {{variable}} to pass the schema name through in the queries.

@AndrewMBaines @Johann Were you able to implement a solution this way?

1 Like

I’ve had a play with selecting both table name and schema using variables. I can’t get it to work - it looks like it’s something to do with how Metabase or the SQL driver are passing the variable names.

There are a few options when using Stored Procedures though.

CREATE PROCEDURE [dbo].[SchemaTable] 
	@TableName nvarchar(50),
	@SchemaName nvarchar(50)
	DECLARE @query nvarchar(1000)
SET @query  = 'Select * from ' + @SchemaName +'.' + @TableName
EXECUTE sp_executesql @query

Downside is that dynamic SQL like that is inefficient as the database has to recalculate the Query Plan every time.

Variants on that would just work for one table. Better from the Metabase perspective as the same columns would be returned every time.
Still have the issue of it not showing in the question builder so you have to design using SQL all the time.

1 Like

@AndrewMBaines That seems like it could work. In my case, I really only have to build questions and add to a dashboard 1 time, I just need my tenants to only see their data. I am using PostgreSQL so I think the syntax may be a little different, but i am going to give it a shot. Thanks for the suggestion, I’ll update if I can make it work.

@wrodg219 were you able to acchieve this? Can you provide details of how you got it working?

@NaveenHadagali Unfortunately, no. We had to go with a custom python solution utilizing Plotly, vue/vuetify. Doesnt seem like multi-tenant application is high on MB priority list.