Phase 13, part 1: a Postgres schema per team

On the multi-tenant edition each team's data is in its own schema; the
tables every team shares (people, sessions, memberships, keys, locks, and
a new teams table) stay in the main one. A team's connection pool searches
its own schema first, so the app's SQL runs unchanged and can't reach
another team's tables. Each request is served by a copy of the Server for
the viewer's team, with that team's database, secrets and caches; agents
work on their own team's. The local and server editions are unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-25 12:08:47 -07:00
co-authored by Claude Opus 5.5
parent ff5eaa9784
commit 0e695ac810
24 changed files with 1037 additions and 289 deletions
+5 -5
View File
@@ -16,12 +16,12 @@ import (
// hasOwner says whether the setup is finished.
func (s *Server) hasOwner() (bool, error) {
if s.setupDone.Load() {
if s.st().setupDone.Load() {
return true, nil
}
ok, err := users.HasOwner(s.DB, users.Team)
ok, err := users.HasOwner(s.DB, s.team())
if ok {
s.setupDone.Store(true)
s.st().setupDone.Store(true)
}
return ok, err
}
@@ -111,11 +111,11 @@ func (s *Server) setupSave(w http.ResponseWriter, r *http.Request) {
s.serverError(w, err)
return
}
if err := users.Join(s.DB, users.Team, u.ID, users.Owner, nil, now); err != nil {
if err := users.Join(s.DB, s.team(), u.ID, users.Owner, nil, now); err != nil {
s.serverError(w, err)
return
}
s.setupDone.Store(true)
s.st().setupDone.Store(true)
s.Log.Info("setup: the owner is created", "email", u.Email)
s.record(audit.Entry{UserID: u.ID, UserName: displayName(u), Action: "setup", Target: u.Email, IP: clientIP(r)})
if err := s.startSession(w, r, u); err != nil {