Phase 14, part 1: plans, each team's account, and their limits

The multi-tenant edition's plans (Free and Paid as decided, or a plans
file) and each team's billing account, with a 14-day trial of Paid. A
team's plan caps what its people and agents may change: modules outside it
stay readable, a lapsed team changes nothing, and agents, Market entries,
crawls and background jobs keep to it. Without a Stripe key, no billing.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-25 13:15:00 -07:00
co-authored by Claude Opus 5.5
parent e47764a78e
commit a47990f9bf
19 changed files with 848 additions and 7 deletions
+29 -1
View File
@@ -27,7 +27,7 @@ type Migration struct {
// PlatformTables are the tables every team shares on the multi-tenant
// edition, in the main schema; every other table is a team's, in its own
// schema.
var PlatformTables = []string{"instances", "locks", "users", "memberships", "sessions", "links", "throttle", "agent_keys", "teams"}
var PlatformTables = []string{"instances", "locks", "users", "memberships", "sessions", "links", "throttle", "agent_keys", "teams", "billing", "stripe_events"}
// both are the migrations after schema 29, on both databases: schema 30
// is both[0]. (migrations, before them, are SQLite's own; Postgres starts
@@ -301,6 +301,34 @@ ALTER TABLE sessions ADD COLUMN view_reason TEXT NOT NULL DEFAULT '';
ALTER TABLE users ADD COLUMN oidc_subject TEXT NOT NULL DEFAULT ''; -- <issuer>|<subject>: who they are at the Core
CREATE UNIQUE INDEX users_oidc_subject ON users(oidc_subject) WHERE oidc_subject <> '';
ALTER TABLE sessions ADD COLUMN via TEXT NOT NULL DEFAULT 'password'; -- password or core
`,
},
// 44
{
Note: "billing: each team's plan and Stripe subscription, and the Stripe events seen (multi-tenant edition)",
Platform: true,
SQLite: `
CREATE TABLE billing (
team_id INTEGER PRIMARY KEY,
plan TEXT NOT NULL DEFAULT 'paid', -- the plan subscribed to (or trialed)
status TEXT NOT NULL DEFAULT 'trialing', -- trialing, active, past_due, canceled, free
trial_ends TEXT NOT NULL DEFAULT '',
customer TEXT NOT NULL DEFAULT '', -- Stripe's customer
subscription TEXT NOT NULL DEFAULT '', -- Stripe's subscription
seats INTEGER NOT NULL DEFAULT 0, -- people paid for
storage_blocks INTEGER NOT NULL DEFAULT 0, -- extra storage blocks paid for
period_end TEXT NOT NULL DEFAULT '', -- the subscription's current period: when the next invoice comes
past_due_since TEXT NOT NULL DEFAULT '',
kept_member INTEGER NOT NULL DEFAULT 0, -- on Free with too many people: the one besides the owner who keeps their access
storage_used INTEGER NOT NULL DEFAULT 0, -- bytes, measured hourly
warned TEXT NOT NULL DEFAULT '', -- the last lapse email sent: past-due, read-only, deleting
updated_at TEXT NOT NULL
);
CREATE TABLE stripe_events (
id TEXT PRIMARY KEY, -- Stripe's event ID: each is handled once
type TEXT NOT NULL,
received_at TEXT NOT NULL
);
`,
},
}