fix(snippets): repair missing note column on SQLite upgrades (#1541)

This commit is contained in:
ZacharyZcR authored and GitHub committed 2026-10-03 21:02:04 +08:00
1 parent d3568e484d
commit 117e125d55
3 files changed
+78

No files matched your search

@@ -0,0 +1,19 @@
import type Database from "better-sqlite3";
/** Repair older SQLite tables before adoption, or after an incomplete 2.9 upgrade. */
export function repairSnippetsNoteColumn(sqlite: Database.Database): void {
for (const table of ["snippets", "p_snippets_snippets"]) {
const columns = sqlite.pragma(`table_info("${table}")`) as Array<{
name: string;
}>;
if (
columns.length === 0 ||
columns.some(({ name }) => name === "is_note")
) {
continue;
}
sqlite.exec(
`ALTER TABLE "${table}" ADD COLUMN "is_note" INTEGER NOT NULL DEFAULT 0`,
);
}
}