From 7be8b6c71e8c11f99d5993440cad1a6751652dfc Mon Sep 17 00:00:00 2001 From: perfectra1n Date: Fri, 28 Nov 2025 21:27:01 -0800 Subject: [PATCH] fix(fts): merge the two migrations into one file --- .../src/migrations/0234__add_fts5_search.ts | 17 +++++++ .../migrations/0236__cleanup_sqlite_search.ts | 47 ------------------- apps/server/src/services/app_info.ts | 2 +- 3 files changed, 18 insertions(+), 48 deletions(-) delete mode 100644 apps/server/src/migrations/0236__cleanup_sqlite_search.ts diff --git a/apps/server/src/migrations/0234__add_fts5_search.ts b/apps/server/src/migrations/0234__add_fts5_search.ts index 113257937..71d6ef17f 100644 --- a/apps/server/src/migrations/0234__add_fts5_search.ts +++ b/apps/server/src/migrations/0234__add_fts5_search.ts @@ -631,5 +631,22 @@ export default function addFTS5SearchAndPerformanceIndexes() { log.info("Attributes FTS5 setup completed successfully"); }); + // ======================================== + // Part 4: Cleanup legacy custom search tables + // ======================================== + // Remove tables from previous custom SQLite search implementation + // that has been replaced by FTS5 + + log.info("Cleaning up legacy custom search tables..."); + + sql.executeScript(`DROP TABLE IF EXISTS note_search_content`); + sql.executeScript(`DROP TABLE IF EXISTS note_tokens`); + + // Clean up any entity changes for these tables + sql.execute(` + DELETE FROM entity_changes + WHERE entityName IN ('note_search_content', 'note_tokens') + `); + log.info("FTS5 and performance optimization migration completed successfully"); } \ No newline at end of file diff --git a/apps/server/src/migrations/0236__cleanup_sqlite_search.ts b/apps/server/src/migrations/0236__cleanup_sqlite_search.ts deleted file mode 100644 index 933e33d50..000000000 --- a/apps/server/src/migrations/0236__cleanup_sqlite_search.ts +++ /dev/null @@ -1,47 +0,0 @@ -/** - * Migration to clean up custom SQLite search implementation - * - * This migration removes tables and triggers created by migration 0235 - * which implemented a custom SQLite-based search system. That system - * has been replaced by FTS5 with trigram tokenizer (migration 0234), - * making these custom tables redundant. - * - * Tables removed: - * - note_search_content: Stored normalized note content for custom search - * - note_tokens: Stored tokenized words for custom token-based search - * - * This migration is safe to run on databases that: - * 1. Never ran migration 0235 (tables don't exist) - * 2. Already ran migration 0235 (tables will be dropped) - */ - -import sql from "../services/sql.js"; -import log from "../services/log.js"; - -export default function cleanupSqliteSearch() { - log.info("Starting SQLite custom search cleanup migration..."); - - try { - sql.transactional(() => { - // Drop custom search tables if they exist - log.info("Dropping note_search_content table..."); - sql.executeScript(`DROP TABLE IF EXISTS note_search_content`); - - log.info("Dropping note_tokens table..."); - sql.executeScript(`DROP TABLE IF EXISTS note_tokens`); - - // Clean up any entity changes for these tables - // This prevents sync issues and cleans up change tracking - log.info("Cleaning up entity changes for removed tables..."); - sql.execute(` - DELETE FROM entity_changes - WHERE entityName IN ('note_search_content', 'note_tokens') - `); - - log.info("SQLite custom search cleanup completed successfully"); - }); - } catch (error) { - log.error(`Error during SQLite search cleanup: ${error}`); - throw new Error(`Failed to clean up SQLite search tables: ${error}`); - } -} diff --git a/apps/server/src/services/app_info.ts b/apps/server/src/services/app_info.ts index 904afcf51..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 = 236; +const APP_DB_VERSION = 234; const SYNC_VERSION = 36; const CLIPPER_PROTOCOL_VERSION = "1.0";