All checks were successful
Build and Publish Docker Image / build-and-push (push) Successful in 41s
18 lines
732 B
TypeScript
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;`);
|
|
}
|
|
}
|