Add conversation pkg
This commit is contained in:
@@ -53,15 +53,16 @@ CREATE TABLE IF NOT EXISTS conversations (
|
||||
CREATE INDEX IF NOT EXISTS idx_conv_user ON conversations(user_id);
|
||||
|
||||
-- Messages are ordered entries within a conversation. The content column
|
||||
-- stores the wire-format JSON for the message — the exact JSON object
|
||||
-- that appears in the OpenAI Chat Completions messages array. The role
|
||||
-- column is extracted for querying without JSON parsing. Nullable metadata
|
||||
-- stores inference JSONB separately from model-visible content. The sequence
|
||||
-- column defines ordering within the conversation. Deleting a message
|
||||
-- cascades to nothing further (all message data is in the row).
|
||||
-- stores the wire-format JSON for the message — the exact JSON object that
|
||||
-- appears in the OpenAI Chat Completions messages array; a CHECK constraint
|
||||
-- keeps it valid JSON. The role column is extracted for querying without
|
||||
-- JSON parsing. Nullable metadata stores inference JSONB separately from
|
||||
-- model-visible content. The sequence column defines ordering within the
|
||||
-- conversation. Deleting a message cascades to nothing further (all message
|
||||
-- data is in the row).
|
||||
CREATE TABLE IF NOT EXISTS messages (
|
||||
conversation_id TEXT NOT NULL REFERENCES conversations(id) ON DELETE CASCADE,
|
||||
content TEXT NOT NULL,
|
||||
content TEXT NOT NULL CHECK (json_valid(content)),
|
||||
created_at TEXT NOT NULL DEFAULT (strftime('%Y-%m-%dT%H:%M:%fZ', 'now')),
|
||||
id TEXT PRIMARY KEY,
|
||||
metadata BLOB CHECK (metadata IS NULL OR json_valid(metadata, 8)),
|
||||
|
||||
Reference in New Issue
Block a user