Add chat_comments table to PGlite schema and thread_id to types

This commit is contained in:
CREDO23 2026-01-22 17:56:45 +02:00
parent ac7d84571d
commit 4b57ba9d2b
2 changed files with 19 additions and 0 deletions

View file

@ -6,6 +6,7 @@ import { z } from "zod";
export const rawComment = z.object({
id: z.number(),
message_id: z.number(),
thread_id: z.number(), // Denormalized for efficient Electric subscriptions
parent_id: z.number().nullable(),
author_id: z.string().nullable(),
content: z.string(),

View file

@ -240,6 +240,24 @@ export async function initElectric(userId: string): Promise<ElectricClient> {
CREATE INDEX IF NOT EXISTS idx_chat_comment_mentions_comment_id ON chat_comment_mentions(comment_id);
`);
// Create chat_comments table for live comment sync
await db.exec(`
CREATE TABLE IF NOT EXISTS chat_comments (
id INTEGER PRIMARY KEY,
message_id INTEGER NOT NULL,
thread_id INTEGER NOT NULL,
parent_id INTEGER,
author_id TEXT,
content TEXT NOT NULL,
created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
updated_at TIMESTAMPTZ NOT NULL DEFAULT NOW()
);
CREATE INDEX IF NOT EXISTS idx_chat_comments_thread_id ON chat_comments(thread_id);
CREATE INDEX IF NOT EXISTS idx_chat_comments_message_id ON chat_comments(message_id);
CREATE INDEX IF NOT EXISTS idx_chat_comments_parent_id ON chat_comments(parent_id);
`);
const electricUrl = getElectricUrl();
// STEP 4: Create the client wrapper