g1t/services/billing/migrations/0046_reset_costs.sql
| 1 | -- What a testing reset wiped that g1t really paid for (src/reset.rs). The |
| 2 | -- model calls and Cloudflare usage behind a reset workspace's ledger still |
| 3 | -- happened: AI Gateway and Cloudflare's bill still show them. The reset |
| 4 | -- keeps their cost here, per day and product, before it deletes the |
| 5 | -- ledger, and the costs run counts it as given away on purpose (why |
| 6 | -- "testing resets"), so drift and the statement keep adding up. |
| 7 | -- |
| 8 | -- One row per day and bucket the workspace had cost on, and one row for |
| 9 | -- the reset itself (bucket '', nothing in it) so every reset is on record |
| 10 | -- even when it wiped nothing g1t paid for. reset_at is the same instant as |
| 11 | -- the reset's admin_actions entry. Never wiped by a reset; moved by a |
| 12 | -- rename. |
| 13 | CREATE TABLE IF NOT EXISTS reset_costs ( |
| 14 | workspace TEXT NOT NULL, |
| 15 | -- The UTC day the wiped usage was charged on. |
| 16 | day TEXT NOT NULL, |
| 17 | -- g1t's product (revenue_map's bucket; models for agent runs), or '' |
| 18 | -- for the reset's own row. |
| 19 | bucket TEXT NOT NULL, |
| 20 | -- What g1t paid for it: the ledger's cost (a workspace's own model |
| 21 | -- provider is none), and month-end meters' cost. |
| 22 | cost_micros INTEGER NOT NULL, |
| 23 | -- What it was valued at, at price, as the reconciliation valued it. |
| 24 | value_micros INTEGER NOT NULL, |
| 25 | reset_at TEXT NOT NULL, |
| 26 | reset_by TEXT NOT NULL, |
| 27 | PRIMARY KEY (workspace, day, bucket, reset_at) |
| 28 | ); |
| 29 | CREATE INDEX IF NOT EXISTS reset_costs_by_day ON reset_costs (day); |
| 30 | |
| 31 | -- Given away, the new why: usage a testing reset wiped. |
| 32 | ALTER TABLE margin_days ADD COLUMN given_reset_micros INTEGER NOT NULL DEFAULT 0; |