fix(growth): harden AI jobs and cost controls

This commit is contained in:
2026-08-21 01:48:47 +03:30
parent 86e9d7c5f9
commit a15c04cac1
13 changed files with 366 additions and 78 deletions

View File

@@ -20,8 +20,12 @@ CREATE TABLE IF NOT EXISTS growth_reports (
input_tokens bigint NOT NULL DEFAULT 0 CHECK (input_tokens >= 0),
output_tokens bigint NOT NULL DEFAULT 0 CHECK (output_tokens >= 0),
latency_ms bigint NOT NULL DEFAULT 0 CHECK (latency_ms >= 0),
provider_requests bigint NOT NULL DEFAULT 0 CHECK (provider_requests >= 0),
reserved_tokens bigint NOT NULL DEFAULT 0 CHECK (reserved_tokens >= 0),
provider_request_id text,
estimated_cost text,
lease_token text,
lease_expires_at timestamptz,
manual_refresh boolean NOT NULL DEFAULT false,
tehran_refresh_day date,
created_at timestamptz NOT NULL DEFAULT now(),
@@ -33,6 +37,14 @@ ALTER TABLE growth_reports ADD COLUMN IF NOT EXISTS provider_request_id text;
-- statement-break
ALTER TABLE growth_reports ADD COLUMN IF NOT EXISTS estimated_cost text;
-- statement-break
ALTER TABLE growth_reports ADD COLUMN IF NOT EXISTS provider_requests bigint NOT NULL DEFAULT 0 CHECK (provider_requests >= 0);
-- statement-break
ALTER TABLE growth_reports ADD COLUMN IF NOT EXISTS reserved_tokens bigint NOT NULL DEFAULT 0 CHECK (reserved_tokens >= 0);
-- statement-break
ALTER TABLE growth_reports ADD COLUMN IF NOT EXISTS lease_token text;
-- statement-break
ALTER TABLE growth_reports ADD COLUMN IF NOT EXISTS lease_expires_at timestamptz;
-- statement-break
ALTER TABLE growth_reports ALTER COLUMN deterministic_evidence DROP NOT NULL;
-- statement-break
CREATE UNIQUE INDEX IF NOT EXISTS growth_reports_current_fingerprint_idx