Tenancy
Keep each client's data separate
Set up tenancy so each client sees only their own rows, in Databrain and in every embed.
Do these five things once per workspace. After that, every guest token shows one client’s rows only.
Before you start
- You are an Admin or a Developer, or your role has the Edit Tenancy Level permission.
- The datasource is connected and synced.
1. Set tenancy
-
Pick the shape your data has. See Choose a tenancy model.
Tenancy Your data clientIdin the guest tokenTable Shared tables with a client column, for example client_idA value of the Primary key column of the Customer table, for example acme-corpDatabase One schema per client on one connection The client’s schema name, for example acme_corp -
Set it on the datasource. See Set tenancy on a datasource.
-
If the workspace uses a datamart, set it on the datamart too. The datamart’s tenancy wins. See Set tenancy on a datamart.
2. Limit every metric to one client
Databrain does not add a client filter to a metric for you, unless you use automatic client scope. Each metric that reads client rows needs one of these. All three keep each client’s rows apart. If one of them already works for you, keep it.
| Way | Use it when | How |
|---|---|---|
| Client filter or client placeholder | One dashboard serves every client | Builder metric: select Add client filter. Custom SQL: add the placeholder, see below. Databrain fills in clientId from the guest token. |
| Metric app filter on the client column | Your guest token already carries the client’s ID | Add a metric filter on the client column with App Filter on. Your backend sends the value in params.appFilters. See Set metric filters from the token. |
| Fixed client value in custom SQL | You make one dashboard for each client | Write the client’s value in the SQL, for example WHERE org_id = 'org-42'. In each guest token, send only that client’s dashboard in params.allowedEmbeds. |
If the metric editor shows This metric shows all clients, check the rows with two guest tokens (step 5). If a token sees another client’s rows, select Add client filter on a builder metric, or Edit SQL on a custom SQL metric. If a token opens another client’s dashboard, the metric is not the cause: send only that client’s dashboard ID in params.allowedEmbeds. This notice reads the metric setup only. It cannot see the values a guest token sends, so it can show on a setup that works, and it can miss one that does not.
On a dashboard, select one client in the client menu. If the header shows 1 metric shows all clients, check that metric the same way. This header also reads the setup only. The client menu is only for previews in Databrain. Embeds use the guest token.
Custom SQL metrics: add the client placeholder
Use the placeholder when one custom SQL metric serves every client. Databrain replaces it with the token’s client when the query runs. Write it in the SQL yourself.
On Table tenancy, compare your client column to 'client_id_variable'. The SQL editor suggests it when you type '.
SELECT order_date, SUM(amount) AS revenue
FROM public.orders
WHERE client_id = 'client_id_variable'
GROUP BY order_date- Keep the quotes, also when the client key is a number. Databrain removes them for a number key.
- Filter each table that holds client rows. A shared lookup table, such as a country list, needs no filter.
On Database tenancy, put {{DATABASE_NAME}} where the schema name goes. Databrain replaces it with the client’s schema:
SELECT order_date, SUM(amount) AS revenue
FROM {{DATABASE_NAME}}.orders
GROUP BY order_dateA metric app filter or a fixed client value also scopes a custom SQL metric, as in the table above. So do a token app filter on a table the SQL reads (see step 4) and automatic client scope.
A custom SQL metric with none of these shows every client’s rows in an embed. If the SQL editor shows Every client sees all rows of this SQL, check the rows with two guest tokens (step 5) before you change the SQL. You can still save it.
Databrain can turn on a stricter tenancy check for a company. It is off by default. When it is on, a guest token with a client on Table or Database tenancy cannot run a metric your team made that has no client placeholder, no row filter from the guest token that applies to its query, and no automatic client scope. Viewers then see Not set up for your account. This check does not read a fixed client value in the SQL.
3. Send clientId in the guest token
Your backend sends the client in clientId when it creates a guest token.
{
"clientId": "acme-corp",
"dataAppName": "Customer Analytics"
}- With tenancy set, Databrain checks the value against your clients. An unknown value can fail with
CLIENT_ID_ERROR. Thehintsays what a valid value is. For a new client on Database tenancy, run Sync schema first. - With no tenancy set, the API still requires
clientId, but Databrain does not use it to filter rows. The token sees every row the data app shows. Databrain uses the value only to keep each person’s own dashboards and layouts apart. To filter rows, set tenancy or use app filters.
4. Narrow rows with app filters
App filters take their values from the guest token. Viewers cannot change them.
| Token field | What it filters |
|---|---|
params.tableAppFilters | Every query that reads the table |
params.dashboardAppFilters | One dashboard filter that has App Filter turned on |
params.appFilters | One metric filter |
Example: lock the dashboard filter named region for one client.
{
"clientId": "acme-corp",
"dataAppName": "Customer Analytics",
"params": {
"dashboardAppFilters": [
{
"dashboardId": "YOUR_DASHBOARD_ID",
"values": { "region": ["Europe"] }
}
]
}
}The key in values is the Filter Name of the dashboard filter. See Set dashboard filters from the token and Control access for each tenant.
App filters can narrow rows inside a client. An app filter on the client column also keeps clients apart, as in step 2.
Cross filters and the filter not applied notice
In an embed, a click on one chart can filter the other charts. Databrain places that cross filter on a chart only when all of these are true:
- The filter is a plain list of values, at most 1,000 of them.
- A chart on the dashboard uses the column as a dimension or a drill level, and it is not the client column.
- For a builder metric, the column is on a table that the metric reads. On Table tenancy, the metric also has a client filter that limits it to one client.
- For a custom SQL metric, the query returns a column with that name.
Custom SQL filters and variable filters never apply as cross filters.
When a cross filter is left out, the chart still shows its data without that filter, and a note says why. Viewers in an embed see A filter could not be applied to this chart. In Databrain, you see the cause:
| Note in Databrain | What to do |
|---|---|
| Filters from other charts apply here only when the metric’s client filter limits it to one client. | Add or fix the metric’s client filter. |
| A filter from another chart does not match this chart’s data, so it was not applied. | Use a column this chart’s metric reads. |
| This SQL chart has no usable column for the filter from another chart, so it was not applied. | Return the column from the SQL query. |
| A filter on this chart uses a table its query does not read, so it was not applied. | Change the filter or the query. |
| The database could not run this chart with the filter from another chart, so that filter was left out. | Check the column type in the warehouse. |
5. Check it
- Open the data app and select the Tenancy tab. Look at every surface that shows Not scoped. See Tenancy model. This tab reads the setup only. A fixed client value or a filter from the guest token can keep rows apart while it still shows Not scoped, so do steps 2 to 4 before you change anything.
- Create guest tokens for two clients with known totals.
- Open the dashboards with each token:
- One dashboard for every client: open it with each token. Each shows only its own total.
- One dashboard for each client: open each client’s dashboard with its own token, and check that the other client’s dashboard does not open.
- With each token, open View as table on a card that allows it. The rows belong to that client only.
Next, check your embed before go-live.
If something goes wrong
- 400
CLIENT_ID_ERROR. On Table tenancy, send a value from the client column. On Database tenancy, send the schema name, and run Sync schema for a new client. - Viewers see Not set up for your account. Tenancy is not set, the token cannot find the metric, or the stricter tenancy check refused a metric with no client filter, placeholder or app filter. Check step 1 and step 2. If you use an app filter, check that the guest token sends its value.
- View underlying data is empty or shows a permission message. See Fix empty or refused underlying data.