feat(key-pool): add LRU sorting via last_used_at column

- Add migration to add last_used_at TIMESTAMPTZ column to provider_keys
- Update select_best_key() SQL to sort by last_used_at ASC NULLS FIRST
- Update record_key_usage() to set last_used_at = NOW() on each use
- Bump SCHEMA_VERSION to 10
This commit is contained in:
iven
2026-03-31 10:14:49 +08:00
parent 1d9283f335
commit 8e6abc91e1
3 changed files with 11 additions and 2 deletions

View File

@@ -0,0 +1,3 @@
-- 20260401000001_provider_keys_last_used.sql
-- Key Pool LRU: 记录每个 key 最后使用时间
ALTER TABLE provider_keys ADD COLUMN IF NOT EXISTS last_used_at TIMESTAMPTZ;