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:
fawney19
2026-05-05 18:27:36 +08:00
parent 099653f732
commit fce7e959e5
372 changed files with 86217 additions and 21160 deletions

View File

@@ -0,0 +1,38 @@
UPDATE public.api_keys
SET
total_requests = 0,
total_tokens = 0,
total_cost_usd = 0,
last_used_at = NULL;
WITH aggregated AS (
SELECT
usage.api_key_id,
COUNT(*)::INTEGER AS total_requests,
COALESCE(
SUM(
GREATEST(
COALESCE(
usage.total_tokens,
COALESCE(usage.input_tokens, 0) + COALESCE(usage.output_tokens, 0)
),
0
)::BIGINT
),
0
)::BIGINT AS total_tokens,
COALESCE(SUM(COALESCE(usage.total_cost_usd, 0)), 0)::NUMERIC(20,8) AS total_cost_usd,
MAX(usage.created_at) AS last_used_at
FROM public.usage
WHERE usage.api_key_id IS NOT NULL
AND BTRIM(usage.api_key_id) <> ''
GROUP BY usage.api_key_id
)
UPDATE public.api_keys
SET
total_requests = aggregated.total_requests,
total_tokens = aggregated.total_tokens,
total_cost_usd = aggregated.total_cost_usd,
last_used_at = aggregated.last_used_at
FROM aggregated
WHERE public.api_keys.id = aggregated.api_key_id;