gitdataai/libs/migrate/sql/m20260508_000002_create_ai_message.sql
ZhenYi b1ef024724 fix(migrate): reorder create_project before add_workspace_id_to_project and remove foreign keys
- Move create_project migration before add_workspace_id_to_project so the
  project table exists when workspace_id column is added
- Remove all FOREIGN KEY constraints from migration SQL files
2026-05-11 01:31:33 +08:00

20 lines
642 B
SQL

CREATE TABLE IF NOT EXISTS ai_message (
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
conversation_id UUID NOT NULL,
parent_message_id UUID,
role VARCHAR(16) NOT NULL,
content JSONB NOT NULL,
model VARCHAR(128),
is_fork_origin BOOLEAN NOT NULL DEFAULT false,
stop_reason VARCHAR(32),
input_tokens INT,
output_tokens INT,
latency_ms INT,
metadata JSONB,
room_id UUID,
created_at TIMESTAMPTZ NOT NULL DEFAULT NOW()
);
CREATE INDEX IF NOT EXISTS idx_ai_msg_conv ON ai_message (conversation_id, created_at);
CREATE INDEX IF NOT EXISTS idx_ai_msg_parent ON ai_message (parent_message_id);