fix(gateway): 避免SSE delta将缓存创建明细重置为0
- 仅在 delta 中 5m/1h 值大于0时覆盖 usage 明细 - 新增回归测试覆盖 delta 默认 0 不应覆盖 message_start 非零值 - 迁移 054 在删除 legacy 字段前追加一次回填,避免升级实例丢失历史写入 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -8,7 +8,37 @@
|
||||
-- cache_creation_1h_tokens (defined in 001_init.sql)
|
||||
--
|
||||
-- Migration 009 already copied data from legacy → canonical columns.
|
||||
-- This migration drops the legacy columns to avoid confusion.
|
||||
-- But upgraded instances may still have post-009 writes in legacy columns.
|
||||
-- Backfill once more before dropping to prevent data loss.
|
||||
|
||||
DO $$
|
||||
BEGIN
|
||||
IF EXISTS (
|
||||
SELECT 1
|
||||
FROM information_schema.columns
|
||||
WHERE table_schema = 'public'
|
||||
AND table_name = 'usage_logs'
|
||||
AND column_name = 'cache_creation5m_tokens'
|
||||
) THEN
|
||||
UPDATE usage_logs
|
||||
SET cache_creation_5m_tokens = cache_creation5m_tokens
|
||||
WHERE cache_creation_5m_tokens = 0
|
||||
AND cache_creation5m_tokens <> 0;
|
||||
END IF;
|
||||
|
||||
IF EXISTS (
|
||||
SELECT 1
|
||||
FROM information_schema.columns
|
||||
WHERE table_schema = 'public'
|
||||
AND table_name = 'usage_logs'
|
||||
AND column_name = 'cache_creation1h_tokens'
|
||||
) THEN
|
||||
UPDATE usage_logs
|
||||
SET cache_creation_1h_tokens = cache_creation1h_tokens
|
||||
WHERE cache_creation_1h_tokens = 0
|
||||
AND cache_creation1h_tokens <> 0;
|
||||
END IF;
|
||||
END $$;
|
||||
|
||||
ALTER TABLE usage_logs DROP COLUMN IF EXISTS cache_creation5m_tokens;
|
||||
ALTER TABLE usage_logs DROP COLUMN IF EXISTS cache_creation1h_tokens;
|
||||
|
||||
Reference in New Issue
Block a user