tenants
Tenant
dataclass
¶
Represents a single tenant in the multi-tenant deployment.
Attributes:
| Name | Type | Description |
|---|---|---|
tenant_id |
str
|
Unique string identifier for the tenant (slug). |
display_name |
str
|
Human-readable name. |
status |
TenantStatus
|
Current lifecycle state. |
label_studio_org_id |
int | None
|
Label Studio organisation ID (per-tenant). |
named_graph_prefix |
str
|
Base IRI prefix for this tenant's named graphs. |
Source code in src/riverbank/tenants/__init__.py
TenantStatus
¶
activate_rls_for_all_tables(conn)
¶
Enable RLS and create tenant-isolation policies on all catalog tables.
Returns a dict mapping table_name -> success.
Source code in src/riverbank/tenants/__init__.py
assign_label_studio_org(conn, tenant_id, org_id)
¶
Associate a Label Studio organisation ID with a tenant.
Each tenant has exactly one Label Studio organisation; reviewer assignments respect tenant boundaries.
Source code in src/riverbank/tenants/__init__.py
clear_current_tenant(conn)
¶
create_rls_policy(conn, table)
¶
Create the tenant isolation RLS policy for a table.
The policy allows rows where tenant_id matches the session-local
app.current_tenant_id GUC, or where tenant_id IS NULL (system
rows that pre-date multi-tenancy).
Policy name: riverbank_tenant_isolation.
Source code in src/riverbank/tenants/__init__.py
create_tenant(conn, tenant)
¶
Persist a new tenant record in _riverbank.tenants.
Creates the _riverbank.tenants table if it does not yet exist, then
inserts the tenant row. Returns True on success.
Source code in src/riverbank/tenants/__init__.py
delete_tenant(conn, tenant_id, gdpr_erasure=False)
¶
Delete a tenant and optionally erase all tenant-scoped data (GDPR).
When gdpr_erasure=True this deletes all rows in the catalog tables
where tenant_id matches before removing the tenant record. The
audit log rows are also removed (GDPR erasure overrides append-only).
When gdpr_erasure=False the tenant record is marked as deleted
and data rows are retained for archival.
Source code in src/riverbank/tenants/__init__.py
enable_rls(conn, table)
¶
Enable Row-Level Security on a single _riverbank table.
Idempotent — safe to call when RLS is already enabled.
Returns True on success, False when the table does not exist or the
operation fails.
Source code in src/riverbank/tenants/__init__.py
list_tenants(conn)
¶
Return all tenants from _riverbank.tenants.
Returns an empty list when the table does not exist (pre-migration state).
Source code in src/riverbank/tenants/__init__.py
set_current_tenant(conn, tenant_id)
¶
Set the app.current_tenant_id session GUC for the current connection.
All RLS policies use this setting to filter rows to the active tenant. Call this at the start of every tenant-scoped database session.
Source code in src/riverbank/tenants/__init__.py
suspend_tenant(conn, tenant_id)
¶
Mark a tenant as suspended (all RLS-gated operations will fail).