:active → Created, schema not yet provisioned
:provisioned → PostgreSQL schema created and ready
:suspended → Access disabled (data preserved)
:deleted → Soft delete (schema can be deprovisioned)
Multi-tenancy with schema-per-tenant isolation on PostgreSQL. Provides tenant CRUD, schema provisioning, tenant resolution, and cross-library integration.
Requires PostgreSQL. On SQLite or H2 the application refuses to boot with
:wagoe/tenant configured. A test profile on H2 sets :allow-h2? true under
:wagoe/tenant and runs it with tenant rows but no per-tenant schemas.
|
| Namespace | Purpose |
|---|---|
| Pure functions: slug validation, schema name generation, prepare-tenant, decisions |
| Protocols: |
| Malli schemas: |
| Service layer with observability interceptors |
| Database CRUD with case conversion |
| PostgreSQL schema provisioning/deprovisioning |
| REST API handlers (CRUD + provision/suspend/activate) |
| Integrant lifecycle ( |
:active → Created, schema not yet provisioned
:provisioned → PostgreSQL schema created and ready
:suspended → Access disabled (data preserved)
:deleted → Soft delete (schema can be deprovisioned)
;; Slug: lowercase alphanumeric + hyphens, 2–100 chars
(tenant/valid-slug? "acme-corp") ;=> true
(tenant/valid-slug? "ACME") ;=> false (uppercase)
(tenant/valid-slug? "acme_corp") ;=> false (underscore)
;; Slug → PostgreSQL schema name
(tenant/slug->schema-name "acme-corp") ;=> "tenant_acme_corp"
(require '[wagoe.tenant.shell.provisioning :as provisioning])
;; Provision: creates PostgreSQL schema and copies table structure
(provisioning/provision-tenant! db-ctx tenant)
;=> {:success? true :schema-name "tenant_acme_corp" :table-count 5}
;; Execute queries in tenant schema context
(provisioning/with-tenant-schema db-ctx "tenant_acme_corp"
(fn [tx]
;; SET search_path TO tenant_acme_corp, public
(jdbc/execute! tx ["SELECT * FROM orders"])))
POST /api/tenants # Create tenant
GET /api/tenants # List tenants
GET /api/tenants/:slug # Get tenant
PATCH /api/tenants/:slug # Update tenant
POST /api/tenants/:slug/provision # Provision schema
POST /api/tenants/:slug/suspend # Suspend tenant
POST /api/tenants/:slug/activate # Activate tenant
DELETE /api/tenants/:slug # Soft delete
clojure -M:test:test/pg :tenant
Can you improve this documentation? These fine people already did:
Thijs Creemers & thijscreemersEdit on GitHub
cljdoc builds & hosts documentation for Clojure/Script libraries
| Ctrl+k | Jump to recent docs |
| ← | Move to previous article |
| → | Move to next article |
| Ctrl+/ | Jump to the search field |