Tenancy

Single-database tenancy

Set TENANCY_SINGLE_DATABASE=true or cfg.SingleDatabase = true.

  • Do not require Config.Drivers for tenant pools
  • Default bootstrappers omit the database switcher
  • Disable auto DB provision/teardown expectations in your pipelines
  • Scope models with:
q, err := tenancy.BelongsToTenant[Post](ctx, "tenant_id")
if err != nil {
    // no tenant in context: refuse an unscoped query (fail-closed)
    return err
}
posts, err := q.Get(ctx)

Still use identification middleware and cache/filesystem bootstrappers so non-DB concerns remain isolated.