Files
coucou/cloud/schema.sql
Claude 5293c0ded0 Coucou Cloud: Stripe and the offers
The Cloud is now sold: Free (everything on the Mac, unchanged) and
« Cloud · your key » at 9 €/month (the AI on the user's own Anthropic key).
Solo, Pro and Max are listed as coming, until the credit offers open.

Worker (billing.ts): the offers in one place (GET /v1/plans, public, so a
price changes without an app update); Stripe Checkout and the customer
portal, opened in the browser (the card never touches Coucou); the signed
Stripe webhook keeps the subscription's state; a user's Mochis run in the
Cloud only with an active subscription (past_due included while Stripe
retries) or a login in COMP_LOGINS (Louis-CFM). Without STRIPE_SECRET_KEY,
billing is off. Under the VAT franchise: no VAT, the invoice footer says
« TVA non applicable, article 293 B du CGI »; STRIPE_TAX turns Stripe Tax on.
The new user columns are added by the Worker itself.
scripts/stripe-setup.mjs makes the price, the portal and the webhook, and
pipes the webhook's secret straight into wrangler.

brain: `cloud subscribe`, `cloud billing` (--json gives the URL to the app);
`cloud status` carries the offer and the offers.

App: the offers view (CloudPlans.swift, for the onboarding too), a
« Choose your offer » step in the Cloud setup, the offer on the account
card (renews / ends / payment failed, Manage, See the offers); the switch
to move a Mochi needs the offer. 28 strings in the 16 languages.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01LJm3SRL9k3gBPaVtfPhwcT
2026-11-30 16:47:31 +00:00

79 lines
2.3 KiB
SQL

-- Coucou Cloud. `npm run db:init` once, after `wrangler d1 create coucou-cloud`.
-- A Coucou user: who they are on GitHub, the hash of the token their Mac uses, their Anthropic key (encrypted).
CREATE TABLE IF NOT EXISTS users (
id INTEGER PRIMARY KEY AUTOINCREMENT,
github_id INTEGER NOT NULL UNIQUE,
login TEXT NOT NULL,
token_hash TEXT UNIQUE,
anthropic_key TEXT,
language TEXT NOT NULL DEFAULT 'fr',
created_at TEXT NOT NULL,
-- Stripe (billing.ts): the customer, the offer, its state and when it renews
stripe_customer_id TEXT,
plan TEXT,
plan_status TEXT,
plan_renews_at TEXT,
plan_cancels INTEGER
);
-- Where the GitHub App is installed, and by whom.
CREATE TABLE IF NOT EXISTS installations (
id INTEGER PRIMARY KEY,
user_id INTEGER NOT NULL,
account TEXT NOT NULL
);
-- The Mochis a user turned on in the Cloud (sent by their Mac).
CREATE TABLE IF NOT EXISTS mochis (
user_id INTEGER NOT NULL,
id TEXT NOT NULL,
name TEXT NOT NULL,
repo TEXT NOT NULL,
trigger TEXT NOT NULL,
instructions TEXT NOT NULL,
model TEXT NOT NULL,
budget_cents INTEGER NOT NULL,
enabled INTEGER NOT NULL,
-- 1: it posts on its own (a review as a comment), no click
autonomous INTEGER NOT NULL DEFAULT 0,
PRIMARY KEY (user_id, id)
);
-- Agent and environment ids made in the user's Anthropic organization, kept to be reused.
CREATE TABLE IF NOT EXISTS ids (
user_id INTEGER NOT NULL,
key TEXT NOT NULL,
value TEXT NOT NULL,
PRIMARY KEY (user_id, key)
);
-- Each run: its session, what it cost, what it wrote, and the proposal waiting for a click.
CREATE TABLE IF NOT EXISTS runs (
id TEXT PRIMARY KEY,
user_id INTEGER NOT NULL,
mochi_id TEXT NOT NULL,
repo TEXT NOT NULL,
item_type TEXT NOT NULL,
item_number INTEGER,
item_title TEXT,
sha TEXT,
session_id TEXT,
status TEXT NOT NULL,
started_at TEXT NOT NULL,
finished_at TEXT,
cost_usd REAL,
turns INTEGER,
active_seconds REAL,
text TEXT,
proposal TEXT,
proposal_state TEXT,
proposal_url TEXT,
-- 1: posted (or tried to) on its own, by an autonomous Mochi
auto INTEGER,
error TEXT,
UNIQUE (user_id, mochi_id, repo, item_number, sha)
);
CREATE INDEX IF NOT EXISTS runs_status ON runs (status);
CREATE INDEX IF NOT EXISTS runs_user ON runs (user_id, started_at);