flagon-io/g1t

public

Where people and agents ship software together. The open-source git platform for the whole job: issues, agents, checks and deploys to the edge.

g1t/services/billing/migrations/0008_accounts.sql

58 lines2,506 bytesCodeBlame

Pick any line to see why it is the way it is: the commit, the pull request and issue it came from, and what the agent was thinking.

Billing accounts, terms and enterprises; g1t is no longer free1-- 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.
6CREATE 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.
28CREATE 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);
34CREATE INDEX account_members_by_account ON account_members (account_id);
35
36-- Every change made in sudo.g1t.sh, and who made it.
37CREATE 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);
46CREATE INDEX admin_actions_by_account ON admin_actions (account, created_at);
47
48-- g1t's own workspace runs comped (it was LIMIT_EXEMPT).
49INSERT INTO billing_accounts (id, kind, name, terms_kind, note, terms_set_by, terms_set_at, created_by, created_at)
50VALUES ('ws_syntaqx', 'workspace', 'syntaqx', 'comped', 'g1t''s own workspace', 'migration', '2026-10-05T00:00:00Z', 'migration', '2026-10-05T00:00:00Z');
51INSERT INTO admin_actions (id, account, action, detail, by, created_at)
52VALUES ('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.
55INSERT INTO billing_accounts (id, kind, name, terms_kind, ceiling_micros, note, terms_set_by, terms_set_at, created_by, created_at)
56SELECT 'ws_' || workspace, 'workspace', workspace, 'custom', ceiling_micros, 'Ceiling set before accounts', 'migration',
57 '2026-10-05T00:00:00Z', 'migration', '2026-10-05T00:00:00Z'
58FROM limits WHERE ceiling_micros IS NOT NULL AND workspace <> 'syntaqx';