Files
growqr-backend/src/actors/conversation/migrations.ts
2026-06-02 19:08:31 +05:30

43 lines
1.5 KiB
TypeScript

import type { RawAccess } from "rivetkit/db";
// Tiny inline migration for the actor-local SQLite database. This keeps the
// example self-contained and avoids wiring drizzle-kit output into the app yet.
export async function migrateConversationDb(db: RawAccess) {
await db.execute(`
CREATE TABLE IF NOT EXISTS conversation_messages (
id TEXT PRIMARY KEY NOT NULL,
conversation_id TEXT NOT NULL,
role TEXT NOT NULL CHECK (role IN ('user', 'assistant')),
sender TEXT NOT NULL,
content TEXT NOT NULL,
created_at INTEGER NOT NULL
);
CREATE INDEX IF NOT EXISTS conversation_messages_conversation_created_at_idx
ON conversation_messages (conversation_id, created_at);
CREATE TABLE IF NOT EXISTS conversation_tool_calls (
id TEXT PRIMARY KEY NOT NULL,
conversation_id TEXT NOT NULL,
message_id TEXT NOT NULL REFERENCES conversation_messages(id) ON DELETE CASCADE,
tool_name TEXT NOT NULL,
args_json TEXT,
result_json TEXT,
status TEXT NOT NULL DEFAULT 'running' CHECK (status IN ('running', 'done', 'error')),
created_at INTEGER NOT NULL,
finished_at INTEGER
);
CREATE INDEX IF NOT EXISTS conversation_tool_calls_conversation_idx
ON conversation_tool_calls (conversation_id, created_at);
CREATE TABLE IF NOT EXISTS conversation_summaries (
id TEXT PRIMARY KEY NOT NULL,
conversation_id TEXT NOT NULL,
content_md TEXT NOT NULL,
created_at INTEGER NOT NULL,
updated_at INTEGER NOT NULL
);
`);
}