3 Commits
Author SHA1 Message Date
davidandClaude Opus 5.5 0e695ac810 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>
2026-11-25 12:08:47 -07:00
davidandClaude Opus 5.5 d827d507c1 Phase 9, part 3: schema migrations for both databases
Migrations from schema 30 on are one list (internal/db/migrations.go),
written in SQLite's SQL and translated for Postgres (db.PostgresSQL)
unless one gives its own. On Postgres the whole migration is one
transaction under an advisory lock, and each step is recorded in
schema_migrations. TestSchemasMatch compares the two schemas (tables,
columns, types, NOT NULL, nocase, indexes), with and without a new
migration.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-25 07:17:56 -07:00
davidandClaude Opus 5.5 1b2947de7c Phase 9, part 2: one database layer for SQLite and Postgres
db.DB wraps database/sql for either database. The SQL stays SQLite's: on
Postgres each statement's ? become $n and LIKE ignores case as SQLite's
does, and the Postgres schema (postgres.sql, schema 29 as a whole) adds
SQLite's instr, json_extract and two-argument max/min, and a nocase ICU
collation. Needs Postgres 18.

LastInsertId became db.Insert (RETURNING id), INSERT OR IGNORE became ON
CONFLICT DO NOTHING, upserts qualify their columns, and three queries
group by every column they use. SUPERMARKET_TEST_POSTGRES runs the test
suite on Postgres, a new schema per test; all tests pass on both.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-25 07:10:44 -07:00