-- 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 does it on its own (posts the review or the reply, opens the draft PR), no click autonomous INTEGER NOT NULL DEFAULT 0, -- repo (works in a copy of the repo), brief (Ship Log), watch (Prod Watch) kind TEXT NOT NULL DEFAULT 'repo', -- write: its changes become a draft PR · read: it only reads tools TEXT NOT NULL DEFAULT 'read', -- "daily 01:30", "weekly mon 03:00"… or "manual", in tz schedule TEXT NOT NULL DEFAULT 'manual', -- Night Shift: the label of the issues it picks label TEXT NOT NULL DEFAULT 'mochi', -- Prod Watch: its addresses (JSON) urls TEXT NOT NULL DEFAULT '[]', tz TEXT NOT NULL DEFAULT 'UTC', -- runs a day at most per_day INTEGER NOT NULL DEFAULT 10, 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: done (or tried) on its own, by an autonomous Mochi auto INTEGER, error TEXT, -- github, schedule, manual, watch trigger TEXT, item_url TEXT, -- the commit it started on and the default branch: a draft PR is made on them base_sha TEXT, base_ref TEXT, -- a Mochi that changes files: the report while it packs, then its changes until the click report TEXT, changes 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);