gitdataai/libs/migrate/sql/m20260508_000005_create_ai_token_usage.sql

15 lines
566 B
SQL

CREATE TABLE IF NOT EXISTS ai_token_usage (
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
user_id UUID NOT NULL,
conversation_id UUID,
model VARCHAR(128) NOT NULL,
input_tokens INT NOT NULL,
output_tokens INT NOT NULL,
cost_usd NUMERIC(10, 6),
recorded_at TIMESTAMPTZ NOT NULL DEFAULT NOW()
);
CREATE INDEX IF NOT EXISTS idx_ai_token_user ON ai_token_usage (user_id);
CREATE INDEX IF NOT EXISTS idx_ai_token_conv ON ai_token_usage (conversation_id);
CREATE INDEX IF NOT EXISTS idx_ai_token_recorded ON ai_token_usage (recorded_at);