fix: 更新数据库脚本添加chat_messages缺失字段 [AC-AISVC-50]
- init_db.sql 添加 prompt_tokens, completion_tokens, total_tokens 等字段 - 新增 migrate_add_columns.sql 用于现有数据库迁移
This commit is contained in:
parent
72700038c6
commit
b11b5a027f
|
|
@ -28,6 +28,13 @@ CREATE TABLE IF NOT EXISTS chat_messages (
|
|||
session_id VARCHAR NOT NULL,
|
||||
role VARCHAR NOT NULL,
|
||||
content TEXT NOT NULL,
|
||||
prompt_tokens INTEGER,
|
||||
completion_tokens INTEGER,
|
||||
total_tokens INTEGER,
|
||||
latency_ms INTEGER,
|
||||
first_token_ms INTEGER,
|
||||
is_error BOOLEAN NOT NULL DEFAULT FALSE,
|
||||
error_message VARCHAR,
|
||||
created_at TIMESTAMP WITHOUT TIME ZONE NOT NULL
|
||||
);
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,29 @@
|
|||
-- Migration: Add missing columns to chat_messages table
|
||||
-- Execute this on existing database to add new columns
|
||||
|
||||
-- Add token tracking columns
|
||||
ALTER TABLE chat_messages ADD COLUMN IF NOT EXISTS prompt_tokens INTEGER;
|
||||
ALTER TABLE chat_messages ADD COLUMN IF NOT EXISTS completion_tokens INTEGER;
|
||||
ALTER TABLE chat_messages ADD COLUMN IF NOT EXISTS total_tokens INTEGER;
|
||||
|
||||
-- Add latency tracking columns
|
||||
ALTER TABLE chat_messages ADD COLUMN IF NOT EXISTS latency_ms INTEGER;
|
||||
ALTER TABLE chat_messages ADD COLUMN IF NOT EXISTS first_token_ms INTEGER;
|
||||
|
||||
-- Add error tracking columns
|
||||
ALTER TABLE chat_messages ADD COLUMN IF NOT EXISTS is_error BOOLEAN NOT NULL DEFAULT FALSE;
|
||||
ALTER TABLE chat_messages ADD COLUMN IF NOT EXISTS error_message VARCHAR;
|
||||
|
||||
-- Create API Keys table if not exists
|
||||
CREATE TABLE IF NOT EXISTS api_keys (
|
||||
id UUID NOT NULL PRIMARY KEY,
|
||||
key VARCHAR NOT NULL UNIQUE,
|
||||
name VARCHAR NOT NULL,
|
||||
is_active BOOLEAN NOT NULL DEFAULT TRUE,
|
||||
created_at TIMESTAMP WITHOUT TIME ZONE NOT NULL,
|
||||
updated_at TIMESTAMP WITHOUT TIME ZONE NOT NULL
|
||||
);
|
||||
|
||||
-- Create API Keys indexes
|
||||
CREATE INDEX IF NOT EXISTS ix_api_keys_key ON api_keys (key);
|
||||
CREATE INDEX IF NOT EXISTS ix_api_keys_is_active ON api_keys (is_active);
|
||||
Loading…
Reference in New Issue