mirror of
https://github.com/fawney19/Aether.git
synced 2026-09-03 01:40:21 +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,177 @@
|
||||
CREATE TABLE IF NOT EXISTS stats_hourly (
|
||||
id VARCHAR(64) PRIMARY KEY,
|
||||
hour_utc BIGINT NOT NULL,
|
||||
total_requests BIGINT NOT NULL DEFAULT 0,
|
||||
success_requests BIGINT NOT NULL DEFAULT 0,
|
||||
error_requests BIGINT NOT NULL DEFAULT 0,
|
||||
input_tokens BIGINT NOT NULL DEFAULT 0,
|
||||
output_tokens BIGINT NOT NULL DEFAULT 0,
|
||||
cache_creation_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,
|
||||
avg_response_time_ms DOUBLE NOT NULL DEFAULT 0,
|
||||
is_complete TINYINT(1) NOT NULL DEFAULT 0,
|
||||
aggregated_at BIGINT,
|
||||
created_at BIGINT NOT NULL,
|
||||
updated_at BIGINT NOT NULL,
|
||||
UNIQUE KEY uq_stats_hourly_hour (hour_utc)
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS stats_hourly_user (
|
||||
id VARCHAR(64) PRIMARY KEY,
|
||||
hour_utc BIGINT NOT NULL,
|
||||
user_id VARCHAR(64) NOT NULL,
|
||||
total_requests BIGINT NOT NULL DEFAULT 0,
|
||||
success_requests BIGINT NOT NULL DEFAULT 0,
|
||||
error_requests BIGINT NOT NULL DEFAULT 0,
|
||||
input_tokens BIGINT NOT NULL DEFAULT 0,
|
||||
output_tokens BIGINT NOT NULL DEFAULT 0,
|
||||
total_cost DOUBLE NOT NULL DEFAULT 0,
|
||||
created_at BIGINT NOT NULL,
|
||||
updated_at BIGINT NOT NULL,
|
||||
UNIQUE KEY uq_stats_hourly_user (hour_utc, user_id)
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS stats_hourly_user_model (
|
||||
id VARCHAR(64) PRIMARY KEY,
|
||||
hour_utc BIGINT NOT NULL,
|
||||
user_id VARCHAR(64) NOT NULL,
|
||||
model VARCHAR(255) NOT NULL,
|
||||
total_requests BIGINT NOT NULL DEFAULT 0,
|
||||
input_tokens BIGINT NOT NULL DEFAULT 0,
|
||||
output_tokens BIGINT NOT NULL DEFAULT 0,
|
||||
total_cost DOUBLE NOT NULL DEFAULT 0,
|
||||
created_at BIGINT NOT NULL,
|
||||
updated_at BIGINT NOT NULL,
|
||||
UNIQUE KEY uq_stats_hourly_user_model (hour_utc, user_id, model)
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS stats_hourly_model (
|
||||
id VARCHAR(64) PRIMARY KEY,
|
||||
hour_utc BIGINT NOT NULL,
|
||||
model VARCHAR(255) NOT NULL,
|
||||
total_requests BIGINT NOT NULL DEFAULT 0,
|
||||
input_tokens BIGINT NOT NULL DEFAULT 0,
|
||||
output_tokens BIGINT NOT NULL DEFAULT 0,
|
||||
total_cost DOUBLE NOT NULL DEFAULT 0,
|
||||
avg_response_time_ms DOUBLE NOT NULL DEFAULT 0,
|
||||
created_at BIGINT NOT NULL,
|
||||
updated_at BIGINT NOT NULL,
|
||||
UNIQUE KEY uq_stats_hourly_model (hour_utc, model)
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS stats_hourly_provider (
|
||||
id VARCHAR(64) PRIMARY KEY,
|
||||
hour_utc BIGINT NOT NULL,
|
||||
provider_name VARCHAR(255) NOT NULL,
|
||||
total_requests BIGINT NOT NULL DEFAULT 0,
|
||||
input_tokens BIGINT NOT NULL DEFAULT 0,
|
||||
output_tokens BIGINT NOT NULL DEFAULT 0,
|
||||
total_cost DOUBLE NOT NULL DEFAULT 0,
|
||||
created_at BIGINT NOT NULL,
|
||||
updated_at BIGINT NOT NULL,
|
||||
UNIQUE KEY uq_stats_hourly_provider (hour_utc, provider_name)
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS stats_daily (
|
||||
id VARCHAR(64) PRIMARY KEY,
|
||||
`date` BIGINT NOT NULL,
|
||||
total_requests BIGINT NOT NULL DEFAULT 0,
|
||||
success_requests BIGINT NOT NULL DEFAULT 0,
|
||||
error_requests BIGINT NOT NULL DEFAULT 0,
|
||||
input_tokens BIGINT NOT NULL DEFAULT 0,
|
||||
output_tokens BIGINT NOT NULL DEFAULT 0,
|
||||
cache_creation_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,
|
||||
avg_response_time_ms DOUBLE NOT NULL DEFAULT 0,
|
||||
fallback_count BIGINT NOT NULL DEFAULT 0,
|
||||
unique_models BIGINT NOT NULL DEFAULT 0,
|
||||
unique_providers BIGINT NOT NULL DEFAULT 0,
|
||||
is_complete TINYINT(1) NOT NULL DEFAULT 0,
|
||||
aggregated_at BIGINT,
|
||||
created_at BIGINT NOT NULL,
|
||||
updated_at BIGINT NOT NULL,
|
||||
UNIQUE KEY uq_stats_daily_date (`date`)
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS stats_daily_model (
|
||||
id VARCHAR(64) PRIMARY KEY,
|
||||
`date` BIGINT NOT NULL,
|
||||
model VARCHAR(255) NOT NULL,
|
||||
total_requests BIGINT NOT NULL DEFAULT 0,
|
||||
input_tokens BIGINT NOT NULL DEFAULT 0,
|
||||
output_tokens BIGINT NOT NULL DEFAULT 0,
|
||||
cache_creation_tokens BIGINT NOT NULL DEFAULT 0,
|
||||
cache_read_tokens BIGINT NOT NULL DEFAULT 0,
|
||||
total_cost DOUBLE NOT NULL DEFAULT 0,
|
||||
avg_response_time_ms DOUBLE NOT NULL DEFAULT 0,
|
||||
created_at BIGINT NOT NULL,
|
||||
updated_at BIGINT NOT NULL,
|
||||
UNIQUE KEY uq_stats_daily_model (`date`, model)
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS stats_daily_provider (
|
||||
id VARCHAR(64) PRIMARY KEY,
|
||||
`date` BIGINT NOT NULL,
|
||||
provider_name VARCHAR(255) NOT NULL,
|
||||
total_requests BIGINT NOT NULL DEFAULT 0,
|
||||
input_tokens BIGINT NOT NULL DEFAULT 0,
|
||||
output_tokens BIGINT NOT NULL DEFAULT 0,
|
||||
cache_creation_tokens BIGINT NOT NULL DEFAULT 0,
|
||||
cache_read_tokens BIGINT NOT NULL DEFAULT 0,
|
||||
total_cost DOUBLE NOT NULL DEFAULT 0,
|
||||
created_at BIGINT NOT NULL,
|
||||
updated_at BIGINT NOT NULL,
|
||||
UNIQUE KEY uq_stats_daily_provider (`date`, provider_name)
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS stats_daily_api_key (
|
||||
id VARCHAR(64) PRIMARY KEY,
|
||||
api_key_id VARCHAR(64) NOT NULL,
|
||||
`date` BIGINT NOT NULL,
|
||||
total_requests BIGINT NOT NULL DEFAULT 0,
|
||||
success_requests BIGINT NOT NULL DEFAULT 0,
|
||||
error_requests BIGINT NOT NULL DEFAULT 0,
|
||||
input_tokens BIGINT NOT NULL DEFAULT 0,
|
||||
output_tokens BIGINT NOT NULL DEFAULT 0,
|
||||
cache_creation_tokens BIGINT NOT NULL DEFAULT 0,
|
||||
cache_read_tokens BIGINT NOT NULL DEFAULT 0,
|
||||
total_cost DOUBLE NOT NULL DEFAULT 0,
|
||||
api_key_name VARCHAR(255),
|
||||
created_at BIGINT NOT NULL,
|
||||
updated_at BIGINT NOT NULL,
|
||||
UNIQUE KEY uq_stats_daily_api_key (`date`, api_key_id)
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS stats_daily_error (
|
||||
id VARCHAR(64) PRIMARY KEY,
|
||||
`date` BIGINT NOT NULL,
|
||||
error_category VARCHAR(255) NOT NULL,
|
||||
provider_name VARCHAR(255),
|
||||
model VARCHAR(255),
|
||||
count BIGINT NOT NULL DEFAULT 0,
|
||||
created_at BIGINT NOT NULL,
|
||||
updated_at BIGINT NOT NULL,
|
||||
UNIQUE KEY uq_stats_daily_error (`date`, error_category, provider_name, model)
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS stats_user_daily (
|
||||
id VARCHAR(64) PRIMARY KEY,
|
||||
user_id VARCHAR(64) NOT NULL,
|
||||
`date` BIGINT NOT NULL,
|
||||
total_requests BIGINT NOT NULL DEFAULT 0,
|
||||
success_requests BIGINT NOT NULL DEFAULT 0,
|
||||
error_requests BIGINT NOT NULL DEFAULT 0,
|
||||
input_tokens BIGINT NOT NULL DEFAULT 0,
|
||||
output_tokens BIGINT NOT NULL DEFAULT 0,
|
||||
cache_creation_tokens BIGINT NOT NULL DEFAULT 0,
|
||||
cache_read_tokens BIGINT NOT NULL DEFAULT 0,
|
||||
total_cost DOUBLE NOT NULL DEFAULT 0,
|
||||
username VARCHAR(255),
|
||||
created_at BIGINT NOT NULL,
|
||||
updated_at BIGINT NOT NULL,
|
||||
UNIQUE KEY uq_stats_user_daily (`date`, user_id)
|
||||
);
|
||||
Reference in New Issue
Block a user