24 lines
794 B
TypeScript
24 lines
794 B
TypeScript
/**
|
|
* 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.
|
|
*
|
|
* @module
|
|
*/
|
|
|
|
import type { DatabaseSync } from "node:sqlite";
|
|
|
|
/** Applies this migration to `db`. */
|
|
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;`);
|
|
}
|
|
}
|