textmachine/platform/internal/pgstore/migrations/00011_ceiling_argument.sql

20 lines
1.2 KiB
SQL

-- +goose Up
-- What was actually handed to the engine as `--ceiling-usd`, in micro-USD.
--
-- It is NOT ceiling_micro_usd. That column is this attempt's own budget — the increment the user
-- bought and the amount held against their balance. The engine's flag means something else
-- (D39.122): it is the book's CUMULATIVE cap, compared against committed + reserved of the whole
-- book across every run it has ever had, so the platform computes
-- argument = committed (read from `tmctl status --json`) + this attempt's increment
-- and the two numbers stop being equal from the second run of a book onwards. The reserved figure is
-- deliberately NOT in that sum — the engine clears it on its own write-open, so adding it would give
-- the run headroom beyond its hold (ratified 09.08; see runs.meter.bookCap).
--
-- Stored because the difference is invisible afterwards and expensive to be wrong about: a support
-- question about a run that stopped early is answered by the limit the process was actually given,
-- not by the one the platform would compute today from a meter that has moved since.
alter table run_attempts add column ceiling_arg_micro_usd bigint not null default 0;
-- +goose Down
alter table run_attempts drop column ceiling_arg_micro_usd;