diff --git a/apps/server/src/migrations/0233__migrate_geo_map_to_collection.ts b/apps/server/src/migrations/0233__migrate_geo_map_to_collection.ts new file mode 100644 index 000000000..b0f49144c --- /dev/null +++ b/apps/server/src/migrations/0233__migrate_geo_map_to_collection.ts @@ -0,0 +1,47 @@ +import type { AttachmentRow } from "@triliumnext/commons"; +import becca from "../becca/becca"; +import becca_loader from "../becca/becca_loader"; +import cls from "../services/cls.js"; +import hidden_subtree from "../services/hidden_subtree"; + +export default () => { + cls.init(() => { + becca_loader.load(); + + // Ensure the geomap template is generated. + hidden_subtree.checkHiddenSubtree(true); + + for (const note of Object.values(becca.notes)) { + if (note.type !== "geoMap") { + continue; + } + + console.log(`Migrating note '${note.noteId}' from geoMap to book type...`); + + note.type = "book"; + note.mime = ""; + note.save(); + + const content = note.getContent(); + if (content) { + const title = "geoMap.json"; + const existingAttachment = note.getAttachmentsByRole("viewConfig") + .filter(a => a.title === title)[0]; + if (existingAttachment) { + existingAttachment.setContent(content); + } else { + note.saveAttachment({ + role: "viewConfig", + title, + mime: "application/json", + content, + position: 0 + }); + } + + } + note.setContent(""); + note.setRelation("template", "_template_geo_map"); + } + }); +}; diff --git a/apps/server/src/migrations/migrations.ts b/apps/server/src/migrations/migrations.ts index 4743d9286..2757b4c25 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 geo map to collection + { + version: 233, + module: async () => import("./0233__migrate_geo_map_to_collection.js") + }, // Remove embedding tables since LLM embedding functionality has been removed { version: 232, diff --git a/apps/server/src/services/app_info.ts b/apps/server/src/services/app_info.ts index b3da2ac0e..0def56253 100644 --- a/apps/server/src/services/app_info.ts +++ b/apps/server/src/services/app_info.ts @@ -3,7 +3,7 @@ import build from "./build.js"; import packageJson from "../../package.json" with { type: "json" }; import dataDir from "./data_dir.js"; -const APP_DB_VERSION = 232; +const APP_DB_VERSION = 233; const SYNC_VERSION = 36; const CLIPPER_PROTOCOL_VERSION = "1.0";