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
+10 -2
View File
@@ -29,6 +29,10 @@ import (
type Caller struct {
ID int64
Name string
// Team is the agent's team, and DB its database (multi-tenant); nil:
// the one the Handler was given.
Team int64
DB *db.DB
// Can says whether the agent may read (act false) or change things in
// a module or scope (market, crm, …).
Can func(scope string, act bool) bool
@@ -66,7 +70,7 @@ func Handler(d *db.DB, version string, auth Authenticator, more func(*mcp.Server
c, _ := r.Context().Value(callerKey{}).(*Caller)
sig := signature(c)
if c != nil {
sig = fmt.Sprintf("%d/%s", c.ID, sig)
sig = fmt.Sprintf("%d/%p/%s", c.ID, c.DB, sig)
}
mu.Lock()
defer mu.Unlock()
@@ -74,7 +78,11 @@ func Handler(d *db.DB, version string, auth Authenticator, more func(*mcp.Server
return srv
}
srv := mcp.NewServer(&mcp.Implementation{Name: "supermarket", Version: version}, nil)
addTools(srv, d, c)
td := d
if c != nil && c.DB != nil {
td = c.DB
}
addTools(srv, td, c)
if more != nil {
more(srv, c)
}