activerecord-tenanted
Installation
SKILL.md
activerecord-tenanted (SQLite per tenant)
One SQLite file per tenant via the Basecamp activerecord-tenanted gem. Identity, sessions, and the tenant row live in a global database. Product data lives in storage/tenants/{env}/{tenant_key}/main.sqlite3.
This is the Herald / Cortex / Innkeeper model. It is not:
- Nebula
acts_as_tenant— one database,workspace_idon every row - Fizzy path tenancy — one database,
Current.account+SCRIPT_NAMEURL prefix
If the app already uses acts_as_tenant or Fizzy-style account slugs in a shared schema, do not introduce this gem.
Philosophy
- Two base classes, two databases.
GlobalRecordnever sees tenant data.ApplicationRecordnever sees identities. - No tenanted query without a tenant.
User.findoutsidewith_tenant/Current.tenant=is a bug, even in jobs and rake tasks. - The URL (or Current) chooses the shard. The gem's default subdomain resolver is wrong for path-based apps — disable it.
- Jobs re-enter the tenant. Active Job does not magically carry the shard. Pass a global id (account/tenant/project) and wrap
performinwith_tenant.