#Query multi-tenant db with $permissions as attribute

3 messages · Page 1 of 1 (latest)

inner glen
#

I'm setting up a multi-tenant database with RLS enabled. My users my have permissions set for multiple Teams, and as such when they query the database with the default $permissions set, they'll end up seeing data for multiple teams in one request.

When trying to query my TablesDB.listRows call to include a Query.contains for $permissions and my team ID (team:${getTeamId()}), I get "Attribute not found in schema: $permissions.

Is the assumption that $permissions isn't a queriable row attribute? Is there any way to handle multi-tenancy without having to update every single table to have a "tenant_id" column?

quasi agate
# inner glen I'm setting up a multi-tenant database with RLS enabled. My users my have permis...

I can help with that. The issue is that $permissions isn’t a queryable attribute in the table schema it’s only used internally by the RLS engine to control access, so Query.contains() can’t filter on it. That’s why you’re getting the “Attribute not found in schema” error.
For multi-tenancy, the usual approach is to store something like a team_id (tenant_id) column in the rows and apply queries or RLS rules based on that. Without a tenant column, the database can’t filter results per team during queries.
Quick question: are you using a single database for all teams or separate collections/tables per team?

inner glen
#

Gotcha. Currently I'm just using a single database for all teams, so all users and thus all teams interface with the same database and tables