481359ddb2
Co-authored-by: Kandev Agent <agent@kandev.dev> Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
2.3 KiB
2.3 KiB
id, title, status, wave, depends_on, plan, spec
| id | title | status | wave | depends_on | plan | spec | |
|---|---|---|---|---|---|---|---|
| 02-org-entity-and-identity | Org entity and identity binding | todo | 1 |
|
plan.md | ../../specs/multi-tenancy/spec.md |
Task 02: Org Entity and Identity Binding
Acceptance
orgsandorg_os_userstables exist with the spec's columns, replay-safe on fresh and existing databases, on SQLite and Postgres.users.org_idandauth_invites.org_idare added via idempotentADD COLUMNmigrations; the users email uniqueness becomesUNIQUE (org_id, email)through a table-rebuild migration with a replay regression test proving values and timestamps survive.authn.IdentitycarriesOrgIDandInstance; the auth middleware populates both from the authenticated user.- A boot migration creates exactly one
is_defaultorg and assigns every existing user, workspace, secret, and config row to it. The migration aborts the boot when any row cannot be assigned. - With the flag off,
OrgIDis empty, no org route is mounted, and the boot payload has noorgkey. - A session or token whose
OrgIDnames a missing or suspended org fails closed withorg_suspended, distinct from a session challenge.
Verification
go test ./internal/tenancy/... ./internal/org/... ./internal/auth/...KANDEV_TEST_POSTGRES_DSN=... go test ./internal/org/... -run TestMigrationgo test ./internal/auth/httpmw/... -run 'TestSuspendedOrg|TestIdentityOrg'
Files Likely Touched
apps/backend/internal/org/{models,store,service,provider}.goapps/backend/internal/auth/authn/identity.goapps/backend/internal/auth/httpmw/middleware.goapps/backend/internal/auth/store/schema.go,service_invites.go,service_setup.goapps/backend/internal/user/{models,store}/apps/backend/internal/tenancy/registry.go(classify the new tables)
Inputs
- Spec: Data model, State machine, Failure modes.
- Patterns:
internal/auth/store/schema.godialect substitution; ADR 0027 replayable migrations; the destructive-cutover migration conventions inapps/backend/AGENTS.mdfor the users table rebuild.
Output Contract
Report the migration's fresh-DB and replay results on both dialects, the abort-on-unassignable-row proof, RED/GREEN commands, and set this task plus its plan checkbox to done.