Skip to content

feat(store): tenant schema + identity plumbing (RIG-2861 T1) - #715

Merged
mattwilkinsonn merged 2 commits into
mainfrom
compass-managed/rig-2918-t1-tenant-schema
Aug 30, 2026
Merged

feat(store): tenant schema + identity plumbing (RIG-2861 T1)#715
mattwilkinsonn merged 2 commits into
mainfrom
compass-managed/rig-2918-t1-tenant-schema

Conversation

@rigel-mintaka

Copy link
Copy Markdown
Contributor

The tenant-identity foundation for Compass managed multi-tenancy, per the
frozen RIG-2861 design record
(docs/designs/infra/runtime/compass-managed-multitenancy/design.md, §T1). This
is T1 only: schema + context plumbing, no RLS (that is T2, gated on RIG-2877).

  • New tenants table (id, slug, display_name, created_at_unix_ms), folded into
    0001_init.sql per the repo's pre-dogfood collapse convention (no new NNNN
    file). accounts gains a NOT NULL tenant_id FK + a lookup index.
  • store.TenantID newtype; WithTenant/TenantFromContext context seam
    mirroring the comms actor seam (context.go).
  • (*Store).BootstrapTenant — idempotent single-tenant seed mirroring
    BootstrapAdmin; Open seeds it and caches the id. resolveTenant stamps the
    context tenant when set, else the bootstrap tenant — OSS single-tenant stays
    degenerate with no if multiTenant fork.
  • All four account inserts stamp tenant_id via resolveTenant(ctx).

Tests (pgtest): idempotent seed, migration on fresh + existing DBs, CreateUser
stamps the context tenant and falls back to the bootstrap tenant. Existing
account/agent/system suites pass unchanged under the new NOT NULL column.

Refs RIG-2918.

@linear-code

linear-code Bot commented Aug 28, 2026

Copy link
Copy Markdown

RIG-2861

RIG-2918

@github-actions

github-actions Bot commented Aug 28, 2026

Copy link
Copy Markdown

Compass engineering docs preview: https://compass-managed-rig-2918-t1.compass-eng-docs.pages.dev

Deployed from compass-managed/rig-2918-t1-tenant-schema at a3992bd.

@rigel-mintaka
rigel-mintaka marked this pull request as ready for review August 28, 2026 05:42
@rigel-mintaka
rigel-mintaka force-pushed the compass-managed/rig-2918-t1-tenant-schema branch from 512b15b to 8f9a6c4 Compare August 29, 2026 19:42
The tenant-identity foundation for Compass managed multi-tenancy, per the
frozen RIG-2861 design record
(docs/designs/infra/runtime/compass-managed-multitenancy/design.md, §T1). This
is T1 only: schema + context plumbing, no RLS (that is T2, gated on RIG-2877).

- New `tenants` table (id, slug, display_name, created_at_unix_ms), folded into
  0001_init.sql per the repo's pre-dogfood collapse convention (no new NNNN
  file). `accounts` gains a NOT NULL `tenant_id` FK + a lookup index.
- `store.TenantID` newtype; `WithTenant`/`TenantFromContext` context seam
  mirroring the comms actor seam (context.go).
- `(*Store).BootstrapTenant` — idempotent single-tenant seed mirroring
  BootstrapAdmin; `Open` seeds it and caches the id. `resolveTenant` stamps the
  context tenant when set, else the bootstrap tenant — OSS single-tenant stays
  degenerate with no `if multiTenant` fork.
- All four account inserts stamp `tenant_id` via `resolveTenant(ctx)`.

Tests (pgtest): idempotent seed, migration on fresh + existing DBs, CreateUser
stamps the context tenant and falls back to the bootstrap tenant. Existing
account/agent/system suites pass unchanged under the new NOT NULL column.

Refs RIG-2918.
…1 review)

Review finding (low): only CreateUser tenant-stamping was directly asserted.
CreateAgent inserts through a different transactional path, so a wrong-tenant
stamp there would escape both the CreateUser test and the NOT NULL column. Add
TestCreateAgentStampsTenant reading back the persisted agent tenant_id.

Refs RIG-2918.
@rigel-mintaka
rigel-mintaka force-pushed the compass-managed/rig-2918-t1-tenant-schema branch from 8f9a6c4 to a3992bd Compare August 30, 2026 04:29
@mattwilkinsonn
mattwilkinsonn merged commit a17625b into main Aug 30, 2026
13 checks passed
@mattwilkinsonn
mattwilkinsonn deleted the compass-managed/rig-2918-t1-tenant-schema branch August 30, 2026 05:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants