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:
+13
-20
@@ -9,7 +9,6 @@ import (
|
||||
"sort"
|
||||
"strconv"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"supermarket/internal/api/gsc"
|
||||
@@ -31,31 +30,24 @@ var googleFields = []secretField{
|
||||
// gscBase is the Search Console API's address; tests point it elsewhere.
|
||||
var gscBase = ""
|
||||
|
||||
// googleAuth caches the access token, which lasts an hour.
|
||||
type googleAuth struct {
|
||||
mu sync.Mutex
|
||||
token string
|
||||
expires time.Time
|
||||
}
|
||||
|
||||
var gauth googleAuth
|
||||
|
||||
func (s *Server) setGoogleToken(res *oauth.Result) {
|
||||
gauth.mu.Lock()
|
||||
defer gauth.mu.Unlock()
|
||||
gauth.token = res.AccessToken
|
||||
tc := s.cache()
|
||||
tc.mu.Lock()
|
||||
defer tc.mu.Unlock()
|
||||
tc.googleToken = res.AccessToken
|
||||
life := res.ExpiresIn
|
||||
if life <= 0 {
|
||||
life = time.Hour
|
||||
}
|
||||
gauth.expires = time.Now().Add(life - time.Minute)
|
||||
tc.googleExpires = time.Now().Add(life - time.Minute)
|
||||
}
|
||||
|
||||
// googleToken returns an access token, refreshing it when it's run out.
|
||||
func (s *Server) googleToken(ctx context.Context) (string, error) {
|
||||
gauth.mu.Lock()
|
||||
tok, exp := gauth.token, gauth.expires
|
||||
gauth.mu.Unlock()
|
||||
tc := s.cache()
|
||||
tc.mu.Lock()
|
||||
tok, exp := tc.googleToken, tc.googleExpires
|
||||
tc.mu.Unlock()
|
||||
if tok != "" && time.Now().Before(exp) {
|
||||
return tok, nil
|
||||
}
|
||||
@@ -177,9 +169,10 @@ func (s *Server) searchSettingsSave(w http.ResponseWriter, r *http.Request) {
|
||||
s.serverError(w, err)
|
||||
return
|
||||
}
|
||||
gauth.mu.Lock()
|
||||
gauth.token = ""
|
||||
gauth.mu.Unlock()
|
||||
tc := s.cache()
|
||||
tc.mu.Lock()
|
||||
tc.googleToken = ""
|
||||
tc.mu.Unlock()
|
||||
}
|
||||
if _, has := r.PostForm["gitea_url"]; has {
|
||||
u := strings.TrimRight(strings.TrimSpace(r.PostFormValue("gitea_url")), "/")
|
||||
|
||||
Reference in New Issue
Block a user