mirror of
https://github.com/fawney19/Aether.git
synced 2026-09-02 17:30:23 +08:00
Add multi-database data layer
Introduce aether-data-schema and driver-specific schema generation for Postgres, MySQL, and SQLite. Split data backends, lifecycle, repositories, and gateway runtime integration across database drivers. Verified with cargo fmt --all --check, cargo clippy --workspace --all-targets -- -D warnings, and cargo test --workspace.
This commit is contained in:
@@ -0,0 +1,188 @@
|
||||
-- Generated by aether-data-schema from schema/logical/*.toml.
|
||||
-- Do not edit generated files directly; edit logical schema or explicit overrides instead.
|
||||
|
||||
CREATE TABLE IF NOT EXISTS public.users (
|
||||
id character varying(64) NOT NULL,
|
||||
external_id character varying(255),
|
||||
email character varying(320),
|
||||
username character varying(255),
|
||||
password_hash character varying(255),
|
||||
role character varying(64),
|
||||
auth_source character varying(64) DEFAULT 'local' NOT NULL,
|
||||
email_verified boolean DEFAULT false NOT NULL,
|
||||
is_active boolean DEFAULT true NOT NULL,
|
||||
is_deleted boolean DEFAULT false NOT NULL,
|
||||
allowed_models jsonb,
|
||||
allowed_providers jsonb,
|
||||
allowed_api_formats jsonb,
|
||||
model_capability_settings jsonb,
|
||||
rate_limit integer,
|
||||
metadata jsonb,
|
||||
created_at bigint NOT NULL,
|
||||
updated_at bigint NOT NULL,
|
||||
last_login_at bigint,
|
||||
ldap_dn character varying(1024),
|
||||
ldap_username character varying(255)
|
||||
);
|
||||
|
||||
ALTER TABLE ONLY public.users ADD CONSTRAINT users_pkey PRIMARY KEY (id);
|
||||
ALTER TABLE ONLY public.users ADD CONSTRAINT users_email_key UNIQUE (email);
|
||||
ALTER TABLE ONLY public.users ADD CONSTRAINT users_username_key UNIQUE (username);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS public.api_keys (
|
||||
id character varying(64) NOT NULL,
|
||||
user_id character varying(64) NOT NULL,
|
||||
key_hash character varying(255) NOT NULL,
|
||||
key_encrypted text,
|
||||
name character varying(255),
|
||||
key_prefix character varying(64),
|
||||
status character varying(64) DEFAULT 'active' NOT NULL,
|
||||
allowed_models jsonb,
|
||||
allowed_providers jsonb,
|
||||
allowed_api_formats jsonb,
|
||||
rate_limit integer DEFAULT 100,
|
||||
concurrent_limit integer,
|
||||
force_capabilities jsonb,
|
||||
is_active boolean DEFAULT true NOT NULL,
|
||||
is_locked boolean DEFAULT false NOT NULL,
|
||||
is_standalone boolean DEFAULT false NOT NULL,
|
||||
auto_delete_on_expiry boolean DEFAULT false NOT NULL,
|
||||
total_requests bigint DEFAULT 0 NOT NULL,
|
||||
total_tokens bigint DEFAULT 0 NOT NULL,
|
||||
total_cost_usd double precision DEFAULT 0 NOT NULL,
|
||||
metadata jsonb,
|
||||
expires_at bigint,
|
||||
last_used_at bigint,
|
||||
created_at bigint NOT NULL,
|
||||
updated_at bigint NOT NULL
|
||||
);
|
||||
|
||||
ALTER TABLE ONLY public.api_keys ADD CONSTRAINT api_keys_pkey PRIMARY KEY (id);
|
||||
ALTER TABLE ONLY public.api_keys ADD CONSTRAINT api_keys_key_hash_key UNIQUE (key_hash);
|
||||
CREATE INDEX IF NOT EXISTS api_keys_user_id_idx ON public.api_keys USING btree (user_id);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS public.audit_logs (
|
||||
id character varying(64) NOT NULL,
|
||||
event_type character varying(64) NOT NULL,
|
||||
user_id character varying(64),
|
||||
api_key_id character varying(64),
|
||||
description text NOT NULL,
|
||||
ip_address character varying(64),
|
||||
user_agent character varying(512),
|
||||
request_id character varying(128),
|
||||
event_metadata jsonb,
|
||||
status_code integer,
|
||||
error_message text,
|
||||
created_at bigint NOT NULL
|
||||
);
|
||||
|
||||
ALTER TABLE ONLY public.audit_logs ADD CONSTRAINT audit_logs_pkey PRIMARY KEY (id);
|
||||
CREATE INDEX IF NOT EXISTS audit_logs_created_at_idx ON public.audit_logs USING btree (created_at);
|
||||
CREATE INDEX IF NOT EXISTS audit_logs_event_type_idx ON public.audit_logs USING btree (event_type);
|
||||
CREATE INDEX IF NOT EXISTS audit_logs_request_id_idx ON public.audit_logs USING btree (request_id);
|
||||
CREATE INDEX IF NOT EXISTS audit_logs_user_id_idx ON public.audit_logs USING btree (user_id);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS public.announcements (
|
||||
id character varying(64) NOT NULL,
|
||||
title character varying(200) NOT NULL,
|
||||
content text NOT NULL,
|
||||
type character varying(32) DEFAULT 'info' NOT NULL,
|
||||
priority integer DEFAULT 0 NOT NULL,
|
||||
author_id character varying(64),
|
||||
is_active boolean DEFAULT true NOT NULL,
|
||||
is_pinned boolean DEFAULT false NOT NULL,
|
||||
start_time bigint,
|
||||
end_time bigint,
|
||||
created_at bigint NOT NULL,
|
||||
updated_at bigint NOT NULL
|
||||
);
|
||||
|
||||
ALTER TABLE ONLY public.announcements ADD CONSTRAINT announcements_pkey PRIMARY KEY (id);
|
||||
CREATE INDEX IF NOT EXISTS announcements_author_id_idx ON public.announcements USING btree (author_id);
|
||||
CREATE INDEX IF NOT EXISTS announcements_created_at_idx ON public.announcements USING btree (created_at);
|
||||
CREATE INDEX IF NOT EXISTS announcements_is_active_idx ON public.announcements USING btree (is_active);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS public.announcement_reads (
|
||||
id character varying(64) NOT NULL,
|
||||
user_id character varying(64) NOT NULL,
|
||||
announcement_id character varying(64) NOT NULL,
|
||||
read_at bigint NOT NULL
|
||||
);
|
||||
|
||||
ALTER TABLE ONLY public.announcement_reads ADD CONSTRAINT announcement_reads_pkey PRIMARY KEY (id);
|
||||
ALTER TABLE ONLY public.announcement_reads ADD CONSTRAINT uq_user_announcement UNIQUE (user_id, announcement_id);
|
||||
CREATE INDEX IF NOT EXISTS announcement_reads_announcement_id_idx ON public.announcement_reads USING btree (announcement_id);
|
||||
CREATE INDEX IF NOT EXISTS announcement_reads_user_id_idx ON public.announcement_reads USING btree (user_id);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS public.management_tokens (
|
||||
id character varying(64) NOT NULL,
|
||||
user_id character varying(64) NOT NULL,
|
||||
name character varying(255) NOT NULL,
|
||||
description text,
|
||||
token_hash character varying(255) NOT NULL,
|
||||
token_prefix character varying(64),
|
||||
allowed_ips jsonb,
|
||||
expires_at bigint,
|
||||
last_used_at bigint,
|
||||
last_used_ip character varying(255),
|
||||
usage_count bigint DEFAULT 0 NOT NULL,
|
||||
is_active boolean DEFAULT true NOT NULL,
|
||||
created_at bigint NOT NULL,
|
||||
updated_at bigint NOT NULL
|
||||
);
|
||||
|
||||
ALTER TABLE ONLY public.management_tokens ADD CONSTRAINT management_tokens_pkey PRIMARY KEY (id);
|
||||
ALTER TABLE ONLY public.management_tokens ADD CONSTRAINT management_tokens_token_hash_key UNIQUE (token_hash);
|
||||
ALTER TABLE ONLY public.management_tokens ADD CONSTRAINT uq_management_tokens_user_name UNIQUE (user_id, name);
|
||||
CREATE INDEX IF NOT EXISTS management_tokens_user_id_idx ON public.management_tokens USING btree (user_id);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS public.user_preferences (
|
||||
id character varying(64) NOT NULL,
|
||||
user_id character varying(64) NOT NULL,
|
||||
avatar_url character varying(500),
|
||||
bio text,
|
||||
default_provider_id character varying(64),
|
||||
theme character varying(20) DEFAULT 'light' NOT NULL,
|
||||
language character varying(10) DEFAULT 'zh-CN' NOT NULL,
|
||||
timezone character varying(50) DEFAULT 'Asia/Shanghai' NOT NULL,
|
||||
email_notifications boolean DEFAULT true NOT NULL,
|
||||
usage_alerts boolean DEFAULT true NOT NULL,
|
||||
announcement_notifications boolean DEFAULT true NOT NULL,
|
||||
created_at bigint NOT NULL,
|
||||
updated_at bigint NOT NULL
|
||||
);
|
||||
|
||||
ALTER TABLE ONLY public.user_preferences ADD CONSTRAINT user_preferences_pkey PRIMARY KEY (id);
|
||||
ALTER TABLE ONLY public.user_preferences ADD CONSTRAINT user_preferences_user_id_key UNIQUE (user_id);
|
||||
CREATE INDEX IF NOT EXISTS user_preferences_default_provider_id_idx ON public.user_preferences USING btree (default_provider_id);
|
||||
CREATE INDEX IF NOT EXISTS user_preferences_user_id_idx ON public.user_preferences USING btree (user_id);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS public.user_sessions (
|
||||
id character varying(64) NOT NULL,
|
||||
user_id character varying(64) NOT NULL,
|
||||
client_device_id character varying(128) NOT NULL,
|
||||
device_label character varying(120),
|
||||
device_type character varying(20) DEFAULT 'unknown' NOT NULL,
|
||||
browser_name character varying(50),
|
||||
browser_version character varying(50),
|
||||
os_name character varying(50),
|
||||
os_version character varying(50),
|
||||
device_model character varying(100),
|
||||
ip_address character varying(45),
|
||||
user_agent character varying(1000),
|
||||
client_hints jsonb,
|
||||
refresh_token_hash character varying(64) NOT NULL,
|
||||
prev_refresh_token_hash character varying(64),
|
||||
rotated_at bigint,
|
||||
last_seen_at bigint NOT NULL,
|
||||
expires_at bigint NOT NULL,
|
||||
revoked_at bigint,
|
||||
revoke_reason character varying(100),
|
||||
created_at bigint NOT NULL,
|
||||
updated_at bigint NOT NULL
|
||||
);
|
||||
|
||||
ALTER TABLE ONLY public.user_sessions ADD CONSTRAINT user_sessions_pkey PRIMARY KEY (id);
|
||||
CREATE INDEX IF NOT EXISTS user_sessions_user_active_idx ON public.user_sessions USING btree (user_id, revoked_at, expires_at);
|
||||
CREATE INDEX IF NOT EXISTS user_sessions_user_device_idx ON public.user_sessions USING btree (user_id, client_device_id);
|
||||
|
||||
@@ -0,0 +1,366 @@
|
||||
-- Generated by aether-data-schema from schema/logical/*.toml.
|
||||
-- Do not edit generated files directly; edit logical schema or explicit overrides instead.
|
||||
|
||||
CREATE TABLE IF NOT EXISTS public.billing_rules (
|
||||
id character varying(64) NOT NULL,
|
||||
global_model_id character varying(64),
|
||||
model_id character varying(64),
|
||||
name character varying(255) NOT NULL,
|
||||
task_type character varying(64) DEFAULT 'chat' NOT NULL,
|
||||
expression text NOT NULL,
|
||||
variables jsonb NOT NULL,
|
||||
dimension_mappings jsonb NOT NULL,
|
||||
is_enabled boolean DEFAULT true NOT NULL,
|
||||
created_at bigint NOT NULL,
|
||||
updated_at bigint NOT NULL
|
||||
);
|
||||
|
||||
ALTER TABLE ONLY public.billing_rules ADD CONSTRAINT billing_rules_pkey PRIMARY KEY (id);
|
||||
CREATE INDEX IF NOT EXISTS billing_rules_global_model_task_idx ON public.billing_rules USING btree (global_model_id, task_type, is_enabled);
|
||||
CREATE INDEX IF NOT EXISTS billing_rules_model_task_idx ON public.billing_rules USING btree (model_id, task_type, is_enabled);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS public.dimension_collectors (
|
||||
id character varying(64) NOT NULL,
|
||||
api_format character varying(64) NOT NULL,
|
||||
task_type character varying(64) NOT NULL,
|
||||
dimension_name character varying(128) NOT NULL,
|
||||
source_type character varying(64) NOT NULL,
|
||||
source_path character varying(255),
|
||||
value_type character varying(64) DEFAULT 'float' NOT NULL,
|
||||
transform_expression text,
|
||||
default_value character varying(255),
|
||||
priority integer DEFAULT 0 NOT NULL,
|
||||
is_enabled boolean DEFAULT true NOT NULL,
|
||||
created_at bigint NOT NULL,
|
||||
updated_at bigint NOT NULL
|
||||
);
|
||||
|
||||
ALTER TABLE ONLY public.dimension_collectors ADD CONSTRAINT dimension_collectors_pkey PRIMARY KEY (id);
|
||||
CREATE INDEX IF NOT EXISTS dimension_collectors_enabled_idx ON public.dimension_collectors USING btree (api_format, task_type, dimension_name, priority, is_enabled);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS public.providers (
|
||||
id character varying(64) NOT NULL,
|
||||
name character varying(255) NOT NULL,
|
||||
description text,
|
||||
website character varying(500),
|
||||
provider_type character varying(64) NOT NULL,
|
||||
billing_type character varying(64),
|
||||
monthly_quota_usd double precision,
|
||||
monthly_used_usd double precision,
|
||||
quota_reset_day integer,
|
||||
quota_last_reset_at bigint,
|
||||
quota_expires_at bigint,
|
||||
enabled boolean DEFAULT true NOT NULL,
|
||||
is_active boolean DEFAULT true NOT NULL,
|
||||
priority bigint DEFAULT 0 NOT NULL,
|
||||
provider_priority integer DEFAULT 100 NOT NULL,
|
||||
keep_priority_on_conversion boolean DEFAULT false NOT NULL,
|
||||
enable_format_conversion boolean DEFAULT true NOT NULL,
|
||||
concurrent_limit integer,
|
||||
max_retries integer,
|
||||
proxy jsonb,
|
||||
request_timeout double precision,
|
||||
stream_first_byte_timeout double precision,
|
||||
config jsonb,
|
||||
created_at bigint NOT NULL,
|
||||
updated_at bigint NOT NULL
|
||||
);
|
||||
|
||||
ALTER TABLE ONLY public.providers ADD CONSTRAINT providers_pkey PRIMARY KEY (id);
|
||||
ALTER TABLE ONLY public.providers ADD CONSTRAINT providers_name_key UNIQUE (name);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS public.provider_api_keys (
|
||||
id character varying(64) NOT NULL,
|
||||
provider_id character varying(64) NOT NULL,
|
||||
name character varying(255) NOT NULL,
|
||||
api_key text,
|
||||
encrypted_key text,
|
||||
auth_type character varying(32) DEFAULT 'api_key' NOT NULL,
|
||||
auth_config jsonb,
|
||||
note text,
|
||||
internal_priority integer DEFAULT 50 NOT NULL,
|
||||
capabilities jsonb,
|
||||
api_formats jsonb,
|
||||
auth_type_by_format jsonb,
|
||||
allow_auth_channel_mismatch_formats jsonb,
|
||||
rate_multipliers jsonb,
|
||||
global_priority_by_format jsonb,
|
||||
allowed_models jsonb,
|
||||
expires_at bigint,
|
||||
cache_ttl_minutes integer DEFAULT 5 NOT NULL,
|
||||
max_probe_interval_minutes integer DEFAULT 32 NOT NULL,
|
||||
proxy jsonb,
|
||||
fingerprint jsonb,
|
||||
concurrent_limit integer,
|
||||
learned_rpm_limit integer,
|
||||
concurrent_429_count integer DEFAULT 0 NOT NULL,
|
||||
rpm_429_count integer DEFAULT 0 NOT NULL,
|
||||
last_429_at bigint,
|
||||
last_429_type character varying(64),
|
||||
adjustment_history jsonb,
|
||||
utilization_samples jsonb,
|
||||
last_probe_increase_at bigint,
|
||||
last_rpm_peak integer,
|
||||
request_count bigint DEFAULT 0 NOT NULL,
|
||||
total_tokens bigint DEFAULT 0 NOT NULL,
|
||||
total_cost_usd double precision DEFAULT 0 NOT NULL,
|
||||
success_count bigint DEFAULT 0 NOT NULL,
|
||||
error_count bigint DEFAULT 0 NOT NULL,
|
||||
total_response_time_ms bigint DEFAULT 0 NOT NULL,
|
||||
last_used_at bigint,
|
||||
last_error_at bigint,
|
||||
last_error_msg text,
|
||||
auto_fetch_models boolean DEFAULT false NOT NULL,
|
||||
last_models_fetch_at bigint,
|
||||
last_models_fetch_error text,
|
||||
locked_models jsonb,
|
||||
model_include_patterns jsonb,
|
||||
model_exclude_patterns jsonb,
|
||||
upstream_metadata jsonb,
|
||||
oauth_invalid_at bigint,
|
||||
oauth_invalid_reason character varying(255),
|
||||
status_snapshot jsonb,
|
||||
health_by_format jsonb,
|
||||
circuit_breaker_by_format jsonb,
|
||||
status character varying(64) DEFAULT 'active' NOT NULL,
|
||||
is_active boolean DEFAULT true NOT NULL,
|
||||
weight bigint DEFAULT 1 NOT NULL,
|
||||
rpm_limit bigint,
|
||||
metadata jsonb,
|
||||
created_at bigint NOT NULL,
|
||||
updated_at bigint NOT NULL
|
||||
);
|
||||
|
||||
ALTER TABLE ONLY public.provider_api_keys ADD CONSTRAINT provider_api_keys_pkey PRIMARY KEY (id);
|
||||
CREATE INDEX IF NOT EXISTS provider_api_keys_provider_id_idx ON public.provider_api_keys USING btree (provider_id);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS public.api_key_provider_mappings (
|
||||
id character varying(64) NOT NULL,
|
||||
api_key_id character varying(64) NOT NULL,
|
||||
provider_id character varying(64) NOT NULL,
|
||||
priority_adjustment integer DEFAULT 0 NOT NULL,
|
||||
weight_multiplier double precision DEFAULT 1 NOT NULL,
|
||||
is_enabled boolean DEFAULT true NOT NULL,
|
||||
created_at bigint NOT NULL,
|
||||
updated_at bigint NOT NULL
|
||||
);
|
||||
|
||||
ALTER TABLE ONLY public.api_key_provider_mappings ADD CONSTRAINT api_key_provider_mappings_pkey PRIMARY KEY (id);
|
||||
ALTER TABLE ONLY public.api_key_provider_mappings ADD CONSTRAINT uq_apikey_provider UNIQUE (api_key_id, provider_id);
|
||||
CREATE INDEX IF NOT EXISTS api_key_provider_mappings_api_key_id_idx ON public.api_key_provider_mappings USING btree (api_key_id);
|
||||
CREATE INDEX IF NOT EXISTS api_key_provider_mappings_provider_id_idx ON public.api_key_provider_mappings USING btree (provider_id);
|
||||
CREATE INDEX IF NOT EXISTS idx_apikey_provider_enabled ON public.api_key_provider_mappings USING btree (api_key_id, is_enabled);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS public.gemini_file_mappings (
|
||||
id character varying(64) NOT NULL,
|
||||
file_name character varying(512) NOT NULL,
|
||||
key_id character varying(64) NOT NULL,
|
||||
user_id character varying(64),
|
||||
display_name character varying(512),
|
||||
mime_type character varying(255),
|
||||
source_hash character varying(128),
|
||||
created_at bigint NOT NULL,
|
||||
expires_at bigint NOT NULL
|
||||
);
|
||||
|
||||
ALTER TABLE ONLY public.gemini_file_mappings ADD CONSTRAINT gemini_file_mappings_pkey PRIMARY KEY (id);
|
||||
ALTER TABLE ONLY public.gemini_file_mappings ADD CONSTRAINT gemini_file_mappings_file_name_key UNIQUE (file_name);
|
||||
CREATE INDEX IF NOT EXISTS gemini_file_mappings_key_id_idx ON public.gemini_file_mappings USING btree (key_id);
|
||||
CREATE INDEX IF NOT EXISTS gemini_file_mappings_user_id_idx ON public.gemini_file_mappings USING btree (user_id);
|
||||
CREATE INDEX IF NOT EXISTS gemini_file_mappings_expires_at_idx ON public.gemini_file_mappings USING btree (expires_at);
|
||||
CREATE INDEX IF NOT EXISTS gemini_file_mappings_source_hash_idx ON public.gemini_file_mappings USING btree (source_hash);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS public.request_candidates (
|
||||
id character varying(64) NOT NULL,
|
||||
request_id character varying(128) NOT NULL,
|
||||
user_id character varying(64),
|
||||
api_key_id character varying(64),
|
||||
username character varying(255),
|
||||
api_key_name character varying(255),
|
||||
candidate_index integer NOT NULL,
|
||||
retry_index integer DEFAULT 0 NOT NULL,
|
||||
provider_id character varying(64),
|
||||
endpoint_id character varying(64),
|
||||
key_id character varying(64),
|
||||
status character varying(32) NOT NULL,
|
||||
skip_reason text,
|
||||
is_cached boolean DEFAULT false NOT NULL,
|
||||
status_code integer,
|
||||
error_type character varying(128),
|
||||
error_message text,
|
||||
latency_ms integer,
|
||||
concurrent_requests integer,
|
||||
extra_data jsonb,
|
||||
required_capabilities jsonb,
|
||||
created_at bigint NOT NULL,
|
||||
started_at bigint,
|
||||
finished_at bigint
|
||||
);
|
||||
|
||||
ALTER TABLE ONLY public.request_candidates ADD CONSTRAINT request_candidates_pkey PRIMARY KEY (id);
|
||||
ALTER TABLE ONLY public.request_candidates ADD CONSTRAINT uq_request_candidate_with_retry UNIQUE (request_id, candidate_index, retry_index);
|
||||
CREATE INDEX IF NOT EXISTS request_candidates_request_id_idx ON public.request_candidates USING btree (request_id);
|
||||
CREATE INDEX IF NOT EXISTS request_candidates_provider_id_idx ON public.request_candidates USING btree (provider_id);
|
||||
CREATE INDEX IF NOT EXISTS request_candidates_endpoint_id_idx ON public.request_candidates USING btree (endpoint_id);
|
||||
CREATE INDEX IF NOT EXISTS request_candidates_status_idx ON public.request_candidates USING btree (status);
|
||||
CREATE INDEX IF NOT EXISTS request_candidates_created_at_idx ON public.request_candidates USING btree (created_at);
|
||||
CREATE INDEX IF NOT EXISTS request_candidates_endpoint_status_created_idx ON public.request_candidates USING btree (endpoint_id, status, created_at);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS public.video_tasks (
|
||||
id character varying(64) NOT NULL,
|
||||
short_id character varying(32),
|
||||
request_id character varying(128) NOT NULL,
|
||||
user_id character varying(64),
|
||||
api_key_id character varying(64),
|
||||
username character varying(255),
|
||||
api_key_name character varying(255),
|
||||
external_task_id character varying(255),
|
||||
provider_id character varying(64),
|
||||
endpoint_id character varying(64),
|
||||
key_id character varying(64),
|
||||
client_api_format character varying(128),
|
||||
provider_api_format character varying(128),
|
||||
format_converted boolean DEFAULT false NOT NULL,
|
||||
model character varying(255),
|
||||
prompt text,
|
||||
original_request_body jsonb,
|
||||
converted_request_body jsonb,
|
||||
duration_seconds integer,
|
||||
resolution character varying(64),
|
||||
aspect_ratio character varying(32),
|
||||
size character varying(64),
|
||||
status character varying(32) DEFAULT 'pending' NOT NULL,
|
||||
progress_percent integer DEFAULT 0 NOT NULL,
|
||||
progress_message text,
|
||||
retry_count integer DEFAULT 0 NOT NULL,
|
||||
max_retries integer DEFAULT 3 NOT NULL,
|
||||
poll_interval_seconds integer DEFAULT 10 NOT NULL,
|
||||
next_poll_at bigint,
|
||||
poll_count integer DEFAULT 0 NOT NULL,
|
||||
max_poll_count integer DEFAULT 360 NOT NULL,
|
||||
created_at bigint NOT NULL,
|
||||
submitted_at bigint,
|
||||
completed_at bigint,
|
||||
updated_at bigint NOT NULL,
|
||||
error_code character varying(128),
|
||||
error_message text,
|
||||
video_url text,
|
||||
video_urls jsonb,
|
||||
thumbnail_url text,
|
||||
video_size_bytes bigint,
|
||||
video_expires_at bigint,
|
||||
stored_video_path character varying(500),
|
||||
storage_provider character varying(50),
|
||||
remixed_from_task_id character varying(64),
|
||||
webhook_url character varying(500),
|
||||
webhook_sent boolean DEFAULT false NOT NULL,
|
||||
webhook_sent_at bigint,
|
||||
request_metadata jsonb,
|
||||
video_duration_seconds double precision
|
||||
);
|
||||
|
||||
ALTER TABLE ONLY public.video_tasks ADD CONSTRAINT video_tasks_pkey PRIMARY KEY (id);
|
||||
ALTER TABLE ONLY public.video_tasks ADD CONSTRAINT video_tasks_short_id_key UNIQUE (short_id);
|
||||
ALTER TABLE ONLY public.video_tasks ADD CONSTRAINT video_tasks_request_id_key UNIQUE (request_id);
|
||||
CREATE INDEX IF NOT EXISTS video_tasks_external_id_idx ON public.video_tasks USING btree (external_task_id);
|
||||
CREATE INDEX IF NOT EXISTS video_tasks_next_poll_idx ON public.video_tasks USING btree (next_poll_at);
|
||||
CREATE INDEX IF NOT EXISTS video_tasks_user_status_idx ON public.video_tasks USING btree (user_id, status);
|
||||
CREATE INDEX IF NOT EXISTS video_tasks_api_key_id_idx ON public.video_tasks USING btree (api_key_id);
|
||||
CREATE INDEX IF NOT EXISTS video_tasks_provider_id_idx ON public.video_tasks USING btree (provider_id);
|
||||
CREATE INDEX IF NOT EXISTS video_tasks_endpoint_id_idx ON public.video_tasks USING btree (endpoint_id);
|
||||
CREATE INDEX IF NOT EXISTS video_tasks_key_id_idx ON public.video_tasks USING btree (key_id);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS public.provider_endpoints (
|
||||
id character varying(64) NOT NULL,
|
||||
provider_id character varying(64) NOT NULL,
|
||||
name character varying(255) NOT NULL,
|
||||
base_url text NOT NULL,
|
||||
api_format character varying(128),
|
||||
api_family character varying(128),
|
||||
endpoint_kind character varying(128),
|
||||
enabled boolean DEFAULT true NOT NULL,
|
||||
is_active boolean DEFAULT true NOT NULL,
|
||||
health_score double precision DEFAULT 1.0 NOT NULL,
|
||||
weight bigint DEFAULT 1 NOT NULL,
|
||||
header_rules jsonb,
|
||||
body_rules jsonb,
|
||||
max_retries integer,
|
||||
custom_path text,
|
||||
metadata jsonb,
|
||||
config jsonb,
|
||||
format_acceptance_config jsonb,
|
||||
proxy jsonb,
|
||||
created_at bigint NOT NULL,
|
||||
updated_at bigint NOT NULL
|
||||
);
|
||||
|
||||
ALTER TABLE ONLY public.provider_endpoints ADD CONSTRAINT provider_endpoints_pkey PRIMARY KEY (id);
|
||||
CREATE INDEX IF NOT EXISTS provider_endpoints_provider_id_idx ON public.provider_endpoints USING btree (provider_id);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS public.provider_usage_tracking (
|
||||
id character varying(64) NOT NULL,
|
||||
provider_id character varying(64) NOT NULL,
|
||||
window_start bigint NOT NULL,
|
||||
window_end bigint NOT NULL,
|
||||
total_requests integer DEFAULT 0 NOT NULL,
|
||||
successful_requests integer DEFAULT 0 NOT NULL,
|
||||
failed_requests integer DEFAULT 0 NOT NULL,
|
||||
avg_response_time_ms double precision DEFAULT 0 NOT NULL,
|
||||
total_response_time_ms double precision DEFAULT 0 NOT NULL,
|
||||
total_cost_usd double precision DEFAULT 0 NOT NULL,
|
||||
created_at bigint NOT NULL,
|
||||
updated_at bigint NOT NULL
|
||||
);
|
||||
|
||||
ALTER TABLE ONLY public.provider_usage_tracking ADD CONSTRAINT provider_usage_tracking_pkey PRIMARY KEY (id);
|
||||
CREATE INDEX IF NOT EXISTS provider_usage_tracking_provider_id_idx ON public.provider_usage_tracking USING btree (provider_id);
|
||||
CREATE INDEX IF NOT EXISTS provider_usage_tracking_window_start_idx ON public.provider_usage_tracking USING btree (window_start);
|
||||
CREATE INDEX IF NOT EXISTS idx_provider_window ON public.provider_usage_tracking USING btree (provider_id, window_start);
|
||||
CREATE INDEX IF NOT EXISTS idx_window_time ON public.provider_usage_tracking USING btree (window_start, window_end);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS public.models (
|
||||
id character varying(64) NOT NULL,
|
||||
provider_id character varying(64) NOT NULL,
|
||||
global_model_id character varying(64),
|
||||
provider_model_name character varying(255) NOT NULL,
|
||||
global_model_name character varying(255),
|
||||
api_format character varying(128),
|
||||
enabled boolean DEFAULT true NOT NULL,
|
||||
is_active boolean DEFAULT true NOT NULL,
|
||||
is_available boolean DEFAULT true NOT NULL,
|
||||
price_per_request double precision,
|
||||
tiered_pricing jsonb,
|
||||
supports_vision boolean,
|
||||
supports_function_calling boolean,
|
||||
supports_streaming boolean,
|
||||
supports_extended_thinking boolean,
|
||||
supports_image_generation boolean,
|
||||
provider_model_mappings jsonb,
|
||||
config jsonb,
|
||||
metadata jsonb,
|
||||
created_at bigint NOT NULL,
|
||||
updated_at bigint NOT NULL
|
||||
);
|
||||
|
||||
ALTER TABLE ONLY public.models ADD CONSTRAINT models_pkey PRIMARY KEY (id);
|
||||
CREATE INDEX IF NOT EXISTS models_provider_id_idx ON public.models USING btree (provider_id);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS public.global_models (
|
||||
id character varying(64) NOT NULL,
|
||||
name character varying(255) NOT NULL,
|
||||
display_name character varying(255),
|
||||
enabled boolean DEFAULT true NOT NULL,
|
||||
is_active boolean DEFAULT true NOT NULL,
|
||||
default_price_per_request double precision,
|
||||
default_tiered_pricing jsonb,
|
||||
supported_capabilities jsonb,
|
||||
usage_count bigint DEFAULT 0 NOT NULL,
|
||||
config jsonb,
|
||||
metadata jsonb,
|
||||
created_at bigint NOT NULL,
|
||||
updated_at bigint NOT NULL
|
||||
);
|
||||
|
||||
ALTER TABLE ONLY public.global_models ADD CONSTRAINT global_models_pkey PRIMARY KEY (id);
|
||||
ALTER TABLE ONLY public.global_models ADD CONSTRAINT global_models_name_key UNIQUE (name);
|
||||
|
||||
@@ -0,0 +1,85 @@
|
||||
-- Generated by aether-data-schema from schema/logical/*.toml.
|
||||
-- Do not edit generated files directly; edit logical schema or explicit overrides instead.
|
||||
|
||||
CREATE TABLE IF NOT EXISTS public.system_configs (
|
||||
id character varying(64) NOT NULL,
|
||||
key character varying(255) NOT NULL,
|
||||
value text NOT NULL,
|
||||
description text,
|
||||
created_at bigint NOT NULL,
|
||||
updated_at bigint NOT NULL
|
||||
);
|
||||
|
||||
ALTER TABLE ONLY public.system_configs ADD CONSTRAINT system_configs_pkey PRIMARY KEY (id);
|
||||
ALTER TABLE ONLY public.system_configs ADD CONSTRAINT system_configs_key_key UNIQUE (key);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS public.auth_modules (
|
||||
id character varying(64) NOT NULL,
|
||||
module_type character varying(128) NOT NULL,
|
||||
enabled boolean DEFAULT true NOT NULL,
|
||||
config jsonb NOT NULL,
|
||||
created_at bigint NOT NULL,
|
||||
updated_at bigint NOT NULL
|
||||
);
|
||||
|
||||
ALTER TABLE ONLY public.auth_modules ADD CONSTRAINT auth_modules_pkey PRIMARY KEY (id);
|
||||
ALTER TABLE ONLY public.auth_modules ADD CONSTRAINT auth_modules_module_type_key UNIQUE (module_type);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS public.oauth_providers (
|
||||
provider_type character varying(64) NOT NULL,
|
||||
display_name character varying(255) NOT NULL,
|
||||
client_id text NOT NULL,
|
||||
client_secret_encrypted text,
|
||||
authorization_url_override character varying(500),
|
||||
token_url_override character varying(500),
|
||||
userinfo_url_override character varying(500),
|
||||
scopes jsonb,
|
||||
redirect_uri character varying(500) NOT NULL,
|
||||
frontend_callback_url character varying(500) NOT NULL,
|
||||
attribute_mapping jsonb,
|
||||
extra_config jsonb,
|
||||
is_enabled boolean DEFAULT false NOT NULL,
|
||||
created_at bigint NOT NULL,
|
||||
updated_at bigint NOT NULL
|
||||
);
|
||||
|
||||
ALTER TABLE ONLY public.oauth_providers ADD CONSTRAINT oauth_providers_pkey PRIMARY KEY (provider_type);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS public.ldap_configs (
|
||||
id bigserial NOT NULL,
|
||||
server_url character varying(255) NOT NULL,
|
||||
bind_dn text NOT NULL,
|
||||
bind_password_encrypted text,
|
||||
base_dn text NOT NULL,
|
||||
user_search_filter text DEFAULT '(uid={username})' NOT NULL,
|
||||
username_attr character varying(50) DEFAULT 'uid' NOT NULL,
|
||||
email_attr character varying(50) DEFAULT 'mail' NOT NULL,
|
||||
display_name_attr character varying(50) DEFAULT 'cn' NOT NULL,
|
||||
is_enabled boolean DEFAULT false NOT NULL,
|
||||
is_exclusive boolean DEFAULT false NOT NULL,
|
||||
use_starttls boolean DEFAULT false NOT NULL,
|
||||
connect_timeout integer DEFAULT 10 NOT NULL,
|
||||
created_at bigint NOT NULL,
|
||||
updated_at bigint NOT NULL
|
||||
);
|
||||
|
||||
ALTER TABLE ONLY public.ldap_configs ADD CONSTRAINT ldap_configs_pkey PRIMARY KEY (id);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS public.user_oauth_links (
|
||||
id character varying(64) NOT NULL,
|
||||
user_id character varying(64) NOT NULL,
|
||||
provider_type character varying(64) NOT NULL,
|
||||
provider_user_id character varying(255) NOT NULL,
|
||||
provider_username character varying(255),
|
||||
provider_email character varying(255),
|
||||
extra_data jsonb,
|
||||
linked_at bigint NOT NULL,
|
||||
last_login_at bigint
|
||||
);
|
||||
|
||||
ALTER TABLE ONLY public.user_oauth_links ADD CONSTRAINT user_oauth_links_pkey PRIMARY KEY (id);
|
||||
ALTER TABLE ONLY public.user_oauth_links ADD CONSTRAINT uq_user_oauth_links_provider_user UNIQUE (provider_type, provider_user_id);
|
||||
ALTER TABLE ONLY public.user_oauth_links ADD CONSTRAINT uq_user_oauth_links_user_provider UNIQUE (user_id, provider_type);
|
||||
CREATE INDEX IF NOT EXISTS user_oauth_links_provider_type_idx ON public.user_oauth_links USING btree (provider_type);
|
||||
CREATE INDEX IF NOT EXISTS user_oauth_links_user_id_idx ON public.user_oauth_links USING btree (user_id);
|
||||
|
||||
@@ -0,0 +1,47 @@
|
||||
-- Generated by aether-data-schema from schema/logical/*.toml.
|
||||
-- Do not edit generated files directly; edit logical schema or explicit overrides instead.
|
||||
|
||||
CREATE TABLE IF NOT EXISTS public.proxy_nodes (
|
||||
id character varying(64) NOT NULL,
|
||||
name character varying(255) NOT NULL,
|
||||
ip character varying(512) NOT NULL,
|
||||
port integer NOT NULL,
|
||||
region character varying(100),
|
||||
status character varying(32) DEFAULT 'online' NOT NULL,
|
||||
registered_by character varying(64),
|
||||
last_heartbeat_at bigint,
|
||||
heartbeat_interval integer DEFAULT 30 NOT NULL,
|
||||
active_connections integer DEFAULT 0 NOT NULL,
|
||||
total_requests bigint DEFAULT 0 NOT NULL,
|
||||
avg_latency_ms double precision,
|
||||
is_manual boolean DEFAULT false NOT NULL,
|
||||
proxy_url character varying(500),
|
||||
proxy_username character varying(255),
|
||||
proxy_password character varying(500),
|
||||
created_at bigint NOT NULL,
|
||||
updated_at bigint NOT NULL,
|
||||
remote_config jsonb,
|
||||
config_version integer DEFAULT 0 NOT NULL,
|
||||
hardware_info jsonb,
|
||||
estimated_max_concurrency integer,
|
||||
tunnel_mode boolean DEFAULT false NOT NULL,
|
||||
tunnel_connected boolean DEFAULT false NOT NULL,
|
||||
tunnel_connected_at bigint,
|
||||
failed_requests bigint DEFAULT 0 NOT NULL,
|
||||
dns_failures bigint DEFAULT 0 NOT NULL,
|
||||
stream_errors bigint DEFAULT 0 NOT NULL,
|
||||
proxy_metadata jsonb
|
||||
);
|
||||
|
||||
ALTER TABLE ONLY public.proxy_nodes ADD CONSTRAINT proxy_nodes_pkey PRIMARY KEY (id);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS public.proxy_node_events (
|
||||
id bigserial NOT NULL,
|
||||
node_id character varying(64) NOT NULL,
|
||||
event_type character varying(64) NOT NULL,
|
||||
detail character varying(500),
|
||||
created_at bigint NOT NULL
|
||||
);
|
||||
|
||||
ALTER TABLE ONLY public.proxy_node_events ADD CONSTRAINT proxy_node_events_pkey PRIMARY KEY (id);
|
||||
|
||||
@@ -0,0 +1,203 @@
|
||||
-- Generated by aether-data-schema from schema/logical/*.toml.
|
||||
-- Do not edit generated files directly; edit logical schema or explicit overrides instead.
|
||||
|
||||
CREATE TABLE IF NOT EXISTS public.wallets (
|
||||
id character varying(64) NOT NULL,
|
||||
user_id character varying(64),
|
||||
api_key_id character varying(64),
|
||||
balance double precision DEFAULT 0 NOT NULL,
|
||||
gift_balance double precision DEFAULT 0 NOT NULL,
|
||||
limit_mode character varying(64) DEFAULT 'finite' NOT NULL,
|
||||
currency character varying(16) DEFAULT 'USD' NOT NULL,
|
||||
status character varying(64) DEFAULT 'active' NOT NULL,
|
||||
total_recharged double precision DEFAULT 0 NOT NULL,
|
||||
total_consumed double precision DEFAULT 0 NOT NULL,
|
||||
total_refunded double precision DEFAULT 0 NOT NULL,
|
||||
total_adjusted double precision DEFAULT 0 NOT NULL,
|
||||
created_at bigint NOT NULL,
|
||||
updated_at bigint NOT NULL
|
||||
);
|
||||
|
||||
ALTER TABLE ONLY public.wallets ADD CONSTRAINT wallets_pkey PRIMARY KEY (id);
|
||||
ALTER TABLE ONLY public.wallets ADD CONSTRAINT wallets_user_id_key UNIQUE (user_id);
|
||||
ALTER TABLE ONLY public.wallets ADD CONSTRAINT wallets_api_key_id_key UNIQUE (api_key_id);
|
||||
CREATE INDEX IF NOT EXISTS wallets_api_key_id_idx ON public.wallets USING btree (api_key_id);
|
||||
CREATE INDEX IF NOT EXISTS wallets_user_id_idx ON public.wallets USING btree (user_id);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS public.wallet_transactions (
|
||||
id character varying(64) NOT NULL,
|
||||
wallet_id character varying(64) NOT NULL,
|
||||
category character varying(64) NOT NULL,
|
||||
reason_code character varying(64) NOT NULL,
|
||||
amount double precision NOT NULL,
|
||||
balance_before double precision NOT NULL,
|
||||
balance_after double precision NOT NULL,
|
||||
recharge_balance_before double precision NOT NULL,
|
||||
recharge_balance_after double precision NOT NULL,
|
||||
gift_balance_before double precision NOT NULL,
|
||||
gift_balance_after double precision NOT NULL,
|
||||
link_type character varying(64),
|
||||
link_id character varying(128),
|
||||
operator_id character varying(64),
|
||||
description text,
|
||||
created_at bigint NOT NULL
|
||||
);
|
||||
|
||||
ALTER TABLE ONLY public.wallet_transactions ADD CONSTRAINT wallet_transactions_pkey PRIMARY KEY (id);
|
||||
CREATE INDEX IF NOT EXISTS idx_wallet_tx_wallet_created ON public.wallet_transactions USING btree (wallet_id, created_at);
|
||||
CREATE INDEX IF NOT EXISTS idx_wallet_tx_category_created ON public.wallet_transactions USING btree (category, created_at);
|
||||
CREATE INDEX IF NOT EXISTS idx_wallet_tx_reason_created ON public.wallet_transactions USING btree (reason_code, created_at);
|
||||
CREATE INDEX IF NOT EXISTS idx_wallet_tx_link ON public.wallet_transactions USING btree (link_type, link_id);
|
||||
CREATE INDEX IF NOT EXISTS ix_wallet_transactions_operator_id ON public.wallet_transactions USING btree (operator_id);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS public.wallet_daily_usage_ledgers (
|
||||
id character varying(64) NOT NULL,
|
||||
wallet_id character varying(64) NOT NULL,
|
||||
billing_date character varying(16) NOT NULL,
|
||||
billing_timezone character varying(64) NOT NULL,
|
||||
total_cost_usd double precision DEFAULT 0 NOT NULL,
|
||||
total_requests bigint DEFAULT 0 NOT NULL,
|
||||
input_tokens bigint DEFAULT 0 NOT NULL,
|
||||
output_tokens bigint DEFAULT 0 NOT NULL,
|
||||
cache_creation_tokens bigint DEFAULT 0 NOT NULL,
|
||||
cache_read_tokens bigint DEFAULT 0 NOT NULL,
|
||||
first_finalized_at bigint,
|
||||
last_finalized_at bigint,
|
||||
aggregated_at bigint NOT NULL,
|
||||
created_at bigint NOT NULL,
|
||||
updated_at bigint NOT NULL
|
||||
);
|
||||
|
||||
ALTER TABLE ONLY public.wallet_daily_usage_ledgers ADD CONSTRAINT wallet_daily_usage_ledgers_pkey PRIMARY KEY (id);
|
||||
CREATE INDEX IF NOT EXISTS idx_wallet_daily_usage_wallet_date ON public.wallet_daily_usage_ledgers USING btree (wallet_id, billing_timezone, billing_date);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS public.payment_orders (
|
||||
id character varying(64) NOT NULL,
|
||||
order_no character varying(128) NOT NULL,
|
||||
wallet_id character varying(64) NOT NULL,
|
||||
user_id character varying(64),
|
||||
amount_usd double precision NOT NULL,
|
||||
pay_amount double precision,
|
||||
pay_currency character varying(16),
|
||||
exchange_rate double precision,
|
||||
refunded_amount_usd double precision DEFAULT 0 NOT NULL,
|
||||
refundable_amount_usd double precision DEFAULT 0 NOT NULL,
|
||||
payment_method character varying(64) NOT NULL,
|
||||
gateway_order_id character varying(128),
|
||||
gateway_response jsonb,
|
||||
status character varying(64) DEFAULT 'pending' NOT NULL,
|
||||
created_at bigint NOT NULL,
|
||||
paid_at bigint,
|
||||
credited_at bigint,
|
||||
expires_at bigint
|
||||
);
|
||||
|
||||
ALTER TABLE ONLY public.payment_orders ADD CONSTRAINT payment_orders_pkey PRIMARY KEY (id);
|
||||
ALTER TABLE ONLY public.payment_orders ADD CONSTRAINT uq_payment_orders_order_no UNIQUE (order_no);
|
||||
CREATE INDEX IF NOT EXISTS idx_payment_orders_wallet_created ON public.payment_orders USING btree (wallet_id, created_at);
|
||||
CREATE INDEX IF NOT EXISTS idx_payment_orders_user_created ON public.payment_orders USING btree (user_id, created_at);
|
||||
CREATE INDEX IF NOT EXISTS idx_payment_orders_status ON public.payment_orders USING btree (status);
|
||||
CREATE INDEX IF NOT EXISTS idx_payment_orders_gateway_order_id ON public.payment_orders USING btree (gateway_order_id);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS public.payment_callbacks (
|
||||
id character varying(64) NOT NULL,
|
||||
payment_order_id character varying(64),
|
||||
payment_method character varying(64) NOT NULL,
|
||||
callback_key character varying(128) NOT NULL,
|
||||
order_no character varying(128),
|
||||
gateway_order_id character varying(128),
|
||||
payload_hash character varying(128),
|
||||
signature_valid boolean DEFAULT false NOT NULL,
|
||||
status character varying(64) DEFAULT 'received' NOT NULL,
|
||||
payload jsonb,
|
||||
error_message text,
|
||||
created_at bigint NOT NULL,
|
||||
processed_at bigint
|
||||
);
|
||||
|
||||
ALTER TABLE ONLY public.payment_callbacks ADD CONSTRAINT payment_callbacks_pkey PRIMARY KEY (id);
|
||||
ALTER TABLE ONLY public.payment_callbacks ADD CONSTRAINT uq_payment_callbacks_callback_key UNIQUE (callback_key);
|
||||
CREATE INDEX IF NOT EXISTS idx_payment_callbacks_order ON public.payment_callbacks USING btree (order_no);
|
||||
CREATE INDEX IF NOT EXISTS idx_payment_callbacks_gateway_order ON public.payment_callbacks USING btree (gateway_order_id);
|
||||
CREATE INDEX IF NOT EXISTS idx_payment_callbacks_created ON public.payment_callbacks USING btree (created_at);
|
||||
CREATE INDEX IF NOT EXISTS ix_payment_callbacks_payment_order_id ON public.payment_callbacks USING btree (payment_order_id);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS public.refund_requests (
|
||||
id character varying(64) NOT NULL,
|
||||
refund_no character varying(128) NOT NULL,
|
||||
wallet_id character varying(64) NOT NULL,
|
||||
user_id character varying(64),
|
||||
payment_order_id character varying(64),
|
||||
source_type character varying(64) NOT NULL,
|
||||
source_id character varying(128),
|
||||
refund_mode character varying(64) NOT NULL,
|
||||
amount_usd double precision NOT NULL,
|
||||
status character varying(64) DEFAULT 'pending_approval' NOT NULL,
|
||||
reason text,
|
||||
requested_by character varying(64),
|
||||
approved_by character varying(64),
|
||||
processed_by character varying(64),
|
||||
gateway_refund_id character varying(128),
|
||||
payout_method character varying(64),
|
||||
payout_reference character varying(255),
|
||||
payout_proof jsonb,
|
||||
failure_reason text,
|
||||
idempotency_key character varying(128),
|
||||
created_at bigint NOT NULL,
|
||||
updated_at bigint NOT NULL,
|
||||
processed_at bigint,
|
||||
completed_at bigint
|
||||
);
|
||||
|
||||
ALTER TABLE ONLY public.refund_requests ADD CONSTRAINT refund_requests_pkey PRIMARY KEY (id);
|
||||
ALTER TABLE ONLY public.refund_requests ADD CONSTRAINT uq_refund_requests_refund_no UNIQUE (refund_no);
|
||||
ALTER TABLE ONLY public.refund_requests ADD CONSTRAINT uq_refund_requests_idempotency_key UNIQUE (idempotency_key);
|
||||
CREATE INDEX IF NOT EXISTS idx_refund_wallet_created ON public.refund_requests USING btree (wallet_id, created_at);
|
||||
CREATE INDEX IF NOT EXISTS idx_refund_user_created ON public.refund_requests USING btree (user_id, created_at);
|
||||
CREATE INDEX IF NOT EXISTS idx_refund_status ON public.refund_requests USING btree (status);
|
||||
CREATE INDEX IF NOT EXISTS ix_refund_requests_payment_order_id ON public.refund_requests USING btree (payment_order_id);
|
||||
CREATE INDEX IF NOT EXISTS ix_refund_requests_requested_by ON public.refund_requests USING btree (requested_by);
|
||||
CREATE INDEX IF NOT EXISTS ix_refund_requests_approved_by ON public.refund_requests USING btree (approved_by);
|
||||
CREATE INDEX IF NOT EXISTS ix_refund_requests_processed_by ON public.refund_requests USING btree (processed_by);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS public.redeem_code_batches (
|
||||
id character varying(64) NOT NULL,
|
||||
name character varying(255) NOT NULL,
|
||||
amount_usd double precision NOT NULL,
|
||||
currency character varying(16) DEFAULT 'USD' NOT NULL,
|
||||
balance_bucket character varying(64) DEFAULT 'gift' NOT NULL,
|
||||
total_count integer NOT NULL,
|
||||
status character varying(64) DEFAULT 'active' NOT NULL,
|
||||
description text,
|
||||
created_by character varying(64),
|
||||
expires_at bigint,
|
||||
created_at bigint NOT NULL,
|
||||
updated_at bigint NOT NULL
|
||||
);
|
||||
|
||||
ALTER TABLE ONLY public.redeem_code_batches ADD CONSTRAINT redeem_code_batches_pkey PRIMARY KEY (id);
|
||||
CREATE INDEX IF NOT EXISTS idx_redeem_code_batches_status ON public.redeem_code_batches USING btree (status, created_at);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS public.redeem_codes (
|
||||
id character varying(64) NOT NULL,
|
||||
batch_id character varying(64) NOT NULL,
|
||||
code_hash character varying(128) NOT NULL,
|
||||
code_prefix character varying(16) NOT NULL,
|
||||
code_suffix character varying(16) NOT NULL,
|
||||
status character varying(64) DEFAULT 'active' NOT NULL,
|
||||
redeemed_by_user_id character varying(64),
|
||||
redeemed_wallet_id character varying(64),
|
||||
redeemed_payment_order_id character varying(64),
|
||||
redeemed_at bigint,
|
||||
disabled_by character varying(64),
|
||||
created_at bigint NOT NULL,
|
||||
updated_at bigint NOT NULL
|
||||
);
|
||||
|
||||
ALTER TABLE ONLY public.redeem_codes ADD CONSTRAINT redeem_codes_pkey PRIMARY KEY (id);
|
||||
ALTER TABLE ONLY public.redeem_codes ADD CONSTRAINT uq_redeem_codes_code_hash UNIQUE (code_hash);
|
||||
CREATE INDEX IF NOT EXISTS idx_redeem_codes_batch_created ON public.redeem_codes USING btree (batch_id, created_at);
|
||||
CREATE INDEX IF NOT EXISTS idx_redeem_codes_status ON public.redeem_codes USING btree (status, updated_at);
|
||||
CREATE INDEX IF NOT EXISTS idx_redeem_codes_redeemed_user ON public.redeem_codes USING btree (redeemed_by_user_id, redeemed_at);
|
||||
CREATE INDEX IF NOT EXISTS idx_redeem_codes_redeemed_order ON public.redeem_codes USING btree (redeemed_payment_order_id);
|
||||
|
||||
@@ -0,0 +1,133 @@
|
||||
-- Generated by aether-data-schema from schema/logical/*.toml.
|
||||
-- Do not edit generated files directly; edit logical schema or explicit overrides instead.
|
||||
|
||||
CREATE TABLE IF NOT EXISTS public.usage (
|
||||
request_id character varying(128) NOT NULL,
|
||||
id character varying(128),
|
||||
user_id character varying(64),
|
||||
api_key_id character varying(64),
|
||||
provider_name character varying(255) DEFAULT 'unknown' NOT NULL,
|
||||
model character varying(255) DEFAULT 'unknown' NOT NULL,
|
||||
target_model character varying(255),
|
||||
provider_id character varying(64),
|
||||
provider_endpoint_id character varying(64),
|
||||
provider_api_key_id character varying(64),
|
||||
request_type character varying(64),
|
||||
api_format character varying(64),
|
||||
api_family character varying(64),
|
||||
endpoint_kind character varying(64),
|
||||
endpoint_api_format character varying(64),
|
||||
provider_api_family character varying(64),
|
||||
provider_endpoint_kind character varying(64),
|
||||
has_format_conversion boolean DEFAULT false NOT NULL,
|
||||
is_stream boolean DEFAULT false NOT NULL,
|
||||
input_tokens bigint DEFAULT 0 NOT NULL,
|
||||
output_tokens bigint DEFAULT 0 NOT NULL,
|
||||
input_output_total_tokens bigint DEFAULT 0 NOT NULL,
|
||||
total_tokens bigint DEFAULT 0 NOT NULL,
|
||||
cache_creation_input_tokens bigint DEFAULT 0 NOT NULL,
|
||||
cache_creation_input_tokens_5m bigint DEFAULT 0 NOT NULL,
|
||||
cache_creation_input_tokens_1h bigint DEFAULT 0 NOT NULL,
|
||||
cache_creation_ephemeral_5m_input_tokens bigint DEFAULT 0 NOT NULL,
|
||||
cache_creation_ephemeral_1h_input_tokens bigint DEFAULT 0 NOT NULL,
|
||||
cache_read_input_tokens bigint DEFAULT 0 NOT NULL,
|
||||
input_context_tokens bigint DEFAULT 0 NOT NULL,
|
||||
input_cost_usd double precision DEFAULT 0 NOT NULL,
|
||||
output_cost_usd double precision DEFAULT 0 NOT NULL,
|
||||
cache_cost_usd double precision DEFAULT 0 NOT NULL,
|
||||
cache_creation_cost_usd double precision DEFAULT 0 NOT NULL,
|
||||
cache_creation_cost_usd_5m double precision DEFAULT 0 NOT NULL,
|
||||
cache_creation_cost_usd_1h double precision DEFAULT 0 NOT NULL,
|
||||
cache_read_cost_usd double precision DEFAULT 0 NOT NULL,
|
||||
request_cost_usd double precision DEFAULT 0 NOT NULL,
|
||||
actual_input_cost_usd double precision DEFAULT 0 NOT NULL,
|
||||
actual_output_cost_usd double precision DEFAULT 0 NOT NULL,
|
||||
actual_cache_cost_usd double precision DEFAULT 0 NOT NULL,
|
||||
actual_cache_creation_cost_usd double precision DEFAULT 0 NOT NULL,
|
||||
actual_cache_creation_cost_usd_5m double precision DEFAULT 0 NOT NULL,
|
||||
actual_cache_creation_cost_usd_1h double precision DEFAULT 0 NOT NULL,
|
||||
actual_cache_read_cost_usd double precision DEFAULT 0 NOT NULL,
|
||||
actual_request_cost_usd double precision DEFAULT 0 NOT NULL,
|
||||
rate_multiplier double precision DEFAULT 1 NOT NULL,
|
||||
input_price_per_1m double precision,
|
||||
output_price_per_1m double precision,
|
||||
cache_creation_price_per_1m double precision,
|
||||
cache_creation_price_per_1m_5m double precision,
|
||||
cache_creation_price_per_1m_1h double precision,
|
||||
cache_read_price_per_1m double precision,
|
||||
price_per_request double precision,
|
||||
status_code integer,
|
||||
error_message text,
|
||||
error_category character varying(255),
|
||||
response_time_ms bigint,
|
||||
first_byte_time_ms bigint,
|
||||
wallet_id character varying(64),
|
||||
status character varying(64) DEFAULT 'completed' NOT NULL,
|
||||
billing_status character varying(64) DEFAULT 'pending' NOT NULL,
|
||||
total_cost_usd double precision DEFAULT 0 NOT NULL,
|
||||
actual_total_cost_usd double precision DEFAULT 0 NOT NULL,
|
||||
request_headers jsonb,
|
||||
request_body jsonb,
|
||||
provider_request_headers jsonb,
|
||||
provider_request_body jsonb,
|
||||
response_headers jsonb,
|
||||
response_body jsonb,
|
||||
client_response_headers jsonb,
|
||||
client_response_body jsonb,
|
||||
request_body_compressed bytea,
|
||||
provider_request_body_compressed bytea,
|
||||
response_body_compressed bytea,
|
||||
client_response_body_compressed bytea,
|
||||
request_metadata jsonb,
|
||||
created_at bigint,
|
||||
candidate_id character varying(128),
|
||||
candidate_index bigint,
|
||||
key_name character varying(255),
|
||||
username character varying(255),
|
||||
api_key_name character varying(255),
|
||||
planner_kind character varying(64),
|
||||
route_family character varying(128),
|
||||
route_kind character varying(128),
|
||||
execution_path character varying(128),
|
||||
local_execution_runtime_miss_reason character varying(255),
|
||||
wallet_balance_before double precision,
|
||||
wallet_balance_after double precision,
|
||||
wallet_recharge_balance_before double precision,
|
||||
wallet_recharge_balance_after double precision,
|
||||
wallet_gift_balance_before double precision,
|
||||
wallet_gift_balance_after double precision,
|
||||
finalized_at bigint,
|
||||
created_at_unix_ms bigint DEFAULT 0 NOT NULL,
|
||||
updated_at_unix_secs bigint DEFAULT 0 NOT NULL
|
||||
);
|
||||
|
||||
ALTER TABLE ONLY public.usage ADD CONSTRAINT usage_pkey PRIMARY KEY (request_id);
|
||||
CREATE INDEX IF NOT EXISTS usage_api_key_id_idx ON public.usage USING btree (api_key_id);
|
||||
CREATE INDEX IF NOT EXISTS usage_billing_status_idx ON public.usage USING btree (billing_status);
|
||||
CREATE INDEX IF NOT EXISTS usage_created_at_idx ON public.usage USING btree (created_at_unix_ms);
|
||||
CREATE INDEX IF NOT EXISTS usage_provider_api_key_id_idx ON public.usage USING btree (provider_api_key_id);
|
||||
CREATE INDEX IF NOT EXISTS usage_provider_id_idx ON public.usage USING btree (provider_id);
|
||||
CREATE INDEX IF NOT EXISTS usage_request_id_idx ON public.usage USING btree (request_id);
|
||||
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_settlement_snapshots (
|
||||
request_id character varying(128) NOT NULL,
|
||||
billing_status character varying(64) NOT NULL,
|
||||
wallet_id character varying(64),
|
||||
wallet_balance_before double precision,
|
||||
wallet_balance_after double precision,
|
||||
wallet_recharge_balance_before double precision,
|
||||
wallet_recharge_balance_after double precision,
|
||||
wallet_gift_balance_before double precision,
|
||||
wallet_gift_balance_after double precision,
|
||||
provider_monthly_used_usd double precision,
|
||||
finalized_at bigint,
|
||||
created_at bigint NOT NULL,
|
||||
updated_at bigint NOT NULL
|
||||
);
|
||||
|
||||
ALTER TABLE ONLY public.usage_settlement_snapshots ADD CONSTRAINT usage_settlement_snapshots_pkey PRIMARY KEY (request_id);
|
||||
CREATE INDEX IF NOT EXISTS usage_settlement_snapshots_billing_status_idx ON public.usage_settlement_snapshots USING btree (billing_status);
|
||||
CREATE INDEX IF NOT EXISTS usage_settlement_snapshots_wallet_id_idx ON public.usage_settlement_snapshots USING btree (wallet_id);
|
||||
|
||||
@@ -0,0 +1,249 @@
|
||||
-- Generated by aether-data-schema from schema/logical/*.toml.
|
||||
-- Do not edit generated files directly; edit logical schema or explicit overrides instead.
|
||||
|
||||
CREATE TABLE IF NOT EXISTS public.stats_hourly (
|
||||
id character varying(64) NOT NULL,
|
||||
hour_utc bigint NOT NULL,
|
||||
total_requests bigint DEFAULT 0 NOT NULL,
|
||||
success_requests bigint DEFAULT 0 NOT NULL,
|
||||
error_requests bigint DEFAULT 0 NOT NULL,
|
||||
input_tokens bigint DEFAULT 0 NOT NULL,
|
||||
output_tokens bigint DEFAULT 0 NOT NULL,
|
||||
cache_creation_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,
|
||||
avg_response_time_ms double precision DEFAULT 0 NOT NULL,
|
||||
is_complete boolean DEFAULT false NOT NULL,
|
||||
aggregated_at bigint,
|
||||
created_at bigint NOT NULL,
|
||||
updated_at bigint NOT NULL
|
||||
);
|
||||
|
||||
ALTER TABLE ONLY public.stats_hourly ADD CONSTRAINT stats_hourly_pkey PRIMARY KEY (id);
|
||||
ALTER TABLE ONLY public.stats_hourly ADD CONSTRAINT uq_stats_hourly_hour UNIQUE (hour_utc);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS public.stats_summary (
|
||||
id character varying(64) NOT NULL,
|
||||
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,
|
||||
total_users bigint DEFAULT 0 NOT NULL,
|
||||
active_users bigint DEFAULT 0 NOT NULL,
|
||||
total_api_keys bigint DEFAULT 0 NOT NULL,
|
||||
active_api_keys bigint DEFAULT 0 NOT NULL,
|
||||
created_at bigint NOT NULL,
|
||||
updated_at bigint NOT NULL
|
||||
);
|
||||
|
||||
ALTER TABLE ONLY public.stats_summary ADD CONSTRAINT stats_summary_pkey PRIMARY KEY (id);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS public.stats_hourly_user (
|
||||
id character varying(64) NOT NULL,
|
||||
hour_utc bigint NOT NULL,
|
||||
user_id character varying(64) NOT NULL,
|
||||
total_requests bigint DEFAULT 0 NOT NULL,
|
||||
success_requests bigint DEFAULT 0 NOT NULL,
|
||||
error_requests bigint DEFAULT 0 NOT NULL,
|
||||
input_tokens bigint DEFAULT 0 NOT NULL,
|
||||
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
|
||||
);
|
||||
|
||||
ALTER TABLE ONLY public.stats_hourly_user ADD CONSTRAINT stats_hourly_user_pkey PRIMARY KEY (id);
|
||||
ALTER TABLE ONLY public.stats_hourly_user ADD CONSTRAINT uq_stats_hourly_user UNIQUE (hour_utc, user_id);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS public.stats_hourly_user_model (
|
||||
id character varying(64) NOT NULL,
|
||||
hour_utc bigint NOT NULL,
|
||||
user_id character varying(64) NOT NULL,
|
||||
model character varying(255) NOT NULL,
|
||||
total_requests bigint DEFAULT 0 NOT NULL,
|
||||
input_tokens bigint DEFAULT 0 NOT NULL,
|
||||
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
|
||||
);
|
||||
|
||||
ALTER TABLE ONLY public.stats_hourly_user_model ADD CONSTRAINT stats_hourly_user_model_pkey PRIMARY KEY (id);
|
||||
ALTER TABLE ONLY public.stats_hourly_user_model ADD CONSTRAINT uq_stats_hourly_user_model UNIQUE (hour_utc, user_id, model);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS public.user_model_usage_counts (
|
||||
id character varying(64) NOT NULL,
|
||||
user_id character varying(64) NOT NULL,
|
||||
model character varying(255) NOT NULL,
|
||||
usage_count bigint DEFAULT 0 NOT NULL,
|
||||
created_at bigint NOT NULL,
|
||||
updated_at bigint NOT NULL
|
||||
);
|
||||
|
||||
ALTER TABLE ONLY public.user_model_usage_counts ADD CONSTRAINT user_model_usage_counts_pkey PRIMARY KEY (id);
|
||||
ALTER TABLE ONLY public.user_model_usage_counts ADD CONSTRAINT uq_user_model_usage_count UNIQUE (user_id, model);
|
||||
CREATE INDEX IF NOT EXISTS idx_user_model_usage_user ON public.user_model_usage_counts USING btree (user_id);
|
||||
CREATE INDEX IF NOT EXISTS idx_user_model_usage_model ON public.user_model_usage_counts USING btree (model);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS public.stats_hourly_model (
|
||||
id character varying(64) NOT NULL,
|
||||
hour_utc bigint NOT NULL,
|
||||
model character varying(255) NOT NULL,
|
||||
total_requests bigint DEFAULT 0 NOT NULL,
|
||||
input_tokens bigint DEFAULT 0 NOT NULL,
|
||||
output_tokens bigint DEFAULT 0 NOT NULL,
|
||||
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
|
||||
);
|
||||
|
||||
ALTER TABLE ONLY public.stats_hourly_model ADD CONSTRAINT stats_hourly_model_pkey PRIMARY KEY (id);
|
||||
ALTER TABLE ONLY public.stats_hourly_model ADD CONSTRAINT uq_stats_hourly_model UNIQUE (hour_utc, model);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS public.stats_hourly_provider (
|
||||
id character varying(64) NOT NULL,
|
||||
hour_utc bigint NOT NULL,
|
||||
provider_name character varying(255) NOT NULL,
|
||||
total_requests bigint DEFAULT 0 NOT NULL,
|
||||
input_tokens bigint DEFAULT 0 NOT NULL,
|
||||
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
|
||||
);
|
||||
|
||||
ALTER TABLE ONLY public.stats_hourly_provider ADD CONSTRAINT stats_hourly_provider_pkey PRIMARY KEY (id);
|
||||
ALTER TABLE ONLY public.stats_hourly_provider ADD CONSTRAINT uq_stats_hourly_provider UNIQUE (hour_utc, provider_name);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS public.stats_daily (
|
||||
id character varying(64) NOT NULL,
|
||||
date bigint NOT NULL,
|
||||
total_requests bigint DEFAULT 0 NOT NULL,
|
||||
success_requests bigint DEFAULT 0 NOT NULL,
|
||||
error_requests bigint DEFAULT 0 NOT NULL,
|
||||
input_tokens bigint DEFAULT 0 NOT NULL,
|
||||
output_tokens bigint DEFAULT 0 NOT NULL,
|
||||
cache_creation_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,
|
||||
input_cost double precision DEFAULT 0 NOT NULL,
|
||||
output_cost double precision DEFAULT 0 NOT NULL,
|
||||
cache_creation_cost double precision DEFAULT 0 NOT NULL,
|
||||
cache_read_cost double precision DEFAULT 0 NOT NULL,
|
||||
avg_response_time_ms double precision DEFAULT 0 NOT NULL,
|
||||
fallback_count bigint DEFAULT 0 NOT NULL,
|
||||
unique_models bigint DEFAULT 0 NOT NULL,
|
||||
unique_providers bigint DEFAULT 0 NOT NULL,
|
||||
is_complete boolean DEFAULT false NOT NULL,
|
||||
aggregated_at bigint,
|
||||
created_at bigint NOT NULL,
|
||||
updated_at bigint NOT NULL,
|
||||
p50_response_time_ms bigint,
|
||||
p90_response_time_ms bigint,
|
||||
p99_response_time_ms bigint,
|
||||
p50_first_byte_time_ms bigint,
|
||||
p90_first_byte_time_ms bigint,
|
||||
p99_first_byte_time_ms bigint
|
||||
);
|
||||
|
||||
ALTER TABLE ONLY public.stats_daily ADD CONSTRAINT stats_daily_pkey PRIMARY KEY (id);
|
||||
ALTER TABLE ONLY public.stats_daily ADD CONSTRAINT uq_stats_daily_date UNIQUE (date);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS public.stats_daily_model (
|
||||
id character varying(64) NOT NULL,
|
||||
date bigint NOT NULL,
|
||||
model character varying(255) NOT NULL,
|
||||
total_requests bigint DEFAULT 0 NOT NULL,
|
||||
input_tokens bigint DEFAULT 0 NOT NULL,
|
||||
output_tokens bigint DEFAULT 0 NOT NULL,
|
||||
cache_creation_tokens bigint DEFAULT 0 NOT NULL,
|
||||
cache_read_tokens bigint DEFAULT 0 NOT NULL,
|
||||
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
|
||||
);
|
||||
|
||||
ALTER TABLE ONLY public.stats_daily_model ADD CONSTRAINT stats_daily_model_pkey PRIMARY KEY (id);
|
||||
ALTER TABLE ONLY public.stats_daily_model ADD CONSTRAINT uq_stats_daily_model UNIQUE (date, model);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS public.stats_daily_provider (
|
||||
id character varying(64) NOT NULL,
|
||||
date bigint NOT NULL,
|
||||
provider_name character varying(255) NOT NULL,
|
||||
total_requests bigint DEFAULT 0 NOT NULL,
|
||||
input_tokens bigint DEFAULT 0 NOT NULL,
|
||||
output_tokens bigint DEFAULT 0 NOT NULL,
|
||||
cache_creation_tokens bigint DEFAULT 0 NOT NULL,
|
||||
cache_read_tokens bigint DEFAULT 0 NOT NULL,
|
||||
total_cost double precision DEFAULT 0 NOT NULL,
|
||||
created_at bigint NOT NULL,
|
||||
updated_at bigint NOT NULL
|
||||
);
|
||||
|
||||
ALTER TABLE ONLY public.stats_daily_provider ADD CONSTRAINT stats_daily_provider_pkey PRIMARY KEY (id);
|
||||
ALTER TABLE ONLY public.stats_daily_provider ADD CONSTRAINT uq_stats_daily_provider UNIQUE (date, provider_name);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS public.stats_daily_api_key (
|
||||
id character varying(64) NOT NULL,
|
||||
api_key_id character varying(64) NOT NULL,
|
||||
date bigint NOT NULL,
|
||||
total_requests bigint DEFAULT 0 NOT NULL,
|
||||
success_requests bigint DEFAULT 0 NOT NULL,
|
||||
error_requests bigint DEFAULT 0 NOT NULL,
|
||||
input_tokens bigint DEFAULT 0 NOT NULL,
|
||||
output_tokens bigint DEFAULT 0 NOT NULL,
|
||||
cache_creation_tokens bigint DEFAULT 0 NOT NULL,
|
||||
cache_read_tokens bigint DEFAULT 0 NOT NULL,
|
||||
total_cost double precision DEFAULT 0 NOT NULL,
|
||||
api_key_name character varying(255),
|
||||
created_at bigint NOT NULL,
|
||||
updated_at bigint NOT NULL
|
||||
);
|
||||
|
||||
ALTER TABLE ONLY public.stats_daily_api_key ADD CONSTRAINT stats_daily_api_key_pkey PRIMARY KEY (id);
|
||||
ALTER TABLE ONLY public.stats_daily_api_key ADD CONSTRAINT uq_stats_daily_api_key UNIQUE (date, api_key_id);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS public.stats_daily_error (
|
||||
id character varying(64) NOT NULL,
|
||||
date bigint NOT NULL,
|
||||
error_category character varying(255) NOT NULL,
|
||||
provider_name character varying(255),
|
||||
model character varying(255),
|
||||
count bigint DEFAULT 0 NOT NULL,
|
||||
created_at bigint NOT NULL,
|
||||
updated_at bigint NOT NULL
|
||||
);
|
||||
|
||||
ALTER TABLE ONLY public.stats_daily_error ADD CONSTRAINT stats_daily_error_pkey PRIMARY KEY (id);
|
||||
ALTER TABLE ONLY public.stats_daily_error ADD CONSTRAINT uq_stats_daily_error UNIQUE (date, error_category, provider_name, model);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS public.stats_user_daily (
|
||||
id character varying(64) NOT NULL,
|
||||
user_id character varying(64) NOT NULL,
|
||||
date bigint NOT NULL,
|
||||
total_requests bigint DEFAULT 0 NOT NULL,
|
||||
success_requests bigint DEFAULT 0 NOT NULL,
|
||||
error_requests bigint DEFAULT 0 NOT NULL,
|
||||
input_tokens bigint DEFAULT 0 NOT NULL,
|
||||
output_tokens bigint DEFAULT 0 NOT NULL,
|
||||
cache_creation_tokens bigint DEFAULT 0 NOT NULL,
|
||||
cache_read_tokens bigint DEFAULT 0 NOT NULL,
|
||||
total_cost double precision DEFAULT 0 NOT NULL,
|
||||
username character varying(255),
|
||||
created_at bigint NOT NULL,
|
||||
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);
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
-- Generated by aether-data-schema from schema/logical/*.toml.
|
||||
-- Do not edit generated files directly; edit logical schema or explicit overrides instead.
|
||||
|
||||
001_identity.sql
|
||||
002_provider_catalog.sql
|
||||
003_auth_config.sql
|
||||
004_proxy_nodes.sql
|
||||
005_wallet_billing.sql
|
||||
006_usage.sql
|
||||
007_stats.sql
|
||||
Reference in New Issue
Block a user