Files
gerbeur/api/db/migrations/0009_chat_reply.ts
2026-06-30 12:27:03 +02:00

18 lines
732 B
TypeScript

import type { DatabaseSync } from "node:sqlite";
// Adds an optional self-reference so a chat message can reply to another.
// Kept as a plain column (no FK): when the replied-to message is later deleted
// the id is retained but the join yields null, letting the UI show a subtle
// "deleted message" reference instead of breaking the insert.
//
// Idempotent: also runs against fresh databases created from schema.sql, where
// the column already exists.
export function up(db: DatabaseSync): void {
const cols = db.prepare(`PRAGMA table_info(chat_messages);`).all() as {
name: string;
}[];
if (!cols.some((c) => c.name === "reply_to_id")) {
db.exec(`ALTER TABLE chat_messages ADD COLUMN reply_to_id TEXT;`);
}
}