rok-tenant — Multi-tenancy for the rok ecosystem.
Provides row-level tenant isolation via task-local tenant ID storage and a Tower middleware that resolves the tenant per request.
Two resolution strategies are supported:
- Shared table — A
tenant_idcolumn is filtered automatically via a global scope when#[model(tenant_scoped)]is applied. - Separate schemas — Use [
TenantSource::Subdomain] to route each request to a dedicated PostgreSQL schema (integration withrok-ormschema switching is handled by the ORM layer).
Quick start
use ;
// Extract tenant from X-Tenant-ID header
let app = new
.nest
.layer;
// Or from the subdomain
let app = new
.nest
.layer;
// Inside a handler or model method:
let tenant = current_tenant_id; // → Option<i64>