g1t/services/billing/migrations/0008_accounts.sql
| 1 | -- Who pays for a workspace, and on what terms. See src/accounts.rs. |
| 2 | |
| 3 | -- A billing account: a workspace's own (`ws_<slug>`, a row only once its |
| 4 | -- terms differ from standard), or an enterprise (`ent_…`) paying for |
| 5 | -- several workspaces. |
| 6 | CREATE TABLE billing_accounts ( |
| 7 | id TEXT PRIMARY KEY, |
| 8 | -- workspace or enterprise. |
| 9 | kind TEXT NOT NULL, |
| 10 | name TEXT NOT NULL, |
| 11 | -- standard, comped or custom. |
| 12 | terms_kind TEXT NOT NULL DEFAULT 'standard', |
| 13 | discount_percent INTEGER NOT NULL DEFAULT 0, |
| 14 | -- Replaces the ceiling trust would give, when set. |
| 15 | ceiling_micros INTEGER, |
| 16 | note TEXT NOT NULL DEFAULT '', |
| 17 | -- When the terms end; standard after. |
| 18 | terms_until TEXT, |
| 19 | terms_set_by TEXT, |
| 20 | terms_set_at TEXT, |
| 21 | -- The payment provider's customer, for an enterprise's one bill. |
| 22 | customer_id TEXT, |
| 23 | created_by TEXT NOT NULL, |
| 24 | created_at TEXT NOT NULL |
| 25 | ); |
| 26 | |
| 27 | -- Workspaces an enterprise pays for. A workspace not here pays for itself. |
| 28 | CREATE TABLE account_members ( |
| 29 | workspace TEXT PRIMARY KEY, |
| 30 | account_id TEXT NOT NULL, |
| 31 | added_by TEXT NOT NULL, |
| 32 | added_at TEXT NOT NULL |
| 33 | ); |
| 34 | CREATE INDEX account_members_by_account ON account_members (account_id); |
| 35 | |
| 36 | -- Every change made in sudo.g1t.sh, and who made it. |
| 37 | CREATE TABLE admin_actions ( |
| 38 | id TEXT PRIMARY KEY, |
| 39 | account TEXT NOT NULL, |
| 40 | -- terms, create, attach, detach, credit. |
| 41 | action TEXT NOT NULL, |
| 42 | detail TEXT NOT NULL, |
| 43 | by TEXT NOT NULL, |
| 44 | created_at TEXT NOT NULL |
| 45 | ); |
| 46 | CREATE INDEX admin_actions_by_account ON admin_actions (account, created_at); |
| 47 | |
| 48 | -- g1t's own workspace runs comped (it was LIMIT_EXEMPT). |
| 49 | INSERT INTO billing_accounts (id, kind, name, terms_kind, note, terms_set_by, terms_set_at, created_by, created_at) |
| 50 | VALUES ('ws_syntaqx', 'workspace', 'syntaqx', 'comped', 'g1t''s own workspace', 'migration', '2026-10-05T00:00:00Z', 'migration', '2026-10-05T00:00:00Z'); |
| 51 | INSERT INTO admin_actions (id, account, action, detail, by, created_at) |
| 52 | VALUES ('adm_migration_syntaqx', 'ws_syntaqx', 'terms', 'standard → comped: g1t''s own workspace', 'migration', '2026-10-05T00:00:00Z'); |
| 53 | |
| 54 | -- Ceilings set by hand before accounts existed become custom terms. |
| 55 | INSERT INTO billing_accounts (id, kind, name, terms_kind, ceiling_micros, note, terms_set_by, terms_set_at, created_by, created_at) |
| 56 | SELECT 'ws_' || workspace, 'workspace', workspace, 'custom', ceiling_micros, 'Ceiling set before accounts', 'migration', |
| 57 | '2026-10-05T00:00:00Z', 'migration', '2026-10-05T00:00:00Z' |
| 58 | FROM limits WHERE ceiling_micros IS NOT NULL AND workspace <> 'syntaqx'; |