-- Infrastructure state shared by all egress callers; deliberately not tenant/RLS scoped. -- Run in an owner transaction and record @tactical-media-broadcast-hub/egress/001_host_budgets.sql -- in the application's schema_migrations(name, applied_at). This package never migrates at runtime. SET LOCAL lock_timeout = '5s'; CREATE TABLE host_budgets ( host text PRIMARY KEY CHECK (host <> '' AND host = lower(host)), capacity double precision NOT NULL CHECK (capacity >= 1 AND capacity < 'Infinity'::double precision), -- Tokens per fixed 10-second interval (fractional tokens support continuous refill). refill_per_interval double precision NOT NULL CHECK (refill_per_interval > 0 AND refill_per_interval < 'Infinity'::double precision), tokens double precision NOT NULL CHECK (tokens >= 0 AND tokens <= capacity), -- A future timestamp parks the bucket: no refill/debit until this deadline. updated_at timestamptz NOT NULL DEFAULT clock_timestamp() CHECK (isfinite(updated_at)) ); COMMENT ON TABLE host_budgets IS 'Infrastructure egress budgets; one IDNA lowercase host:effective-port key across callers and host classes. Retain while host is in use.';