refactor: drive pg sqlite copy from target schema

This commit is contained in:
HsungKayphoon
2026-05-16 17:29:14 +08:00
parent 527feb69db
commit f9f1fa928a
18 changed files with 628 additions and 5406 deletions

View File

@@ -111,63 +111,6 @@ CREATE TABLE IF NOT EXISTS `usage` (
KEY usage_wallet_id_idx (`wallet_id`)
);
CREATE TABLE IF NOT EXISTS usage_body_blobs (
`body_ref` VARCHAR(160) NOT NULL,
`request_id` VARCHAR(128) NOT NULL,
`body_field` VARCHAR(64) NOT NULL,
`payload_gzip` LONGBLOB NOT NULL,
`created_at` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
`updated_at` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY (`body_ref`),
UNIQUE KEY usage_body_blobs_request_id_field_key (`request_id`, `body_field`),
KEY usage_body_blobs_request_id_idx (`request_id`),
CONSTRAINT usage_body_blobs_request_id_fkey FOREIGN KEY (`request_id`) REFERENCES usage (`request_id`) ON DELETE CASCADE
);
CREATE TABLE IF NOT EXISTS usage_http_audits (
`request_id` VARCHAR(128) NOT NULL,
`request_headers` JSON,
`provider_request_headers` JSON,
`response_headers` JSON,
`client_response_headers` JSON,
`request_body_ref` VARCHAR(160),
`provider_request_body_ref` VARCHAR(160),
`response_body_ref` VARCHAR(160),
`client_response_body_ref` VARCHAR(160),
`request_body_state` VARCHAR(32),
`provider_request_body_state` VARCHAR(32),
`response_body_state` VARCHAR(32),
`client_response_body_state` VARCHAR(32),
`body_capture_mode` VARCHAR(32) NOT NULL DEFAULT 'none',
`created_at` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
`updated_at` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY (`request_id`),
KEY usage_http_audits_updated_at_idx (`updated_at`),
CONSTRAINT usage_http_audits_request_id_fkey FOREIGN KEY (`request_id`) REFERENCES usage (`request_id`) ON DELETE CASCADE
);
CREATE TABLE IF NOT EXISTS usage_routing_snapshots (
`request_id` VARCHAR(128) NOT NULL,
`candidate_id` VARCHAR(160),
`candidate_index` BIGINT,
`key_name` VARCHAR(255),
`planner_kind` VARCHAR(120),
`route_family` VARCHAR(80),
`route_kind` VARCHAR(80),
`execution_path` VARCHAR(80),
`local_execution_runtime_miss_reason` VARCHAR(120),
`selected_provider_id` VARCHAR(64),
`selected_endpoint_id` VARCHAR(64),
`selected_provider_api_key_id` VARCHAR(64),
`has_format_conversion` TINYINT(1),
`created_at` BIGINT NOT NULL DEFAULT 0,
`updated_at` BIGINT NOT NULL DEFAULT 0,
PRIMARY KEY (`request_id`),
KEY ix_usage_routing_snapshots_route_family_kind (`route_family`, `route_kind`),
KEY ix_usage_routing_snapshots_candidate_id (`candidate_id`),
CONSTRAINT usage_routing_snapshots_request_id_fkey FOREIGN KEY (`request_id`) REFERENCES usage (`request_id`) ON DELETE CASCADE
);
CREATE TABLE IF NOT EXISTS usage_settlement_snapshots (
`request_id` VARCHAR(128) NOT NULL,
`billing_status` VARCHAR(64) NOT NULL,

View File

@@ -18,26 +18,6 @@ CREATE TABLE IF NOT EXISTS stats_hourly (
`aggregated_at` BIGINT,
`created_at` BIGINT NOT NULL,
`updated_at` BIGINT NOT NULL,
`response_time_sum_ms` DOUBLE NOT NULL DEFAULT 0,
`response_time_samples` BIGINT NOT NULL DEFAULT 0,
`cache_hit_total_requests` BIGINT NOT NULL DEFAULT 0,
`cache_hit_requests` BIGINT NOT NULL DEFAULT 0,
`completed_total_requests` BIGINT NOT NULL DEFAULT 0,
`completed_cache_hit_requests` BIGINT NOT NULL DEFAULT 0,
`completed_input_tokens` BIGINT NOT NULL DEFAULT 0,
`completed_cache_creation_tokens` BIGINT NOT NULL DEFAULT 0,
`completed_cache_read_tokens` BIGINT NOT NULL DEFAULT 0,
`completed_total_input_context` BIGINT NOT NULL DEFAULT 0,
`completed_cache_creation_cost` DOUBLE NOT NULL DEFAULT 0,
`completed_cache_read_cost` DOUBLE NOT NULL DEFAULT 0,
`settled_total_cost` DOUBLE NOT NULL DEFAULT 0,
`settled_total_requests` BIGINT NOT NULL DEFAULT 0,
`settled_input_tokens` BIGINT NOT NULL DEFAULT 0,
`settled_output_tokens` BIGINT NOT NULL DEFAULT 0,
`settled_cache_creation_tokens` BIGINT NOT NULL DEFAULT 0,
`settled_cache_read_tokens` BIGINT NOT NULL DEFAULT 0,
`settled_first_finalized_at_unix_secs` BIGINT,
`settled_last_finalized_at_unix_secs` BIGINT,
PRIMARY KEY (`id`),
UNIQUE KEY uq_stats_hourly_hour (`hour_utc`)
);
@@ -75,19 +55,6 @@ CREATE TABLE IF NOT EXISTS stats_hourly_user (
`total_cost` DOUBLE NOT NULL DEFAULT 0,
`created_at` BIGINT NOT NULL,
`updated_at` BIGINT NOT NULL,
`cache_creation_tokens` BIGINT NOT NULL DEFAULT 0,
`cache_read_tokens` BIGINT NOT NULL DEFAULT 0,
`actual_total_cost` DOUBLE NOT NULL DEFAULT 0,
`response_time_sum_ms` DOUBLE NOT NULL DEFAULT 0,
`response_time_samples` BIGINT NOT NULL DEFAULT 0,
`settled_total_cost` DOUBLE NOT NULL DEFAULT 0,
`settled_total_requests` BIGINT NOT NULL DEFAULT 0,
`settled_input_tokens` BIGINT NOT NULL DEFAULT 0,
`settled_output_tokens` BIGINT NOT NULL DEFAULT 0,
`settled_cache_creation_tokens` BIGINT NOT NULL DEFAULT 0,
`settled_cache_read_tokens` BIGINT NOT NULL DEFAULT 0,
`settled_first_finalized_at_unix_secs` BIGINT,
`settled_last_finalized_at_unix_secs` BIGINT,
PRIMARY KEY (`id`),
UNIQUE KEY uq_stats_hourly_user (`hour_utc`, `user_id`)
);
@@ -103,8 +70,6 @@ CREATE TABLE IF NOT EXISTS stats_hourly_user_model (
`total_cost` DOUBLE NOT NULL DEFAULT 0,
`created_at` BIGINT NOT NULL,
`updated_at` BIGINT NOT NULL,
`response_time_sum_ms` DOUBLE NOT NULL DEFAULT 0,
`response_time_samples` BIGINT NOT NULL DEFAULT 0,
PRIMARY KEY (`id`),
UNIQUE KEY uq_stats_hourly_user_model (`hour_utc`, `user_id`, `model`)
);
@@ -133,8 +98,6 @@ CREATE TABLE IF NOT EXISTS stats_hourly_model (
`avg_response_time_ms` DOUBLE NOT NULL DEFAULT 0,
`created_at` BIGINT NOT NULL,
`updated_at` BIGINT NOT NULL,
`response_time_sum_ms` DOUBLE NOT NULL DEFAULT 0,
`response_time_samples` BIGINT NOT NULL DEFAULT 0,
PRIMARY KEY (`id`),
UNIQUE KEY uq_stats_hourly_model (`hour_utc`, `model`)
);
@@ -183,30 +146,6 @@ CREATE TABLE IF NOT EXISTS stats_daily (
`p50_first_byte_time_ms` BIGINT,
`p90_first_byte_time_ms` BIGINT,
`p99_first_byte_time_ms` BIGINT,
`effective_input_tokens` BIGINT NOT NULL DEFAULT 0,
`total_input_context` BIGINT NOT NULL DEFAULT 0,
`response_time_sum_ms` DOUBLE NOT NULL DEFAULT 0,
`response_time_samples` BIGINT NOT NULL DEFAULT 0,
`cache_creation_ephemeral_5m_tokens` BIGINT NOT NULL DEFAULT 0,
`cache_creation_ephemeral_1h_tokens` BIGINT NOT NULL DEFAULT 0,
`cache_hit_total_requests` BIGINT NOT NULL DEFAULT 0,
`cache_hit_requests` BIGINT NOT NULL DEFAULT 0,
`completed_total_requests` BIGINT NOT NULL DEFAULT 0,
`completed_cache_hit_requests` BIGINT NOT NULL DEFAULT 0,
`completed_input_tokens` BIGINT NOT NULL DEFAULT 0,
`completed_cache_creation_tokens` BIGINT NOT NULL DEFAULT 0,
`completed_cache_read_tokens` BIGINT NOT NULL DEFAULT 0,
`completed_total_input_context` BIGINT NOT NULL DEFAULT 0,
`completed_cache_creation_cost` DOUBLE NOT NULL DEFAULT 0,
`completed_cache_read_cost` DOUBLE NOT NULL DEFAULT 0,
`settled_total_cost` DOUBLE NOT NULL DEFAULT 0,
`settled_total_requests` BIGINT NOT NULL DEFAULT 0,
`settled_input_tokens` BIGINT NOT NULL DEFAULT 0,
`settled_output_tokens` BIGINT NOT NULL DEFAULT 0,
`settled_cache_creation_tokens` BIGINT NOT NULL DEFAULT 0,
`settled_cache_read_tokens` BIGINT NOT NULL DEFAULT 0,
`settled_first_finalized_at_unix_secs` BIGINT,
`settled_last_finalized_at_unix_secs` BIGINT,
PRIMARY KEY (`id`),
UNIQUE KEY uq_stats_daily_date (`date`)
);
@@ -224,10 +163,6 @@ CREATE TABLE IF NOT EXISTS stats_daily_model (
`avg_response_time_ms` DOUBLE NOT NULL DEFAULT 0,
`created_at` BIGINT NOT NULL,
`updated_at` BIGINT NOT NULL,
`cache_creation_ephemeral_5m_tokens` BIGINT NOT NULL DEFAULT 0,
`cache_creation_ephemeral_1h_tokens` BIGINT NOT NULL DEFAULT 0,
`response_time_sum_ms` DOUBLE NOT NULL DEFAULT 0,
`response_time_samples` BIGINT NOT NULL DEFAULT 0,
PRIMARY KEY (`id`),
UNIQUE KEY uq_stats_daily_model (`date`, `model`)
);
@@ -295,314 +230,7 @@ CREATE TABLE IF NOT EXISTS stats_user_daily (
`username` VARCHAR(255),
`created_at` BIGINT NOT NULL,
`updated_at` BIGINT NOT NULL,
`actual_total_cost` DOUBLE NOT NULL DEFAULT 0,
`response_time_sum_ms` DOUBLE NOT NULL DEFAULT 0,
`response_time_samples` BIGINT NOT NULL DEFAULT 0,
`effective_input_tokens` BIGINT NOT NULL DEFAULT 0,
`total_input_context` BIGINT NOT NULL DEFAULT 0,
`cache_creation_cost` DOUBLE NOT NULL DEFAULT 0,
`cache_read_cost` DOUBLE NOT NULL DEFAULT 0,
`cache_creation_ephemeral_5m_tokens` BIGINT NOT NULL DEFAULT 0,
`cache_creation_ephemeral_1h_tokens` BIGINT NOT NULL DEFAULT 0,
`settled_total_cost` DOUBLE NOT NULL DEFAULT 0,
`settled_total_requests` BIGINT NOT NULL DEFAULT 0,
`settled_input_tokens` BIGINT NOT NULL DEFAULT 0,
`settled_output_tokens` BIGINT NOT NULL DEFAULT 0,
`settled_cache_creation_tokens` BIGINT NOT NULL DEFAULT 0,
`settled_cache_read_tokens` BIGINT NOT NULL DEFAULT 0,
`settled_first_finalized_at_unix_secs` BIGINT,
`settled_last_finalized_at_unix_secs` BIGINT,
PRIMARY KEY (`id`),
UNIQUE KEY uq_stats_user_daily (`date`, `user_id`)
);
CREATE TABLE IF NOT EXISTS stats_user_summary (
`id` VARCHAR(64) NOT NULL,
`user_id` VARCHAR(64) NOT NULL,
`username` VARCHAR(255),
`cutoff_date` BIGINT NOT NULL,
`all_time_requests` BIGINT NOT NULL DEFAULT 0,
`all_time_success_requests` BIGINT NOT NULL DEFAULT 0,
`all_time_error_requests` BIGINT NOT NULL DEFAULT 0,
`all_time_input_tokens` BIGINT NOT NULL DEFAULT 0,
`all_time_output_tokens` BIGINT NOT NULL DEFAULT 0,
`all_time_cache_creation_tokens` BIGINT NOT NULL DEFAULT 0,
`all_time_cache_read_tokens` BIGINT NOT NULL DEFAULT 0,
`all_time_cost` DOUBLE NOT NULL DEFAULT 0,
`all_time_actual_cost` DOUBLE NOT NULL DEFAULT 0,
`active_days` BIGINT NOT NULL DEFAULT 0,
`first_active_date` BIGINT,
`last_active_date` BIGINT,
`created_at` BIGINT NOT NULL DEFAULT 0,
`updated_at` BIGINT NOT NULL DEFAULT 0,
PRIMARY KEY (`id`),
UNIQUE KEY uq_stats_user_summary_user_id (`user_id`),
KEY idx_stats_user_summary_cutoff_date (`cutoff_date`)
);
CREATE TABLE IF NOT EXISTS stats_user_daily_model (
`id` VARCHAR(64) NOT NULL,
`user_id` VARCHAR(64) NOT NULL,
`username` VARCHAR(255),
`date` BIGINT NOT NULL,
`model` VARCHAR(255) NOT NULL,
`total_requests` BIGINT NOT NULL DEFAULT 0,
`success_requests` BIGINT NOT NULL DEFAULT 0,
`input_tokens` BIGINT NOT NULL DEFAULT 0,
`effective_input_tokens` BIGINT NOT NULL DEFAULT 0,
`output_tokens` BIGINT NOT NULL DEFAULT 0,
`total_tokens` BIGINT NOT NULL DEFAULT 0,
`total_input_context` BIGINT NOT NULL DEFAULT 0,
`cache_creation_tokens` BIGINT NOT NULL DEFAULT 0,
`cache_creation_ephemeral_5m_tokens` BIGINT NOT NULL DEFAULT 0,
`cache_creation_ephemeral_1h_tokens` BIGINT NOT NULL DEFAULT 0,
`cache_read_tokens` BIGINT NOT NULL DEFAULT 0,
`total_cost` DOUBLE NOT NULL DEFAULT 0,
`actual_total_cost` DOUBLE NOT NULL DEFAULT 0,
`response_time_sum_ms` DOUBLE NOT NULL DEFAULT 0,
`response_time_samples` BIGINT NOT NULL DEFAULT 0,
`successful_response_time_sum_ms` DOUBLE NOT NULL DEFAULT 0,
`successful_response_time_samples` BIGINT NOT NULL DEFAULT 0,
`created_at` BIGINT NOT NULL DEFAULT 0,
`updated_at` BIGINT NOT NULL DEFAULT 0,
PRIMARY KEY (`id`),
UNIQUE KEY uq_stats_user_daily_model_user_id_date_model (`user_id`, `date`, `model`),
KEY idx_stats_user_daily_model_date (`date`),
KEY idx_stats_user_daily_model_user_id (`user_id`)
);
CREATE TABLE IF NOT EXISTS stats_user_daily_provider (
`id` VARCHAR(64) NOT NULL,
`user_id` VARCHAR(64) NOT NULL,
`username` VARCHAR(255),
`date` BIGINT NOT NULL,
`provider_name` VARCHAR(255) NOT NULL,
`total_requests` BIGINT NOT NULL DEFAULT 0,
`success_requests` BIGINT NOT NULL DEFAULT 0,
`input_tokens` BIGINT NOT NULL DEFAULT 0,
`effective_input_tokens` BIGINT NOT NULL DEFAULT 0,
`output_tokens` BIGINT NOT NULL DEFAULT 0,
`total_tokens` BIGINT NOT NULL DEFAULT 0,
`total_input_context` BIGINT NOT NULL DEFAULT 0,
`cache_creation_tokens` BIGINT NOT NULL DEFAULT 0,
`cache_creation_ephemeral_5m_tokens` BIGINT NOT NULL DEFAULT 0,
`cache_creation_ephemeral_1h_tokens` BIGINT NOT NULL DEFAULT 0,
`cache_read_tokens` BIGINT NOT NULL DEFAULT 0,
`total_cost` DOUBLE NOT NULL DEFAULT 0,
`actual_total_cost` DOUBLE NOT NULL DEFAULT 0,
`response_time_sum_ms` DOUBLE NOT NULL DEFAULT 0,
`response_time_samples` BIGINT NOT NULL DEFAULT 0,
`successful_response_time_sum_ms` DOUBLE NOT NULL DEFAULT 0,
`successful_response_time_samples` BIGINT NOT NULL DEFAULT 0,
`created_at` BIGINT NOT NULL DEFAULT 0,
`updated_at` BIGINT NOT NULL DEFAULT 0,
PRIMARY KEY (`id`),
UNIQUE KEY uq_stats_user_daily_provider_user_id_date_provider_name (`user_id`, `date`, `provider_name`),
KEY idx_stats_user_daily_provider_date (`date`),
KEY idx_stats_user_daily_provider_user_id (`user_id`)
);
CREATE TABLE IF NOT EXISTS stats_user_daily_api_format (
`id` VARCHAR(64) NOT NULL,
`user_id` VARCHAR(64) NOT NULL,
`username` VARCHAR(255),
`date` BIGINT NOT NULL,
`api_format` VARCHAR(255) NOT NULL,
`total_requests` BIGINT NOT NULL DEFAULT 0,
`success_requests` BIGINT NOT NULL DEFAULT 0,
`input_tokens` BIGINT NOT NULL DEFAULT 0,
`effective_input_tokens` BIGINT NOT NULL DEFAULT 0,
`output_tokens` BIGINT NOT NULL DEFAULT 0,
`total_tokens` BIGINT NOT NULL DEFAULT 0,
`total_input_context` BIGINT NOT NULL DEFAULT 0,
`cache_creation_tokens` BIGINT NOT NULL DEFAULT 0,
`cache_creation_ephemeral_5m_tokens` BIGINT NOT NULL DEFAULT 0,
`cache_creation_ephemeral_1h_tokens` BIGINT NOT NULL DEFAULT 0,
`cache_read_tokens` BIGINT NOT NULL DEFAULT 0,
`total_cost` DOUBLE NOT NULL DEFAULT 0,
`actual_total_cost` DOUBLE NOT NULL DEFAULT 0,
`response_time_sum_ms` DOUBLE NOT NULL DEFAULT 0,
`response_time_samples` BIGINT NOT NULL DEFAULT 0,
`successful_response_time_sum_ms` DOUBLE NOT NULL DEFAULT 0,
`successful_response_time_samples` BIGINT NOT NULL DEFAULT 0,
`created_at` BIGINT NOT NULL DEFAULT 0,
`updated_at` BIGINT NOT NULL DEFAULT 0,
PRIMARY KEY (`id`),
UNIQUE KEY uq_stats_user_daily_api_format_user_id_date_api_format (`user_id`, `date`, `api_format`),
KEY idx_stats_user_daily_api_format_date (`date`),
KEY idx_stats_user_daily_api_format_user_id (`user_id`)
);
CREATE TABLE IF NOT EXISTS stats_daily_model_provider (
`id` VARCHAR(64) NOT NULL,
`date` BIGINT NOT NULL,
`model` VARCHAR(255) NOT NULL,
`provider_name` VARCHAR(255) NOT NULL,
`total_requests` BIGINT NOT NULL DEFAULT 0,
`total_tokens` BIGINT NOT NULL DEFAULT 0,
`total_cost` DOUBLE NOT NULL DEFAULT 0,
`response_time_sum_ms` DOUBLE NOT NULL DEFAULT 0,
`response_time_samples` BIGINT NOT NULL DEFAULT 0,
`created_at` BIGINT NOT NULL DEFAULT 0,
`updated_at` BIGINT NOT NULL DEFAULT 0,
PRIMARY KEY (`id`),
UNIQUE KEY uq_stats_daily_model_provider_date_model_provider_name (`date`, `model`, `provider_name`),
KEY idx_stats_daily_model_provider_date (`date`),
KEY idx_stats_daily_model_provider_date_model_provider (`date`, `model`, `provider_name`)
);
CREATE TABLE IF NOT EXISTS stats_user_daily_model_provider (
`id` VARCHAR(64) NOT NULL,
`user_id` VARCHAR(64) NOT NULL,
`username` VARCHAR(255),
`date` BIGINT NOT NULL,
`model` VARCHAR(255) NOT NULL,
`provider_name` VARCHAR(255) NOT NULL,
`total_requests` BIGINT NOT NULL DEFAULT 0,
`total_tokens` BIGINT NOT NULL DEFAULT 0,
`total_cost` DOUBLE NOT NULL DEFAULT 0,
`response_time_sum_ms` DOUBLE NOT NULL DEFAULT 0,
`response_time_samples` BIGINT NOT NULL DEFAULT 0,
`created_at` BIGINT NOT NULL DEFAULT 0,
`updated_at` BIGINT NOT NULL DEFAULT 0,
PRIMARY KEY (`id`),
UNIQUE KEY uq_stats_user_daily_model_provider_user_id_date_model_provider_name (`user_id`, `date`, `model`, `provider_name`),
KEY idx_stats_user_daily_model_provider_date (`date`),
KEY idx_stats_user_daily_model_provider_user_date (`user_id`, `date`)
);
CREATE TABLE IF NOT EXISTS stats_daily_cost_savings (
`id` VARCHAR(64) NOT NULL,
`date` BIGINT NOT NULL,
`cache_read_tokens` BIGINT NOT NULL DEFAULT 0,
`cache_read_cost` DOUBLE NOT NULL DEFAULT 0,
`cache_creation_cost` DOUBLE NOT NULL DEFAULT 0,
`estimated_full_cost` DOUBLE NOT NULL DEFAULT 0,
`created_at` BIGINT NOT NULL DEFAULT 0,
`updated_at` BIGINT NOT NULL DEFAULT 0,
PRIMARY KEY (`id`),
UNIQUE KEY uq_stats_daily_cost_savings_date (`date`),
KEY idx_stats_daily_cost_savings_date (`date`)
);
CREATE TABLE IF NOT EXISTS stats_daily_cost_savings_provider (
`id` VARCHAR(64) NOT NULL,
`date` BIGINT NOT NULL,
`provider_name` VARCHAR(255) NOT NULL,
`cache_read_tokens` BIGINT NOT NULL DEFAULT 0,
`cache_read_cost` DOUBLE NOT NULL DEFAULT 0,
`cache_creation_cost` DOUBLE NOT NULL DEFAULT 0,
`estimated_full_cost` DOUBLE NOT NULL DEFAULT 0,
`created_at` BIGINT NOT NULL DEFAULT 0,
`updated_at` BIGINT NOT NULL DEFAULT 0,
PRIMARY KEY (`id`),
UNIQUE KEY uq_stats_daily_cost_savings_provider_date_provider_name (`date`, `provider_name`),
KEY idx_stats_daily_cost_savings_provider_date (`date`),
KEY idx_stats_daily_cost_savings_provider_date_provider (`date`, `provider_name`)
);
CREATE TABLE IF NOT EXISTS stats_daily_cost_savings_model (
`id` VARCHAR(64) NOT NULL,
`date` BIGINT NOT NULL,
`model` VARCHAR(255) NOT NULL,
`cache_read_tokens` BIGINT NOT NULL DEFAULT 0,
`cache_read_cost` DOUBLE NOT NULL DEFAULT 0,
`cache_creation_cost` DOUBLE NOT NULL DEFAULT 0,
`estimated_full_cost` DOUBLE NOT NULL DEFAULT 0,
`created_at` BIGINT NOT NULL DEFAULT 0,
`updated_at` BIGINT NOT NULL DEFAULT 0,
PRIMARY KEY (`id`),
UNIQUE KEY uq_stats_daily_cost_savings_model_date_model (`date`, `model`),
KEY idx_stats_daily_cost_savings_model_date (`date`),
KEY idx_stats_daily_cost_savings_model_date_model (`date`, `model`)
);
CREATE TABLE IF NOT EXISTS stats_daily_cost_savings_model_provider (
`id` VARCHAR(64) NOT NULL,
`date` BIGINT NOT NULL,
`model` VARCHAR(255) NOT NULL,
`provider_name` VARCHAR(255) NOT NULL,
`cache_read_tokens` BIGINT NOT NULL DEFAULT 0,
`cache_read_cost` DOUBLE NOT NULL DEFAULT 0,
`cache_creation_cost` DOUBLE NOT NULL DEFAULT 0,
`estimated_full_cost` DOUBLE NOT NULL DEFAULT 0,
`created_at` BIGINT NOT NULL DEFAULT 0,
`updated_at` BIGINT NOT NULL DEFAULT 0,
PRIMARY KEY (`id`),
UNIQUE KEY uq_stats_daily_cost_savings_model_provider_date_model_provider_name (`date`, `model`, `provider_name`),
KEY idx_stats_daily_cost_savings_model_provider_date (`date`),
KEY idx_stats_daily_cost_savings_model_provider_date_dims (`date`, `model`, `provider_name`)
);
CREATE TABLE IF NOT EXISTS stats_user_daily_cost_savings (
`id` VARCHAR(64) NOT NULL,
`user_id` VARCHAR(64) NOT NULL,
`username` VARCHAR(255),
`date` BIGINT NOT NULL,
`cache_read_tokens` BIGINT NOT NULL DEFAULT 0,
`cache_read_cost` DOUBLE NOT NULL DEFAULT 0,
`cache_creation_cost` DOUBLE NOT NULL DEFAULT 0,
`estimated_full_cost` DOUBLE NOT NULL DEFAULT 0,
`created_at` BIGINT NOT NULL DEFAULT 0,
`updated_at` BIGINT NOT NULL DEFAULT 0,
PRIMARY KEY (`id`),
UNIQUE KEY uq_stats_user_daily_cost_savings_user_id_date (`user_id`, `date`),
KEY idx_stats_user_daily_cost_savings_date (`date`),
KEY idx_stats_user_daily_cost_savings_user_date (`user_id`, `date`)
);
CREATE TABLE IF NOT EXISTS stats_user_daily_cost_savings_provider (
`id` VARCHAR(64) NOT NULL,
`user_id` VARCHAR(64) NOT NULL,
`username` VARCHAR(255),
`date` BIGINT NOT NULL,
`provider_name` VARCHAR(255) NOT NULL,
`cache_read_tokens` BIGINT NOT NULL DEFAULT 0,
`cache_read_cost` DOUBLE NOT NULL DEFAULT 0,
`cache_creation_cost` DOUBLE NOT NULL DEFAULT 0,
`estimated_full_cost` DOUBLE NOT NULL DEFAULT 0,
`created_at` BIGINT NOT NULL DEFAULT 0,
`updated_at` BIGINT NOT NULL DEFAULT 0,
PRIMARY KEY (`id`),
UNIQUE KEY uq_stats_user_daily_cost_savings_provider_user_id_date_provider_name (`user_id`, `date`, `provider_name`),
KEY idx_stats_user_daily_cost_savings_provider_date (`date`),
KEY idx_stats_user_daily_cost_savings_provider_user_date (`user_id`, `date`)
);
CREATE TABLE IF NOT EXISTS stats_user_daily_cost_savings_model (
`id` VARCHAR(64) NOT NULL,
`user_id` VARCHAR(64) NOT NULL,
`username` VARCHAR(255),
`date` BIGINT NOT NULL,
`model` VARCHAR(255) NOT NULL,
`cache_read_tokens` BIGINT NOT NULL DEFAULT 0,
`cache_read_cost` DOUBLE NOT NULL DEFAULT 0,
`cache_creation_cost` DOUBLE NOT NULL DEFAULT 0,
`estimated_full_cost` DOUBLE NOT NULL DEFAULT 0,
`created_at` BIGINT NOT NULL DEFAULT 0,
`updated_at` BIGINT NOT NULL DEFAULT 0,
PRIMARY KEY (`id`),
UNIQUE KEY uq_stats_user_daily_cost_savings_model_user_id_date_model (`user_id`, `date`, `model`),
KEY idx_stats_user_daily_cost_savings_model_date (`date`),
KEY idx_stats_user_daily_cost_savings_model_user_date (`user_id`, `date`)
);
CREATE TABLE IF NOT EXISTS stats_user_daily_cost_savings_model_provider (
`id` VARCHAR(64) NOT NULL,
`user_id` VARCHAR(64) NOT NULL,
`username` VARCHAR(255),
`date` BIGINT NOT NULL,
`model` VARCHAR(255) NOT NULL,
`provider_name` VARCHAR(255) NOT NULL,
`cache_read_tokens` BIGINT NOT NULL DEFAULT 0,
`cache_read_cost` DOUBLE NOT NULL DEFAULT 0,
`cache_creation_cost` DOUBLE NOT NULL DEFAULT 0,
`estimated_full_cost` DOUBLE NOT NULL DEFAULT 0,
`created_at` BIGINT NOT NULL DEFAULT 0,
`updated_at` BIGINT NOT NULL DEFAULT 0,
PRIMARY KEY (`id`),
UNIQUE KEY uq_stats_user_daily_cost_savings_model_provider_user_id_date_model_provider_name (`user_id`, `date`, `model`, `provider_name`),
KEY idx_stats_user_daily_cost_savings_model_provider_date (`date`),
KEY idx_stats_user_daily_cost_savings_model_provider_user_date (`user_id`, `date`)
);

View File

@@ -112,66 +112,6 @@ CREATE INDEX IF NOT EXISTS usage_request_id_idx ON public.usage USING btree (req
CREATE INDEX IF NOT EXISTS usage_user_id_idx ON public.usage USING btree (user_id);
CREATE INDEX IF NOT EXISTS usage_wallet_id_idx ON public.usage USING btree (wallet_id);
CREATE TABLE IF NOT EXISTS public.usage_body_blobs (
body_ref character varying(160) NOT NULL,
request_id character varying(128) NOT NULL,
body_field character varying(64) NOT NULL,
payload_gzip bytea NOT NULL,
created_at timestamp with time zone DEFAULT CURRENT_TIMESTAMP NOT NULL,
updated_at timestamp with time zone DEFAULT CURRENT_TIMESTAMP NOT NULL
);
ALTER TABLE ONLY public.usage_body_blobs ADD CONSTRAINT usage_body_blobs_pkey PRIMARY KEY (body_ref);
ALTER TABLE ONLY public.usage_body_blobs ADD CONSTRAINT usage_body_blobs_request_id_field_key UNIQUE (request_id, body_field);
CREATE INDEX IF NOT EXISTS usage_body_blobs_request_id_idx ON public.usage_body_blobs USING btree (request_id);
ALTER TABLE ONLY public.usage_body_blobs ADD CONSTRAINT usage_body_blobs_request_id_fkey FOREIGN KEY (request_id) REFERENCES public.usage(request_id) ON DELETE CASCADE;
CREATE TABLE IF NOT EXISTS public.usage_http_audits (
request_id character varying(128) NOT NULL,
request_headers jsonb,
provider_request_headers jsonb,
response_headers jsonb,
client_response_headers jsonb,
request_body_ref character varying(160),
provider_request_body_ref character varying(160),
response_body_ref character varying(160),
client_response_body_ref character varying(160),
request_body_state character varying(32),
provider_request_body_state character varying(32),
response_body_state character varying(32),
client_response_body_state character varying(32),
body_capture_mode character varying(32) DEFAULT 'none' NOT NULL,
created_at timestamp with time zone DEFAULT CURRENT_TIMESTAMP NOT NULL,
updated_at timestamp with time zone DEFAULT CURRENT_TIMESTAMP NOT NULL
);
ALTER TABLE ONLY public.usage_http_audits ADD CONSTRAINT usage_http_audits_pkey PRIMARY KEY (request_id);
CREATE INDEX IF NOT EXISTS usage_http_audits_updated_at_idx ON public.usage_http_audits USING btree (updated_at);
ALTER TABLE ONLY public.usage_http_audits ADD CONSTRAINT usage_http_audits_request_id_fkey FOREIGN KEY (request_id) REFERENCES public.usage(request_id) ON DELETE CASCADE;
CREATE TABLE IF NOT EXISTS public.usage_routing_snapshots (
request_id character varying(128) NOT NULL,
candidate_id character varying(160),
candidate_index bigint,
key_name character varying(255),
planner_kind character varying(120),
route_family character varying(80),
route_kind character varying(80),
execution_path character varying(80),
local_execution_runtime_miss_reason character varying(120),
selected_provider_id character varying(64),
selected_endpoint_id character varying(64),
selected_provider_api_key_id character varying(64),
has_format_conversion boolean,
created_at bigint DEFAULT 0 NOT NULL,
updated_at bigint DEFAULT 0 NOT NULL
);
ALTER TABLE ONLY public.usage_routing_snapshots ADD CONSTRAINT usage_routing_snapshots_pkey PRIMARY KEY (request_id);
CREATE INDEX IF NOT EXISTS ix_usage_routing_snapshots_route_family_kind ON public.usage_routing_snapshots USING btree (route_family, route_kind);
CREATE INDEX IF NOT EXISTS ix_usage_routing_snapshots_candidate_id ON public.usage_routing_snapshots USING btree (candidate_id);
ALTER TABLE ONLY public.usage_routing_snapshots ADD CONSTRAINT usage_routing_snapshots_request_id_fkey FOREIGN KEY (request_id) REFERENCES public.usage(request_id) ON DELETE CASCADE;
CREATE TABLE IF NOT EXISTS public.usage_settlement_snapshots (
request_id character varying(128) NOT NULL,
billing_status character varying(64) NOT NULL,

View File

@@ -17,27 +17,7 @@ CREATE TABLE IF NOT EXISTS public.stats_hourly (
is_complete boolean DEFAULT false NOT NULL,
aggregated_at bigint,
created_at bigint NOT NULL,
updated_at bigint NOT NULL,
response_time_sum_ms double precision DEFAULT 0 NOT NULL,
response_time_samples bigint DEFAULT 0 NOT NULL,
cache_hit_total_requests bigint DEFAULT 0 NOT NULL,
cache_hit_requests bigint DEFAULT 0 NOT NULL,
completed_total_requests bigint DEFAULT 0 NOT NULL,
completed_cache_hit_requests bigint DEFAULT 0 NOT NULL,
completed_input_tokens bigint DEFAULT 0 NOT NULL,
completed_cache_creation_tokens bigint DEFAULT 0 NOT NULL,
completed_cache_read_tokens bigint DEFAULT 0 NOT NULL,
completed_total_input_context bigint DEFAULT 0 NOT NULL,
completed_cache_creation_cost double precision DEFAULT 0 NOT NULL,
completed_cache_read_cost double precision DEFAULT 0 NOT NULL,
settled_total_cost double precision DEFAULT 0 NOT NULL,
settled_total_requests bigint DEFAULT 0 NOT NULL,
settled_input_tokens bigint DEFAULT 0 NOT NULL,
settled_output_tokens bigint DEFAULT 0 NOT NULL,
settled_cache_creation_tokens bigint DEFAULT 0 NOT NULL,
settled_cache_read_tokens bigint DEFAULT 0 NOT NULL,
settled_first_finalized_at_unix_secs bigint,
settled_last_finalized_at_unix_secs bigint
updated_at bigint NOT NULL
);
ALTER TABLE ONLY public.stats_hourly ADD CONSTRAINT stats_hourly_pkey PRIMARY KEY (id);
@@ -76,20 +56,7 @@ CREATE TABLE IF NOT EXISTS public.stats_hourly_user (
output_tokens bigint DEFAULT 0 NOT NULL,
total_cost double precision DEFAULT 0 NOT NULL,
created_at bigint NOT NULL,
updated_at bigint NOT NULL,
cache_creation_tokens bigint DEFAULT 0 NOT NULL,
cache_read_tokens bigint DEFAULT 0 NOT NULL,
actual_total_cost double precision DEFAULT 0 NOT NULL,
response_time_sum_ms double precision DEFAULT 0 NOT NULL,
response_time_samples bigint DEFAULT 0 NOT NULL,
settled_total_cost double precision DEFAULT 0 NOT NULL,
settled_total_requests bigint DEFAULT 0 NOT NULL,
settled_input_tokens bigint DEFAULT 0 NOT NULL,
settled_output_tokens bigint DEFAULT 0 NOT NULL,
settled_cache_creation_tokens bigint DEFAULT 0 NOT NULL,
settled_cache_read_tokens bigint DEFAULT 0 NOT NULL,
settled_first_finalized_at_unix_secs bigint,
settled_last_finalized_at_unix_secs bigint
updated_at bigint NOT NULL
);
ALTER TABLE ONLY public.stats_hourly_user ADD CONSTRAINT stats_hourly_user_pkey PRIMARY KEY (id);
@@ -105,9 +72,7 @@ CREATE TABLE IF NOT EXISTS public.stats_hourly_user_model (
output_tokens bigint DEFAULT 0 NOT NULL,
total_cost double precision DEFAULT 0 NOT NULL,
created_at bigint NOT NULL,
updated_at bigint NOT NULL,
response_time_sum_ms double precision DEFAULT 0 NOT NULL,
response_time_samples bigint DEFAULT 0 NOT NULL
updated_at bigint NOT NULL
);
ALTER TABLE ONLY public.stats_hourly_user_model ADD CONSTRAINT stats_hourly_user_model_pkey PRIMARY KEY (id);
@@ -137,9 +102,7 @@ CREATE TABLE IF NOT EXISTS public.stats_hourly_model (
total_cost double precision DEFAULT 0 NOT NULL,
avg_response_time_ms double precision DEFAULT 0 NOT NULL,
created_at bigint NOT NULL,
updated_at bigint NOT NULL,
response_time_sum_ms double precision DEFAULT 0 NOT NULL,
response_time_samples bigint DEFAULT 0 NOT NULL
updated_at bigint NOT NULL
);
ALTER TABLE ONLY public.stats_hourly_model ADD CONSTRAINT stats_hourly_model_pkey PRIMARY KEY (id);
@@ -189,31 +152,7 @@ CREATE TABLE IF NOT EXISTS public.stats_daily (
p99_response_time_ms bigint,
p50_first_byte_time_ms bigint,
p90_first_byte_time_ms bigint,
p99_first_byte_time_ms bigint,
effective_input_tokens bigint DEFAULT 0 NOT NULL,
total_input_context bigint DEFAULT 0 NOT NULL,
response_time_sum_ms double precision DEFAULT 0 NOT NULL,
response_time_samples bigint DEFAULT 0 NOT NULL,
cache_creation_ephemeral_5m_tokens bigint DEFAULT 0 NOT NULL,
cache_creation_ephemeral_1h_tokens bigint DEFAULT 0 NOT NULL,
cache_hit_total_requests bigint DEFAULT 0 NOT NULL,
cache_hit_requests bigint DEFAULT 0 NOT NULL,
completed_total_requests bigint DEFAULT 0 NOT NULL,
completed_cache_hit_requests bigint DEFAULT 0 NOT NULL,
completed_input_tokens bigint DEFAULT 0 NOT NULL,
completed_cache_creation_tokens bigint DEFAULT 0 NOT NULL,
completed_cache_read_tokens bigint DEFAULT 0 NOT NULL,
completed_total_input_context bigint DEFAULT 0 NOT NULL,
completed_cache_creation_cost double precision DEFAULT 0 NOT NULL,
completed_cache_read_cost double precision DEFAULT 0 NOT NULL,
settled_total_cost double precision DEFAULT 0 NOT NULL,
settled_total_requests bigint DEFAULT 0 NOT NULL,
settled_input_tokens bigint DEFAULT 0 NOT NULL,
settled_output_tokens bigint DEFAULT 0 NOT NULL,
settled_cache_creation_tokens bigint DEFAULT 0 NOT NULL,
settled_cache_read_tokens bigint DEFAULT 0 NOT NULL,
settled_first_finalized_at_unix_secs bigint,
settled_last_finalized_at_unix_secs bigint
p99_first_byte_time_ms bigint
);
ALTER TABLE ONLY public.stats_daily ADD CONSTRAINT stats_daily_pkey PRIMARY KEY (id);
@@ -231,11 +170,7 @@ CREATE TABLE IF NOT EXISTS public.stats_daily_model (
total_cost double precision DEFAULT 0 NOT NULL,
avg_response_time_ms double precision DEFAULT 0 NOT NULL,
created_at bigint NOT NULL,
updated_at bigint NOT NULL,
cache_creation_ephemeral_5m_tokens bigint DEFAULT 0 NOT NULL,
cache_creation_ephemeral_1h_tokens bigint DEFAULT 0 NOT NULL,
response_time_sum_ms double precision DEFAULT 0 NOT NULL,
response_time_samples bigint DEFAULT 0 NOT NULL
updated_at bigint NOT NULL
);
ALTER TABLE ONLY public.stats_daily_model ADD CONSTRAINT stats_daily_model_pkey PRIMARY KEY (id);
@@ -306,330 +241,9 @@ CREATE TABLE IF NOT EXISTS public.stats_user_daily (
total_cost double precision DEFAULT 0 NOT NULL,
username character varying(255),
created_at bigint NOT NULL,
updated_at bigint NOT NULL,
actual_total_cost double precision DEFAULT 0 NOT NULL,
response_time_sum_ms double precision DEFAULT 0 NOT NULL,
response_time_samples bigint DEFAULT 0 NOT NULL,
effective_input_tokens bigint DEFAULT 0 NOT NULL,
total_input_context bigint DEFAULT 0 NOT NULL,
cache_creation_cost double precision DEFAULT 0 NOT NULL,
cache_read_cost double precision DEFAULT 0 NOT NULL,
cache_creation_ephemeral_5m_tokens bigint DEFAULT 0 NOT NULL,
cache_creation_ephemeral_1h_tokens bigint DEFAULT 0 NOT NULL,
settled_total_cost double precision DEFAULT 0 NOT NULL,
settled_total_requests bigint DEFAULT 0 NOT NULL,
settled_input_tokens bigint DEFAULT 0 NOT NULL,
settled_output_tokens bigint DEFAULT 0 NOT NULL,
settled_cache_creation_tokens bigint DEFAULT 0 NOT NULL,
settled_cache_read_tokens bigint DEFAULT 0 NOT NULL,
settled_first_finalized_at_unix_secs bigint,
settled_last_finalized_at_unix_secs bigint
updated_at bigint NOT NULL
);
ALTER TABLE ONLY public.stats_user_daily ADD CONSTRAINT stats_user_daily_pkey PRIMARY KEY (id);
ALTER TABLE ONLY public.stats_user_daily ADD CONSTRAINT uq_stats_user_daily UNIQUE (date, user_id);
CREATE TABLE IF NOT EXISTS public.stats_user_summary (
id character varying(64) NOT NULL,
user_id character varying(64) NOT NULL,
username character varying(255),
cutoff_date bigint NOT NULL,
all_time_requests bigint DEFAULT 0 NOT NULL,
all_time_success_requests bigint DEFAULT 0 NOT NULL,
all_time_error_requests bigint DEFAULT 0 NOT NULL,
all_time_input_tokens bigint DEFAULT 0 NOT NULL,
all_time_output_tokens bigint DEFAULT 0 NOT NULL,
all_time_cache_creation_tokens bigint DEFAULT 0 NOT NULL,
all_time_cache_read_tokens bigint DEFAULT 0 NOT NULL,
all_time_cost double precision DEFAULT 0 NOT NULL,
all_time_actual_cost double precision DEFAULT 0 NOT NULL,
active_days bigint DEFAULT 0 NOT NULL,
first_active_date bigint,
last_active_date bigint,
created_at bigint DEFAULT 0 NOT NULL,
updated_at bigint DEFAULT 0 NOT NULL
);
ALTER TABLE ONLY public.stats_user_summary ADD CONSTRAINT stats_user_summary_pkey PRIMARY KEY (id);
ALTER TABLE ONLY public.stats_user_summary ADD CONSTRAINT uq_stats_user_summary_user_id UNIQUE (user_id);
CREATE INDEX IF NOT EXISTS idx_stats_user_summary_cutoff_date ON public.stats_user_summary USING btree (cutoff_date);
CREATE TABLE IF NOT EXISTS public.stats_user_daily_model (
id character varying(64) NOT NULL,
user_id character varying(64) NOT NULL,
username character varying(255),
date bigint NOT NULL,
model character varying(255) NOT NULL,
total_requests bigint DEFAULT 0 NOT NULL,
success_requests bigint DEFAULT 0 NOT NULL,
input_tokens bigint DEFAULT 0 NOT NULL,
effective_input_tokens bigint DEFAULT 0 NOT NULL,
output_tokens bigint DEFAULT 0 NOT NULL,
total_tokens bigint DEFAULT 0 NOT NULL,
total_input_context bigint DEFAULT 0 NOT NULL,
cache_creation_tokens bigint DEFAULT 0 NOT NULL,
cache_creation_ephemeral_5m_tokens bigint DEFAULT 0 NOT NULL,
cache_creation_ephemeral_1h_tokens bigint DEFAULT 0 NOT NULL,
cache_read_tokens bigint DEFAULT 0 NOT NULL,
total_cost double precision DEFAULT 0 NOT NULL,
actual_total_cost double precision DEFAULT 0 NOT NULL,
response_time_sum_ms double precision DEFAULT 0 NOT NULL,
response_time_samples bigint DEFAULT 0 NOT NULL,
successful_response_time_sum_ms double precision DEFAULT 0 NOT NULL,
successful_response_time_samples bigint DEFAULT 0 NOT NULL,
created_at bigint DEFAULT 0 NOT NULL,
updated_at bigint DEFAULT 0 NOT NULL
);
ALTER TABLE ONLY public.stats_user_daily_model ADD CONSTRAINT stats_user_daily_model_pkey PRIMARY KEY (id);
ALTER TABLE ONLY public.stats_user_daily_model ADD CONSTRAINT uq_stats_user_daily_model_user_id_date_model UNIQUE (user_id, date, model);
CREATE INDEX IF NOT EXISTS idx_stats_user_daily_model_date ON public.stats_user_daily_model USING btree (date);
CREATE INDEX IF NOT EXISTS idx_stats_user_daily_model_user_id ON public.stats_user_daily_model USING btree (user_id);
CREATE TABLE IF NOT EXISTS public.stats_user_daily_provider (
id character varying(64) NOT NULL,
user_id character varying(64) NOT NULL,
username character varying(255),
date bigint NOT NULL,
provider_name character varying(255) NOT NULL,
total_requests bigint DEFAULT 0 NOT NULL,
success_requests bigint DEFAULT 0 NOT NULL,
input_tokens bigint DEFAULT 0 NOT NULL,
effective_input_tokens bigint DEFAULT 0 NOT NULL,
output_tokens bigint DEFAULT 0 NOT NULL,
total_tokens bigint DEFAULT 0 NOT NULL,
total_input_context bigint DEFAULT 0 NOT NULL,
cache_creation_tokens bigint DEFAULT 0 NOT NULL,
cache_creation_ephemeral_5m_tokens bigint DEFAULT 0 NOT NULL,
cache_creation_ephemeral_1h_tokens bigint DEFAULT 0 NOT NULL,
cache_read_tokens bigint DEFAULT 0 NOT NULL,
total_cost double precision DEFAULT 0 NOT NULL,
actual_total_cost double precision DEFAULT 0 NOT NULL,
response_time_sum_ms double precision DEFAULT 0 NOT NULL,
response_time_samples bigint DEFAULT 0 NOT NULL,
successful_response_time_sum_ms double precision DEFAULT 0 NOT NULL,
successful_response_time_samples bigint DEFAULT 0 NOT NULL,
created_at bigint DEFAULT 0 NOT NULL,
updated_at bigint DEFAULT 0 NOT NULL
);
ALTER TABLE ONLY public.stats_user_daily_provider ADD CONSTRAINT stats_user_daily_provider_pkey PRIMARY KEY (id);
ALTER TABLE ONLY public.stats_user_daily_provider ADD CONSTRAINT uq_stats_user_daily_provider_user_id_date_provider_name UNIQUE (user_id, date, provider_name);
CREATE INDEX IF NOT EXISTS idx_stats_user_daily_provider_date ON public.stats_user_daily_provider USING btree (date);
CREATE INDEX IF NOT EXISTS idx_stats_user_daily_provider_user_id ON public.stats_user_daily_provider USING btree (user_id);
CREATE TABLE IF NOT EXISTS public.stats_user_daily_api_format (
id character varying(64) NOT NULL,
user_id character varying(64) NOT NULL,
username character varying(255),
date bigint NOT NULL,
api_format character varying(255) NOT NULL,
total_requests bigint DEFAULT 0 NOT NULL,
success_requests bigint DEFAULT 0 NOT NULL,
input_tokens bigint DEFAULT 0 NOT NULL,
effective_input_tokens bigint DEFAULT 0 NOT NULL,
output_tokens bigint DEFAULT 0 NOT NULL,
total_tokens bigint DEFAULT 0 NOT NULL,
total_input_context bigint DEFAULT 0 NOT NULL,
cache_creation_tokens bigint DEFAULT 0 NOT NULL,
cache_creation_ephemeral_5m_tokens bigint DEFAULT 0 NOT NULL,
cache_creation_ephemeral_1h_tokens bigint DEFAULT 0 NOT NULL,
cache_read_tokens bigint DEFAULT 0 NOT NULL,
total_cost double precision DEFAULT 0 NOT NULL,
actual_total_cost double precision DEFAULT 0 NOT NULL,
response_time_sum_ms double precision DEFAULT 0 NOT NULL,
response_time_samples bigint DEFAULT 0 NOT NULL,
successful_response_time_sum_ms double precision DEFAULT 0 NOT NULL,
successful_response_time_samples bigint DEFAULT 0 NOT NULL,
created_at bigint DEFAULT 0 NOT NULL,
updated_at bigint DEFAULT 0 NOT NULL
);
ALTER TABLE ONLY public.stats_user_daily_api_format ADD CONSTRAINT stats_user_daily_api_format_pkey PRIMARY KEY (id);
ALTER TABLE ONLY public.stats_user_daily_api_format ADD CONSTRAINT uq_stats_user_daily_api_format_user_id_date_api_format UNIQUE (user_id, date, api_format);
CREATE INDEX IF NOT EXISTS idx_stats_user_daily_api_format_date ON public.stats_user_daily_api_format USING btree (date);
CREATE INDEX IF NOT EXISTS idx_stats_user_daily_api_format_user_id ON public.stats_user_daily_api_format USING btree (user_id);
CREATE TABLE IF NOT EXISTS public.stats_daily_model_provider (
id character varying(64) NOT NULL,
date bigint NOT NULL,
model character varying(255) NOT NULL,
provider_name character varying(255) NOT NULL,
total_requests bigint DEFAULT 0 NOT NULL,
total_tokens bigint DEFAULT 0 NOT NULL,
total_cost double precision DEFAULT 0 NOT NULL,
response_time_sum_ms double precision DEFAULT 0 NOT NULL,
response_time_samples bigint DEFAULT 0 NOT NULL,
created_at bigint DEFAULT 0 NOT NULL,
updated_at bigint DEFAULT 0 NOT NULL
);
ALTER TABLE ONLY public.stats_daily_model_provider ADD CONSTRAINT stats_daily_model_provider_pkey PRIMARY KEY (id);
ALTER TABLE ONLY public.stats_daily_model_provider ADD CONSTRAINT uq_stats_daily_model_provider_date_model_provider_name UNIQUE (date, model, provider_name);
CREATE INDEX IF NOT EXISTS idx_stats_daily_model_provider_date ON public.stats_daily_model_provider USING btree (date);
CREATE INDEX IF NOT EXISTS idx_stats_daily_model_provider_date_model_provider ON public.stats_daily_model_provider USING btree (date, model, provider_name);
CREATE TABLE IF NOT EXISTS public.stats_user_daily_model_provider (
id character varying(64) NOT NULL,
user_id character varying(64) NOT NULL,
username character varying(255),
date bigint NOT NULL,
model character varying(255) NOT NULL,
provider_name character varying(255) NOT NULL,
total_requests bigint DEFAULT 0 NOT NULL,
total_tokens bigint DEFAULT 0 NOT NULL,
total_cost double precision DEFAULT 0 NOT NULL,
response_time_sum_ms double precision DEFAULT 0 NOT NULL,
response_time_samples bigint DEFAULT 0 NOT NULL,
created_at bigint DEFAULT 0 NOT NULL,
updated_at bigint DEFAULT 0 NOT NULL
);
ALTER TABLE ONLY public.stats_user_daily_model_provider ADD CONSTRAINT stats_user_daily_model_provider_pkey PRIMARY KEY (id);
ALTER TABLE ONLY public.stats_user_daily_model_provider ADD CONSTRAINT uq_stats_user_daily_model_provider_user_id_date_model_provider_name UNIQUE (user_id, date, model, provider_name);
CREATE INDEX IF NOT EXISTS idx_stats_user_daily_model_provider_date ON public.stats_user_daily_model_provider USING btree (date);
CREATE INDEX IF NOT EXISTS idx_stats_user_daily_model_provider_user_date ON public.stats_user_daily_model_provider USING btree (user_id, date);
CREATE TABLE IF NOT EXISTS public.stats_daily_cost_savings (
id character varying(64) NOT NULL,
date bigint NOT NULL,
cache_read_tokens bigint DEFAULT 0 NOT NULL,
cache_read_cost double precision DEFAULT 0 NOT NULL,
cache_creation_cost double precision DEFAULT 0 NOT NULL,
estimated_full_cost double precision DEFAULT 0 NOT NULL,
created_at bigint DEFAULT 0 NOT NULL,
updated_at bigint DEFAULT 0 NOT NULL
);
ALTER TABLE ONLY public.stats_daily_cost_savings ADD CONSTRAINT stats_daily_cost_savings_pkey PRIMARY KEY (id);
ALTER TABLE ONLY public.stats_daily_cost_savings ADD CONSTRAINT uq_stats_daily_cost_savings_date UNIQUE (date);
CREATE INDEX IF NOT EXISTS idx_stats_daily_cost_savings_date ON public.stats_daily_cost_savings USING btree (date);
CREATE TABLE IF NOT EXISTS public.stats_daily_cost_savings_provider (
id character varying(64) NOT NULL,
date bigint NOT NULL,
provider_name character varying(255) NOT NULL,
cache_read_tokens bigint DEFAULT 0 NOT NULL,
cache_read_cost double precision DEFAULT 0 NOT NULL,
cache_creation_cost double precision DEFAULT 0 NOT NULL,
estimated_full_cost double precision DEFAULT 0 NOT NULL,
created_at bigint DEFAULT 0 NOT NULL,
updated_at bigint DEFAULT 0 NOT NULL
);
ALTER TABLE ONLY public.stats_daily_cost_savings_provider ADD CONSTRAINT stats_daily_cost_savings_provider_pkey PRIMARY KEY (id);
ALTER TABLE ONLY public.stats_daily_cost_savings_provider ADD CONSTRAINT uq_stats_daily_cost_savings_provider_date_provider_name UNIQUE (date, provider_name);
CREATE INDEX IF NOT EXISTS idx_stats_daily_cost_savings_provider_date ON public.stats_daily_cost_savings_provider USING btree (date);
CREATE INDEX IF NOT EXISTS idx_stats_daily_cost_savings_provider_date_provider ON public.stats_daily_cost_savings_provider USING btree (date, provider_name);
CREATE TABLE IF NOT EXISTS public.stats_daily_cost_savings_model (
id character varying(64) NOT NULL,
date bigint NOT NULL,
model character varying(255) NOT NULL,
cache_read_tokens bigint DEFAULT 0 NOT NULL,
cache_read_cost double precision DEFAULT 0 NOT NULL,
cache_creation_cost double precision DEFAULT 0 NOT NULL,
estimated_full_cost double precision DEFAULT 0 NOT NULL,
created_at bigint DEFAULT 0 NOT NULL,
updated_at bigint DEFAULT 0 NOT NULL
);
ALTER TABLE ONLY public.stats_daily_cost_savings_model ADD CONSTRAINT stats_daily_cost_savings_model_pkey PRIMARY KEY (id);
ALTER TABLE ONLY public.stats_daily_cost_savings_model ADD CONSTRAINT uq_stats_daily_cost_savings_model_date_model UNIQUE (date, model);
CREATE INDEX IF NOT EXISTS idx_stats_daily_cost_savings_model_date ON public.stats_daily_cost_savings_model USING btree (date);
CREATE INDEX IF NOT EXISTS idx_stats_daily_cost_savings_model_date_model ON public.stats_daily_cost_savings_model USING btree (date, model);
CREATE TABLE IF NOT EXISTS public.stats_daily_cost_savings_model_provider (
id character varying(64) NOT NULL,
date bigint NOT NULL,
model character varying(255) NOT NULL,
provider_name character varying(255) NOT NULL,
cache_read_tokens bigint DEFAULT 0 NOT NULL,
cache_read_cost double precision DEFAULT 0 NOT NULL,
cache_creation_cost double precision DEFAULT 0 NOT NULL,
estimated_full_cost double precision DEFAULT 0 NOT NULL,
created_at bigint DEFAULT 0 NOT NULL,
updated_at bigint DEFAULT 0 NOT NULL
);
ALTER TABLE ONLY public.stats_daily_cost_savings_model_provider ADD CONSTRAINT stats_daily_cost_savings_model_provider_pkey PRIMARY KEY (id);
ALTER TABLE ONLY public.stats_daily_cost_savings_model_provider ADD CONSTRAINT uq_stats_daily_cost_savings_model_provider_date_model_provider_name UNIQUE (date, model, provider_name);
CREATE INDEX IF NOT EXISTS idx_stats_daily_cost_savings_model_provider_date ON public.stats_daily_cost_savings_model_provider USING btree (date);
CREATE INDEX IF NOT EXISTS idx_stats_daily_cost_savings_model_provider_date_dims ON public.stats_daily_cost_savings_model_provider USING btree (date, model, provider_name);
CREATE TABLE IF NOT EXISTS public.stats_user_daily_cost_savings (
id character varying(64) NOT NULL,
user_id character varying(64) NOT NULL,
username character varying(255),
date bigint NOT NULL,
cache_read_tokens bigint DEFAULT 0 NOT NULL,
cache_read_cost double precision DEFAULT 0 NOT NULL,
cache_creation_cost double precision DEFAULT 0 NOT NULL,
estimated_full_cost double precision DEFAULT 0 NOT NULL,
created_at bigint DEFAULT 0 NOT NULL,
updated_at bigint DEFAULT 0 NOT NULL
);
ALTER TABLE ONLY public.stats_user_daily_cost_savings ADD CONSTRAINT stats_user_daily_cost_savings_pkey PRIMARY KEY (id);
ALTER TABLE ONLY public.stats_user_daily_cost_savings ADD CONSTRAINT uq_stats_user_daily_cost_savings_user_id_date UNIQUE (user_id, date);
CREATE INDEX IF NOT EXISTS idx_stats_user_daily_cost_savings_date ON public.stats_user_daily_cost_savings USING btree (date);
CREATE INDEX IF NOT EXISTS idx_stats_user_daily_cost_savings_user_date ON public.stats_user_daily_cost_savings USING btree (user_id, date);
CREATE TABLE IF NOT EXISTS public.stats_user_daily_cost_savings_provider (
id character varying(64) NOT NULL,
user_id character varying(64) NOT NULL,
username character varying(255),
date bigint NOT NULL,
provider_name character varying(255) NOT NULL,
cache_read_tokens bigint DEFAULT 0 NOT NULL,
cache_read_cost double precision DEFAULT 0 NOT NULL,
cache_creation_cost double precision DEFAULT 0 NOT NULL,
estimated_full_cost double precision DEFAULT 0 NOT NULL,
created_at bigint DEFAULT 0 NOT NULL,
updated_at bigint DEFAULT 0 NOT NULL
);
ALTER TABLE ONLY public.stats_user_daily_cost_savings_provider ADD CONSTRAINT stats_user_daily_cost_savings_provider_pkey PRIMARY KEY (id);
ALTER TABLE ONLY public.stats_user_daily_cost_savings_provider ADD CONSTRAINT uq_stats_user_daily_cost_savings_provider_user_id_date_provider_name UNIQUE (user_id, date, provider_name);
CREATE INDEX IF NOT EXISTS idx_stats_user_daily_cost_savings_provider_date ON public.stats_user_daily_cost_savings_provider USING btree (date);
CREATE INDEX IF NOT EXISTS idx_stats_user_daily_cost_savings_provider_user_date ON public.stats_user_daily_cost_savings_provider USING btree (user_id, date);
CREATE TABLE IF NOT EXISTS public.stats_user_daily_cost_savings_model (
id character varying(64) NOT NULL,
user_id character varying(64) NOT NULL,
username character varying(255),
date bigint NOT NULL,
model character varying(255) NOT NULL,
cache_read_tokens bigint DEFAULT 0 NOT NULL,
cache_read_cost double precision DEFAULT 0 NOT NULL,
cache_creation_cost double precision DEFAULT 0 NOT NULL,
estimated_full_cost double precision DEFAULT 0 NOT NULL,
created_at bigint DEFAULT 0 NOT NULL,
updated_at bigint DEFAULT 0 NOT NULL
);
ALTER TABLE ONLY public.stats_user_daily_cost_savings_model ADD CONSTRAINT stats_user_daily_cost_savings_model_pkey PRIMARY KEY (id);
ALTER TABLE ONLY public.stats_user_daily_cost_savings_model ADD CONSTRAINT uq_stats_user_daily_cost_savings_model_user_id_date_model UNIQUE (user_id, date, model);
CREATE INDEX IF NOT EXISTS idx_stats_user_daily_cost_savings_model_date ON public.stats_user_daily_cost_savings_model USING btree (date);
CREATE INDEX IF NOT EXISTS idx_stats_user_daily_cost_savings_model_user_date ON public.stats_user_daily_cost_savings_model USING btree (user_id, date);
CREATE TABLE IF NOT EXISTS public.stats_user_daily_cost_savings_model_provider (
id character varying(64) NOT NULL,
user_id character varying(64) NOT NULL,
username character varying(255),
date bigint NOT NULL,
model character varying(255) NOT NULL,
provider_name character varying(255) NOT NULL,
cache_read_tokens bigint DEFAULT 0 NOT NULL,
cache_read_cost double precision DEFAULT 0 NOT NULL,
cache_creation_cost double precision DEFAULT 0 NOT NULL,
estimated_full_cost double precision DEFAULT 0 NOT NULL,
created_at bigint DEFAULT 0 NOT NULL,
updated_at bigint DEFAULT 0 NOT NULL
);
ALTER TABLE ONLY public.stats_user_daily_cost_savings_model_provider ADD CONSTRAINT stats_user_daily_cost_savings_model_provider_pkey PRIMARY KEY (id);
ALTER TABLE ONLY public.stats_user_daily_cost_savings_model_provider ADD CONSTRAINT uq_stats_user_daily_cost_savings_model_provider_user_id_date_model_provider_name UNIQUE (user_id, date, model, provider_name);
CREATE INDEX IF NOT EXISTS idx_stats_user_daily_cost_savings_model_provider_date ON public.stats_user_daily_cost_savings_model_provider USING btree (date);
CREATE INDEX IF NOT EXISTS idx_stats_user_daily_cost_savings_model_provider_user_date ON public.stats_user_daily_cost_savings_model_provider USING btree (user_id, date);

View File

@@ -110,60 +110,6 @@ CREATE INDEX IF NOT EXISTS usage_request_id_idx ON "usage" (request_id);
CREATE INDEX IF NOT EXISTS usage_user_id_idx ON "usage" (user_id);
CREATE INDEX IF NOT EXISTS usage_wallet_id_idx ON "usage" (wallet_id);
CREATE TABLE IF NOT EXISTS usage_body_blobs (
body_ref TEXT PRIMARY KEY NOT NULL,
request_id TEXT NOT NULL,
body_field TEXT NOT NULL,
payload_gzip BLOB NOT NULL,
created_at TEXT NOT NULL DEFAULT CURRENT_TIMESTAMP,
updated_at TEXT NOT NULL DEFAULT CURRENT_TIMESTAMP,
UNIQUE (request_id, body_field),
CONSTRAINT usage_body_blobs_request_id_fkey FOREIGN KEY (request_id) REFERENCES usage (request_id) ON DELETE CASCADE
);
CREATE INDEX IF NOT EXISTS usage_body_blobs_request_id_idx ON usage_body_blobs (request_id);
CREATE TABLE IF NOT EXISTS usage_http_audits (
request_id TEXT PRIMARY KEY NOT NULL,
request_headers TEXT,
provider_request_headers TEXT,
response_headers TEXT,
client_response_headers TEXT,
request_body_ref TEXT,
provider_request_body_ref TEXT,
response_body_ref TEXT,
client_response_body_ref TEXT,
request_body_state TEXT,
provider_request_body_state TEXT,
response_body_state TEXT,
client_response_body_state TEXT,
body_capture_mode TEXT NOT NULL DEFAULT 'none',
created_at TEXT NOT NULL DEFAULT CURRENT_TIMESTAMP,
updated_at TEXT NOT NULL DEFAULT CURRENT_TIMESTAMP,
CONSTRAINT usage_http_audits_request_id_fkey FOREIGN KEY (request_id) REFERENCES usage (request_id) ON DELETE CASCADE
);
CREATE INDEX IF NOT EXISTS usage_http_audits_updated_at_idx ON usage_http_audits (updated_at);
CREATE TABLE IF NOT EXISTS usage_routing_snapshots (
request_id TEXT PRIMARY KEY NOT NULL,
candidate_id TEXT,
candidate_index INTEGER,
key_name TEXT,
planner_kind TEXT,
route_family TEXT,
route_kind TEXT,
execution_path TEXT,
local_execution_runtime_miss_reason TEXT,
selected_provider_id TEXT,
selected_endpoint_id TEXT,
selected_provider_api_key_id TEXT,
has_format_conversion INTEGER,
created_at INTEGER NOT NULL DEFAULT 0,
updated_at INTEGER NOT NULL DEFAULT 0,
CONSTRAINT usage_routing_snapshots_request_id_fkey FOREIGN KEY (request_id) REFERENCES usage (request_id) ON DELETE CASCADE
);
CREATE INDEX IF NOT EXISTS ix_usage_routing_snapshots_route_family_kind ON usage_routing_snapshots (route_family, route_kind);
CREATE INDEX IF NOT EXISTS ix_usage_routing_snapshots_candidate_id ON usage_routing_snapshots (candidate_id);
CREATE TABLE IF NOT EXISTS usage_settlement_snapshots (
request_id TEXT PRIMARY KEY NOT NULL,
billing_status TEXT NOT NULL,

View File

@@ -18,26 +18,6 @@ CREATE TABLE IF NOT EXISTS stats_hourly (
aggregated_at INTEGER,
created_at INTEGER NOT NULL,
updated_at INTEGER NOT NULL,
response_time_sum_ms REAL NOT NULL DEFAULT 0,
response_time_samples INTEGER NOT NULL DEFAULT 0,
cache_hit_total_requests INTEGER NOT NULL DEFAULT 0,
cache_hit_requests INTEGER NOT NULL DEFAULT 0,
completed_total_requests INTEGER NOT NULL DEFAULT 0,
completed_cache_hit_requests INTEGER NOT NULL DEFAULT 0,
completed_input_tokens INTEGER NOT NULL DEFAULT 0,
completed_cache_creation_tokens INTEGER NOT NULL DEFAULT 0,
completed_cache_read_tokens INTEGER NOT NULL DEFAULT 0,
completed_total_input_context INTEGER NOT NULL DEFAULT 0,
completed_cache_creation_cost REAL NOT NULL DEFAULT 0,
completed_cache_read_cost REAL NOT NULL DEFAULT 0,
settled_total_cost REAL NOT NULL DEFAULT 0,
settled_total_requests INTEGER NOT NULL DEFAULT 0,
settled_input_tokens INTEGER NOT NULL DEFAULT 0,
settled_output_tokens INTEGER NOT NULL DEFAULT 0,
settled_cache_creation_tokens INTEGER NOT NULL DEFAULT 0,
settled_cache_read_tokens INTEGER NOT NULL DEFAULT 0,
settled_first_finalized_at_unix_secs INTEGER,
settled_last_finalized_at_unix_secs INTEGER,
UNIQUE (hour_utc)
);
@@ -73,19 +53,6 @@ CREATE TABLE IF NOT EXISTS stats_hourly_user (
total_cost REAL NOT NULL DEFAULT 0,
created_at INTEGER NOT NULL,
updated_at INTEGER NOT NULL,
cache_creation_tokens INTEGER NOT NULL DEFAULT 0,
cache_read_tokens INTEGER NOT NULL DEFAULT 0,
actual_total_cost REAL NOT NULL DEFAULT 0,
response_time_sum_ms REAL NOT NULL DEFAULT 0,
response_time_samples INTEGER NOT NULL DEFAULT 0,
settled_total_cost REAL NOT NULL DEFAULT 0,
settled_total_requests INTEGER NOT NULL DEFAULT 0,
settled_input_tokens INTEGER NOT NULL DEFAULT 0,
settled_output_tokens INTEGER NOT NULL DEFAULT 0,
settled_cache_creation_tokens INTEGER NOT NULL DEFAULT 0,
settled_cache_read_tokens INTEGER NOT NULL DEFAULT 0,
settled_first_finalized_at_unix_secs INTEGER,
settled_last_finalized_at_unix_secs INTEGER,
UNIQUE (hour_utc, user_id)
);
@@ -100,8 +67,6 @@ CREATE TABLE IF NOT EXISTS stats_hourly_user_model (
total_cost REAL NOT NULL DEFAULT 0,
created_at INTEGER NOT NULL,
updated_at INTEGER NOT NULL,
response_time_sum_ms REAL NOT NULL DEFAULT 0,
response_time_samples INTEGER NOT NULL DEFAULT 0,
UNIQUE (hour_utc, user_id, model)
);
@@ -128,8 +93,6 @@ CREATE TABLE IF NOT EXISTS stats_hourly_model (
avg_response_time_ms REAL NOT NULL DEFAULT 0,
created_at INTEGER NOT NULL,
updated_at INTEGER NOT NULL,
response_time_sum_ms REAL NOT NULL DEFAULT 0,
response_time_samples INTEGER NOT NULL DEFAULT 0,
UNIQUE (hour_utc, model)
);
@@ -176,30 +139,6 @@ CREATE TABLE IF NOT EXISTS stats_daily (
p50_first_byte_time_ms INTEGER,
p90_first_byte_time_ms INTEGER,
p99_first_byte_time_ms INTEGER,
effective_input_tokens INTEGER NOT NULL DEFAULT 0,
total_input_context INTEGER NOT NULL DEFAULT 0,
response_time_sum_ms REAL NOT NULL DEFAULT 0,
response_time_samples INTEGER NOT NULL DEFAULT 0,
cache_creation_ephemeral_5m_tokens INTEGER NOT NULL DEFAULT 0,
cache_creation_ephemeral_1h_tokens INTEGER NOT NULL DEFAULT 0,
cache_hit_total_requests INTEGER NOT NULL DEFAULT 0,
cache_hit_requests INTEGER NOT NULL DEFAULT 0,
completed_total_requests INTEGER NOT NULL DEFAULT 0,
completed_cache_hit_requests INTEGER NOT NULL DEFAULT 0,
completed_input_tokens INTEGER NOT NULL DEFAULT 0,
completed_cache_creation_tokens INTEGER NOT NULL DEFAULT 0,
completed_cache_read_tokens INTEGER NOT NULL DEFAULT 0,
completed_total_input_context INTEGER NOT NULL DEFAULT 0,
completed_cache_creation_cost REAL NOT NULL DEFAULT 0,
completed_cache_read_cost REAL NOT NULL DEFAULT 0,
settled_total_cost REAL NOT NULL DEFAULT 0,
settled_total_requests INTEGER NOT NULL DEFAULT 0,
settled_input_tokens INTEGER NOT NULL DEFAULT 0,
settled_output_tokens INTEGER NOT NULL DEFAULT 0,
settled_cache_creation_tokens INTEGER NOT NULL DEFAULT 0,
settled_cache_read_tokens INTEGER NOT NULL DEFAULT 0,
settled_first_finalized_at_unix_secs INTEGER,
settled_last_finalized_at_unix_secs INTEGER,
UNIQUE (date)
);
@@ -216,10 +155,6 @@ CREATE TABLE IF NOT EXISTS stats_daily_model (
avg_response_time_ms REAL NOT NULL DEFAULT 0,
created_at INTEGER NOT NULL,
updated_at INTEGER NOT NULL,
cache_creation_ephemeral_5m_tokens INTEGER NOT NULL DEFAULT 0,
cache_creation_ephemeral_1h_tokens INTEGER NOT NULL DEFAULT 0,
response_time_sum_ms REAL NOT NULL DEFAULT 0,
response_time_samples INTEGER NOT NULL DEFAULT 0,
UNIQUE (date, model)
);
@@ -283,299 +218,6 @@ CREATE TABLE IF NOT EXISTS stats_user_daily (
username TEXT,
created_at INTEGER NOT NULL,
updated_at INTEGER NOT NULL,
actual_total_cost REAL NOT NULL DEFAULT 0,
response_time_sum_ms REAL NOT NULL DEFAULT 0,
response_time_samples INTEGER NOT NULL DEFAULT 0,
effective_input_tokens INTEGER NOT NULL DEFAULT 0,
total_input_context INTEGER NOT NULL DEFAULT 0,
cache_creation_cost REAL NOT NULL DEFAULT 0,
cache_read_cost REAL NOT NULL DEFAULT 0,
cache_creation_ephemeral_5m_tokens INTEGER NOT NULL DEFAULT 0,
cache_creation_ephemeral_1h_tokens INTEGER NOT NULL DEFAULT 0,
settled_total_cost REAL NOT NULL DEFAULT 0,
settled_total_requests INTEGER NOT NULL DEFAULT 0,
settled_input_tokens INTEGER NOT NULL DEFAULT 0,
settled_output_tokens INTEGER NOT NULL DEFAULT 0,
settled_cache_creation_tokens INTEGER NOT NULL DEFAULT 0,
settled_cache_read_tokens INTEGER NOT NULL DEFAULT 0,
settled_first_finalized_at_unix_secs INTEGER,
settled_last_finalized_at_unix_secs INTEGER,
UNIQUE (date, user_id)
);
CREATE TABLE IF NOT EXISTS stats_user_summary (
id TEXT PRIMARY KEY NOT NULL,
user_id TEXT NOT NULL,
username TEXT,
cutoff_date INTEGER NOT NULL,
all_time_requests INTEGER NOT NULL DEFAULT 0,
all_time_success_requests INTEGER NOT NULL DEFAULT 0,
all_time_error_requests INTEGER NOT NULL DEFAULT 0,
all_time_input_tokens INTEGER NOT NULL DEFAULT 0,
all_time_output_tokens INTEGER NOT NULL DEFAULT 0,
all_time_cache_creation_tokens INTEGER NOT NULL DEFAULT 0,
all_time_cache_read_tokens INTEGER NOT NULL DEFAULT 0,
all_time_cost REAL NOT NULL DEFAULT 0,
all_time_actual_cost REAL NOT NULL DEFAULT 0,
active_days INTEGER NOT NULL DEFAULT 0,
first_active_date INTEGER,
last_active_date INTEGER,
created_at INTEGER NOT NULL DEFAULT 0,
updated_at INTEGER NOT NULL DEFAULT 0,
UNIQUE (user_id)
);
CREATE INDEX IF NOT EXISTS idx_stats_user_summary_cutoff_date ON stats_user_summary (cutoff_date);
CREATE TABLE IF NOT EXISTS stats_user_daily_model (
id TEXT PRIMARY KEY NOT NULL,
user_id TEXT NOT NULL,
username TEXT,
date INTEGER NOT NULL,
model TEXT NOT NULL,
total_requests INTEGER NOT NULL DEFAULT 0,
success_requests INTEGER NOT NULL DEFAULT 0,
input_tokens INTEGER NOT NULL DEFAULT 0,
effective_input_tokens INTEGER NOT NULL DEFAULT 0,
output_tokens INTEGER NOT NULL DEFAULT 0,
total_tokens INTEGER NOT NULL DEFAULT 0,
total_input_context INTEGER NOT NULL DEFAULT 0,
cache_creation_tokens INTEGER NOT NULL DEFAULT 0,
cache_creation_ephemeral_5m_tokens INTEGER NOT NULL DEFAULT 0,
cache_creation_ephemeral_1h_tokens INTEGER NOT NULL DEFAULT 0,
cache_read_tokens INTEGER NOT NULL DEFAULT 0,
total_cost REAL NOT NULL DEFAULT 0,
actual_total_cost REAL NOT NULL DEFAULT 0,
response_time_sum_ms REAL NOT NULL DEFAULT 0,
response_time_samples INTEGER NOT NULL DEFAULT 0,
successful_response_time_sum_ms REAL NOT NULL DEFAULT 0,
successful_response_time_samples INTEGER NOT NULL DEFAULT 0,
created_at INTEGER NOT NULL DEFAULT 0,
updated_at INTEGER NOT NULL DEFAULT 0,
UNIQUE (user_id, date, model)
);
CREATE INDEX IF NOT EXISTS idx_stats_user_daily_model_date ON stats_user_daily_model (date);
CREATE INDEX IF NOT EXISTS idx_stats_user_daily_model_user_id ON stats_user_daily_model (user_id);
CREATE TABLE IF NOT EXISTS stats_user_daily_provider (
id TEXT PRIMARY KEY NOT NULL,
user_id TEXT NOT NULL,
username TEXT,
date INTEGER NOT NULL,
provider_name TEXT NOT NULL,
total_requests INTEGER NOT NULL DEFAULT 0,
success_requests INTEGER NOT NULL DEFAULT 0,
input_tokens INTEGER NOT NULL DEFAULT 0,
effective_input_tokens INTEGER NOT NULL DEFAULT 0,
output_tokens INTEGER NOT NULL DEFAULT 0,
total_tokens INTEGER NOT NULL DEFAULT 0,
total_input_context INTEGER NOT NULL DEFAULT 0,
cache_creation_tokens INTEGER NOT NULL DEFAULT 0,
cache_creation_ephemeral_5m_tokens INTEGER NOT NULL DEFAULT 0,
cache_creation_ephemeral_1h_tokens INTEGER NOT NULL DEFAULT 0,
cache_read_tokens INTEGER NOT NULL DEFAULT 0,
total_cost REAL NOT NULL DEFAULT 0,
actual_total_cost REAL NOT NULL DEFAULT 0,
response_time_sum_ms REAL NOT NULL DEFAULT 0,
response_time_samples INTEGER NOT NULL DEFAULT 0,
successful_response_time_sum_ms REAL NOT NULL DEFAULT 0,
successful_response_time_samples INTEGER NOT NULL DEFAULT 0,
created_at INTEGER NOT NULL DEFAULT 0,
updated_at INTEGER NOT NULL DEFAULT 0,
UNIQUE (user_id, date, provider_name)
);
CREATE INDEX IF NOT EXISTS idx_stats_user_daily_provider_date ON stats_user_daily_provider (date);
CREATE INDEX IF NOT EXISTS idx_stats_user_daily_provider_user_id ON stats_user_daily_provider (user_id);
CREATE TABLE IF NOT EXISTS stats_user_daily_api_format (
id TEXT PRIMARY KEY NOT NULL,
user_id TEXT NOT NULL,
username TEXT,
date INTEGER NOT NULL,
api_format TEXT NOT NULL,
total_requests INTEGER NOT NULL DEFAULT 0,
success_requests INTEGER NOT NULL DEFAULT 0,
input_tokens INTEGER NOT NULL DEFAULT 0,
effective_input_tokens INTEGER NOT NULL DEFAULT 0,
output_tokens INTEGER NOT NULL DEFAULT 0,
total_tokens INTEGER NOT NULL DEFAULT 0,
total_input_context INTEGER NOT NULL DEFAULT 0,
cache_creation_tokens INTEGER NOT NULL DEFAULT 0,
cache_creation_ephemeral_5m_tokens INTEGER NOT NULL DEFAULT 0,
cache_creation_ephemeral_1h_tokens INTEGER NOT NULL DEFAULT 0,
cache_read_tokens INTEGER NOT NULL DEFAULT 0,
total_cost REAL NOT NULL DEFAULT 0,
actual_total_cost REAL NOT NULL DEFAULT 0,
response_time_sum_ms REAL NOT NULL DEFAULT 0,
response_time_samples INTEGER NOT NULL DEFAULT 0,
successful_response_time_sum_ms REAL NOT NULL DEFAULT 0,
successful_response_time_samples INTEGER NOT NULL DEFAULT 0,
created_at INTEGER NOT NULL DEFAULT 0,
updated_at INTEGER NOT NULL DEFAULT 0,
UNIQUE (user_id, date, api_format)
);
CREATE INDEX IF NOT EXISTS idx_stats_user_daily_api_format_date ON stats_user_daily_api_format (date);
CREATE INDEX IF NOT EXISTS idx_stats_user_daily_api_format_user_id ON stats_user_daily_api_format (user_id);
CREATE TABLE IF NOT EXISTS stats_daily_model_provider (
id TEXT PRIMARY KEY NOT NULL,
date INTEGER NOT NULL,
model TEXT NOT NULL,
provider_name TEXT NOT NULL,
total_requests INTEGER NOT NULL DEFAULT 0,
total_tokens INTEGER NOT NULL DEFAULT 0,
total_cost REAL NOT NULL DEFAULT 0,
response_time_sum_ms REAL NOT NULL DEFAULT 0,
response_time_samples INTEGER NOT NULL DEFAULT 0,
created_at INTEGER NOT NULL DEFAULT 0,
updated_at INTEGER NOT NULL DEFAULT 0,
UNIQUE (date, model, provider_name)
);
CREATE INDEX IF NOT EXISTS idx_stats_daily_model_provider_date ON stats_daily_model_provider (date);
CREATE INDEX IF NOT EXISTS idx_stats_daily_model_provider_date_model_provider ON stats_daily_model_provider (date, model, provider_name);
CREATE TABLE IF NOT EXISTS stats_user_daily_model_provider (
id TEXT PRIMARY KEY NOT NULL,
user_id TEXT NOT NULL,
username TEXT,
date INTEGER NOT NULL,
model TEXT NOT NULL,
provider_name TEXT NOT NULL,
total_requests INTEGER NOT NULL DEFAULT 0,
total_tokens INTEGER NOT NULL DEFAULT 0,
total_cost REAL NOT NULL DEFAULT 0,
response_time_sum_ms REAL NOT NULL DEFAULT 0,
response_time_samples INTEGER NOT NULL DEFAULT 0,
created_at INTEGER NOT NULL DEFAULT 0,
updated_at INTEGER NOT NULL DEFAULT 0,
UNIQUE (user_id, date, model, provider_name)
);
CREATE INDEX IF NOT EXISTS idx_stats_user_daily_model_provider_date ON stats_user_daily_model_provider (date);
CREATE INDEX IF NOT EXISTS idx_stats_user_daily_model_provider_user_date ON stats_user_daily_model_provider (user_id, date);
CREATE TABLE IF NOT EXISTS stats_daily_cost_savings (
id TEXT PRIMARY KEY NOT NULL,
date INTEGER NOT NULL,
cache_read_tokens INTEGER NOT NULL DEFAULT 0,
cache_read_cost REAL NOT NULL DEFAULT 0,
cache_creation_cost REAL NOT NULL DEFAULT 0,
estimated_full_cost REAL NOT NULL DEFAULT 0,
created_at INTEGER NOT NULL DEFAULT 0,
updated_at INTEGER NOT NULL DEFAULT 0,
UNIQUE (date)
);
CREATE INDEX IF NOT EXISTS idx_stats_daily_cost_savings_date ON stats_daily_cost_savings (date);
CREATE TABLE IF NOT EXISTS stats_daily_cost_savings_provider (
id TEXT PRIMARY KEY NOT NULL,
date INTEGER NOT NULL,
provider_name TEXT NOT NULL,
cache_read_tokens INTEGER NOT NULL DEFAULT 0,
cache_read_cost REAL NOT NULL DEFAULT 0,
cache_creation_cost REAL NOT NULL DEFAULT 0,
estimated_full_cost REAL NOT NULL DEFAULT 0,
created_at INTEGER NOT NULL DEFAULT 0,
updated_at INTEGER NOT NULL DEFAULT 0,
UNIQUE (date, provider_name)
);
CREATE INDEX IF NOT EXISTS idx_stats_daily_cost_savings_provider_date ON stats_daily_cost_savings_provider (date);
CREATE INDEX IF NOT EXISTS idx_stats_daily_cost_savings_provider_date_provider ON stats_daily_cost_savings_provider (date, provider_name);
CREATE TABLE IF NOT EXISTS stats_daily_cost_savings_model (
id TEXT PRIMARY KEY NOT NULL,
date INTEGER NOT NULL,
model TEXT NOT NULL,
cache_read_tokens INTEGER NOT NULL DEFAULT 0,
cache_read_cost REAL NOT NULL DEFAULT 0,
cache_creation_cost REAL NOT NULL DEFAULT 0,
estimated_full_cost REAL NOT NULL DEFAULT 0,
created_at INTEGER NOT NULL DEFAULT 0,
updated_at INTEGER NOT NULL DEFAULT 0,
UNIQUE (date, model)
);
CREATE INDEX IF NOT EXISTS idx_stats_daily_cost_savings_model_date ON stats_daily_cost_savings_model (date);
CREATE INDEX IF NOT EXISTS idx_stats_daily_cost_savings_model_date_model ON stats_daily_cost_savings_model (date, model);
CREATE TABLE IF NOT EXISTS stats_daily_cost_savings_model_provider (
id TEXT PRIMARY KEY NOT NULL,
date INTEGER NOT NULL,
model TEXT NOT NULL,
provider_name TEXT NOT NULL,
cache_read_tokens INTEGER NOT NULL DEFAULT 0,
cache_read_cost REAL NOT NULL DEFAULT 0,
cache_creation_cost REAL NOT NULL DEFAULT 0,
estimated_full_cost REAL NOT NULL DEFAULT 0,
created_at INTEGER NOT NULL DEFAULT 0,
updated_at INTEGER NOT NULL DEFAULT 0,
UNIQUE (date, model, provider_name)
);
CREATE INDEX IF NOT EXISTS idx_stats_daily_cost_savings_model_provider_date ON stats_daily_cost_savings_model_provider (date);
CREATE INDEX IF NOT EXISTS idx_stats_daily_cost_savings_model_provider_date_dims ON stats_daily_cost_savings_model_provider (date, model, provider_name);
CREATE TABLE IF NOT EXISTS stats_user_daily_cost_savings (
id TEXT PRIMARY KEY NOT NULL,
user_id TEXT NOT NULL,
username TEXT,
date INTEGER NOT NULL,
cache_read_tokens INTEGER NOT NULL DEFAULT 0,
cache_read_cost REAL NOT NULL DEFAULT 0,
cache_creation_cost REAL NOT NULL DEFAULT 0,
estimated_full_cost REAL NOT NULL DEFAULT 0,
created_at INTEGER NOT NULL DEFAULT 0,
updated_at INTEGER NOT NULL DEFAULT 0,
UNIQUE (user_id, date)
);
CREATE INDEX IF NOT EXISTS idx_stats_user_daily_cost_savings_date ON stats_user_daily_cost_savings (date);
CREATE INDEX IF NOT EXISTS idx_stats_user_daily_cost_savings_user_date ON stats_user_daily_cost_savings (user_id, date);
CREATE TABLE IF NOT EXISTS stats_user_daily_cost_savings_provider (
id TEXT PRIMARY KEY NOT NULL,
user_id TEXT NOT NULL,
username TEXT,
date INTEGER NOT NULL,
provider_name TEXT NOT NULL,
cache_read_tokens INTEGER NOT NULL DEFAULT 0,
cache_read_cost REAL NOT NULL DEFAULT 0,
cache_creation_cost REAL NOT NULL DEFAULT 0,
estimated_full_cost REAL NOT NULL DEFAULT 0,
created_at INTEGER NOT NULL DEFAULT 0,
updated_at INTEGER NOT NULL DEFAULT 0,
UNIQUE (user_id, date, provider_name)
);
CREATE INDEX IF NOT EXISTS idx_stats_user_daily_cost_savings_provider_date ON stats_user_daily_cost_savings_provider (date);
CREATE INDEX IF NOT EXISTS idx_stats_user_daily_cost_savings_provider_user_date ON stats_user_daily_cost_savings_provider (user_id, date);
CREATE TABLE IF NOT EXISTS stats_user_daily_cost_savings_model (
id TEXT PRIMARY KEY NOT NULL,
user_id TEXT NOT NULL,
username TEXT,
date INTEGER NOT NULL,
model TEXT NOT NULL,
cache_read_tokens INTEGER NOT NULL DEFAULT 0,
cache_read_cost REAL NOT NULL DEFAULT 0,
cache_creation_cost REAL NOT NULL DEFAULT 0,
estimated_full_cost REAL NOT NULL DEFAULT 0,
created_at INTEGER NOT NULL DEFAULT 0,
updated_at INTEGER NOT NULL DEFAULT 0,
UNIQUE (user_id, date, model)
);
CREATE INDEX IF NOT EXISTS idx_stats_user_daily_cost_savings_model_date ON stats_user_daily_cost_savings_model (date);
CREATE INDEX IF NOT EXISTS idx_stats_user_daily_cost_savings_model_user_date ON stats_user_daily_cost_savings_model (user_id, date);
CREATE TABLE IF NOT EXISTS stats_user_daily_cost_savings_model_provider (
id TEXT PRIMARY KEY NOT NULL,
user_id TEXT NOT NULL,
username TEXT,
date INTEGER NOT NULL,
model TEXT NOT NULL,
provider_name TEXT NOT NULL,
cache_read_tokens INTEGER NOT NULL DEFAULT 0,
cache_read_cost REAL NOT NULL DEFAULT 0,
cache_creation_cost REAL NOT NULL DEFAULT 0,
estimated_full_cost REAL NOT NULL DEFAULT 0,
created_at INTEGER NOT NULL DEFAULT 0,
updated_at INTEGER NOT NULL DEFAULT 0,
UNIQUE (user_id, date, model, provider_name)
);
CREATE INDEX IF NOT EXISTS idx_stats_user_daily_cost_savings_model_provider_date ON stats_user_daily_cost_savings_model_provider (date);
CREATE INDEX IF NOT EXISTS idx_stats_user_daily_cost_savings_model_provider_user_date ON stats_user_daily_cost_savings_model_provider (user_id, date);

View File

@@ -554,269 +554,6 @@ columns = ["user_id"]
name = "usage_wallet_id_idx"
columns = ["wallet_id"]
[table.usage_body_blobs]
domain = "usage"
order = 12
primary_key = ["body_ref"]
[[table.usage_body_blobs.columns]]
name = "body_ref"
type = "text"
length = 160
[[table.usage_body_blobs.columns]]
name = "request_id"
type = "text"
length = 128
[[table.usage_body_blobs.columns]]
name = "body_field"
type = "text"
length = 64
[[table.usage_body_blobs.columns]]
name = "payload_gzip"
type = "bytes"
[[table.usage_body_blobs.columns]]
name = "created_at"
type = "timestamp"
default = { raw = "CURRENT_TIMESTAMP" }
driver = { mysql = { type = "TIMESTAMP" }, sqlite = { type = "TEXT" } }
[[table.usage_body_blobs.columns]]
name = "updated_at"
type = "timestamp"
default = { raw = "CURRENT_TIMESTAMP" }
driver = { mysql = { type = "TIMESTAMP" }, sqlite = { type = "TEXT" } }
[[table.usage_body_blobs.uniques]]
name = "usage_body_blobs_request_id_field_key"
columns = ["request_id", "body_field"]
[[table.usage_body_blobs.indexes]]
name = "usage_body_blobs_request_id_idx"
columns = ["request_id"]
[[table.usage_body_blobs.foreign_keys]]
name = "usage_body_blobs_request_id_fkey"
columns = ["request_id"]
references_table = "usage"
references_columns = ["request_id"]
on_delete = "cascade"
[table.usage_http_audits]
domain = "usage"
order = 14
primary_key = ["request_id"]
[[table.usage_http_audits.columns]]
name = "request_id"
type = "text"
length = 128
[[table.usage_http_audits.columns]]
name = "request_headers"
type = "json"
nullable = true
[[table.usage_http_audits.columns]]
name = "provider_request_headers"
type = "json"
nullable = true
[[table.usage_http_audits.columns]]
name = "response_headers"
type = "json"
nullable = true
[[table.usage_http_audits.columns]]
name = "client_response_headers"
type = "json"
nullable = true
[[table.usage_http_audits.columns]]
name = "request_body_ref"
type = "text"
length = 160
nullable = true
[[table.usage_http_audits.columns]]
name = "provider_request_body_ref"
type = "text"
length = 160
nullable = true
[[table.usage_http_audits.columns]]
name = "response_body_ref"
type = "text"
length = 160
nullable = true
[[table.usage_http_audits.columns]]
name = "client_response_body_ref"
type = "text"
length = 160
nullable = true
[[table.usage_http_audits.columns]]
name = "request_body_state"
type = "text"
length = 32
nullable = true
[[table.usage_http_audits.columns]]
name = "provider_request_body_state"
type = "text"
length = 32
nullable = true
[[table.usage_http_audits.columns]]
name = "response_body_state"
type = "text"
length = 32
nullable = true
[[table.usage_http_audits.columns]]
name = "client_response_body_state"
type = "text"
length = 32
nullable = true
[[table.usage_http_audits.columns]]
name = "body_capture_mode"
type = "text"
length = 32
default = "none"
[[table.usage_http_audits.columns]]
name = "created_at"
type = "timestamp"
default = { raw = "CURRENT_TIMESTAMP" }
driver = { mysql = { type = "TIMESTAMP" }, sqlite = { type = "TEXT" } }
[[table.usage_http_audits.columns]]
name = "updated_at"
type = "timestamp"
default = { raw = "CURRENT_TIMESTAMP" }
driver = { mysql = { type = "TIMESTAMP" }, sqlite = { type = "TEXT" } }
[[table.usage_http_audits.indexes]]
name = "usage_http_audits_updated_at_idx"
columns = ["updated_at"]
[[table.usage_http_audits.foreign_keys]]
name = "usage_http_audits_request_id_fkey"
columns = ["request_id"]
references_table = "usage"
references_columns = ["request_id"]
on_delete = "cascade"
[table.usage_routing_snapshots]
domain = "usage"
order = 16
primary_key = ["request_id"]
[[table.usage_routing_snapshots.columns]]
name = "request_id"
type = "text"
length = 128
[[table.usage_routing_snapshots.columns]]
name = "candidate_id"
type = "text"
length = 160
nullable = true
[[table.usage_routing_snapshots.columns]]
name = "candidate_index"
type = "int64"
nullable = true
[[table.usage_routing_snapshots.columns]]
name = "key_name"
type = "text"
length = 255
nullable = true
[[table.usage_routing_snapshots.columns]]
name = "planner_kind"
type = "text"
length = 120
nullable = true
[[table.usage_routing_snapshots.columns]]
name = "route_family"
type = "text"
length = 80
nullable = true
[[table.usage_routing_snapshots.columns]]
name = "route_kind"
type = "text"
length = 80
nullable = true
[[table.usage_routing_snapshots.columns]]
name = "execution_path"
type = "text"
length = 80
nullable = true
[[table.usage_routing_snapshots.columns]]
name = "local_execution_runtime_miss_reason"
type = "text"
length = 120
nullable = true
[[table.usage_routing_snapshots.columns]]
name = "selected_provider_id"
type = "text_id"
length = 64
nullable = true
[[table.usage_routing_snapshots.columns]]
name = "selected_endpoint_id"
type = "text_id"
length = 64
nullable = true
[[table.usage_routing_snapshots.columns]]
name = "selected_provider_api_key_id"
type = "text_id"
length = 64
nullable = true
[[table.usage_routing_snapshots.columns]]
name = "has_format_conversion"
type = "bool"
nullable = true
[[table.usage_routing_snapshots.columns]]
name = "created_at"
type = "unix_seconds"
default = 0
[[table.usage_routing_snapshots.columns]]
name = "updated_at"
type = "unix_seconds"
default = 0
[[table.usage_routing_snapshots.indexes]]
name = "ix_usage_routing_snapshots_route_family_kind"
columns = ["route_family", "route_kind"]
[[table.usage_routing_snapshots.indexes]]
name = "ix_usage_routing_snapshots_candidate_id"
columns = ["candidate_id"]
[[table.usage_routing_snapshots.foreign_keys]]
name = "usage_routing_snapshots_request_id_fkey"
columns = ["request_id"]
references_table = "usage"
references_columns = ["request_id"]
on_delete = "cascade"
[table.usage_settlement_snapshots]
domain = "usage"
order = 20

File diff suppressed because it is too large Load Diff