4d84625332
One row per provider/translator per day; try_spend is a single atomic upsert so concurrent reconcile closes can't both slip a spend past the daily cap. No allowance configured reads as unlimited.
20 lines
960 B
SQL
20 lines
960 B
SQL
-- #197. Token bucket state for §15's provider and translator budgets. The
|
|
-- allowance itself is `subtitle_settings.provider_daily_budgets` /
|
|
-- `translator_daily_budgets` (#198); this table only tracks what has already
|
|
-- been spent today, so a bucket with no allowance configured reads as
|
|
-- unlimited rather than zero (0025's own comment on that column).
|
|
--
|
|
-- One row per (kind, name, day); a new day is a fresh row rather than a
|
|
-- reset column, so the refill is "today has no row yet" and needs no cron.
|
|
|
|
CREATE TABLE subtitle_budget_spend (
|
|
kind TEXT NOT NULL CHECK (kind IN ('provider', 'translator')),
|
|
name TEXT NOT NULL,
|
|
-- UTC calendar day, `YYYY-MM-DD`.
|
|
day TEXT NOT NULL,
|
|
-- A provider unit is one download; a translator unit is one character of
|
|
-- source text sent (DESIGN.md §15: translators bill per character).
|
|
spent INTEGER NOT NULL DEFAULT 0 CHECK (spent >= 0),
|
|
PRIMARY KEY (kind, name, day)
|
|
) STRICT;
|