g1t/services/billing/migrations/0036_model_costs_in_full.sql
| 1 | -- Model costs counted in full, and margin kept on every sale. |
| 2 | -- |
| 3 | -- What a discount on an account's terms took below cost plus the margin: |
| 4 | -- counted as given (why "discount"), so a discounted sale is valued at its |
| 5 | -- price and never reads as margin lost. Negative on a correction down. |
| 6 | ALTER TABLE ledger ADD COLUMN discount_micros INTEGER NOT NULL DEFAULT 0; |
| 7 | ALTER TABLE margin_days ADD COLUMN given_discount_micros INTEGER NOT NULL DEFAULT 0; |
| 8 | |
| 9 | -- Why a run was settled at no less than the sandbox reported instead of |
| 10 | -- at AI Gateway's figure: a model the gateway has no price for, or more |
| 11 | -- logs than were read. Null when the gateway's figure was the whole cost. |
| 12 | ALTER TABLE runs ADD COLUMN gateway_note TEXT; |
| 13 | |
| 14 | -- AI Gateway's analytics (cost_lines source ai_gateway): what the gateway |
| 15 | -- priced g1t's own provider traffic at, per day and model. Its cost is the |
| 16 | -- models bucket's "Cloudflare" side, checked against the ledger's model |
| 17 | -- cost (which stays the bucket's cost). |
| 18 | INSERT OR IGNORE INTO cost_map (product, meter, bucket, price_meter, own_meter, scale_to_own, note, updated_at, updated_by) VALUES |
| 19 | ('ai_gateway_requests', '*', 'models', NULL, NULL, 0, 'What AI Gateway priced g1t''s own model traffic at, per model', '2026-10-07T00:00:00Z', 'migration'); |