/** * Lets a chat message reply to another, through `chat_messages.reply_to_id`. * The column has no foreign key on purpose: when the replied-to message is * deleted, the id stays and chat-service's join reads null, so the chat shows * "deleted message" where the quote was. * * @module */ import type { DatabaseSync } from "node:sqlite"; /** * Run once by `runMigrations`. Existing messages reply to nothing, and a * database made from schema.sql already has the column. */ 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;`); } }