diff --git a/apps/server/src/migrations/0234__migrate_open_note_contexts_format.ts b/apps/server/src/migrations/0234__migrate_open_note_contexts_format.ts new file mode 100644 index 000000000..72b09ed2a --- /dev/null +++ b/apps/server/src/migrations/0234__migrate_open_note_contexts_format.ts @@ -0,0 +1,42 @@ +import cls from "../services/cls.js"; +import sql from "../services/sql.js"; + +export default () => { + cls.init(() => { + const row = sql.getRow<{ value: string }>( + `SELECT value FROM options WHERE name = 'openNoteContexts'` + ); + + if (!row || !row.value) { + return; + } + + let parsed: any; + try { + parsed = JSON.parse(row.value); + } catch { + return; + } + + // Already in new format, skip + if (parsed[0].windowId) { + return; + } + + // Old format: just contexts + const migrated = [ + { + windowId: "main", + createdAt: 0, + closedAt: null, + contexts: parsed + } + ]; + + sql.execute( + `UPDATE options SET value = ? WHERE name = 'openNoteContexts'`, + [JSON.stringify(migrated)] + ); + + }); +}; diff --git a/apps/server/src/migrations/migrations.ts b/apps/server/src/migrations/migrations.ts index 2757b4c25..0f7f6e40d 100644 --- a/apps/server/src/migrations/migrations.ts +++ b/apps/server/src/migrations/migrations.ts @@ -6,6 +6,11 @@ // Migrations should be kept in descending order, so the latest migration is first. const MIGRATIONS: (SqlMigration | JsMigration)[] = [ + // Migrate openNoteContexts option to the new structured format with window metadata + { + version: 234, + module: async () => import("./0234__migrate_open_note_contexts_format") + }, // Migrate geo map to collection { version: 233, diff --git a/apps/server/src/services/app_info.ts b/apps/server/src/services/app_info.ts index 2837e8de7..002f9c43b 100644 --- a/apps/server/src/services/app_info.ts +++ b/apps/server/src/services/app_info.ts @@ -4,7 +4,7 @@ import packageJson from "../../package.json" with { type: "json" }; import dataDir from "./data_dir.js"; import { AppInfo } from "@triliumnext/commons"; -const APP_DB_VERSION = 233; +const APP_DB_VERSION = 234; const SYNC_VERSION = 36; const CLIPPER_PROTOCOL_VERSION = "1.0";