From 6216c06153394014cac017a4f9758fce39c3686e Mon Sep 17 00:00:00 2001 From: Dallin Romney Date: Tue, 7 Jan 2025 01:33:01 +0100 Subject: [PATCH 1/3] split up docs sqlite migrations --- core/indexing/docs/DocsService.ts | 19 +++++++++++++++++-- core/indexing/docs/migrations.ts | 24 ++++++++++++++++++++++-- 2 files changed, 39 insertions(+), 4 deletions(-) diff --git a/core/indexing/docs/DocsService.ts b/core/indexing/docs/DocsService.ts index 1696466dc..1f56de495 100644 --- a/core/indexing/docs/DocsService.ts +++ b/core/indexing/docs/DocsService.ts @@ -743,10 +743,17 @@ export default class DocsService { } async getFavicon(startUrl: string) { + if (!this.config.embeddingsProvider) { + console.warn( + "Attempting to get favicon without embeddings provider specified", + ); + return; + } const db = await this.getOrCreateSqliteDb(); const result = await db.get( - `SELECT favicon FROM ${DocsService.sqlitebTableName} WHERE startUrl = ?`, + `SELECT favicon FROM ${DocsService.sqlitebTableName} WHERE startUrl = ? AND embeddingsProviderId = ?`, startUrl, + this.config.embeddingsProvider.embeddingId, ); if (!result) { @@ -1011,10 +1018,18 @@ export default class DocsService { } private async deleteMetadataFromSqlite(startUrl: string) { + if (!this.config.embeddingsProvider) { + console.warn( + `Attempting to delete metadata for ${startUrl} without embeddings provider specified`, + ); + return; + } const db = await this.getOrCreateSqliteDb(); + await db.run( - `DELETE FROM ${DocsService.sqlitebTableName} WHERE startUrl = ?`, + `DELETE FROM ${DocsService.sqlitebTableName} WHERE startUrl = ? AND embeddingsProviderId = ?`, startUrl, + this.config.embeddingsProvider.embeddingId, ); } diff --git a/core/indexing/docs/migrations.ts b/core/indexing/docs/migrations.ts index b84b0b842..1a09b8b5a 100644 --- a/core/indexing/docs/migrations.ts +++ b/core/indexing/docs/migrations.ts @@ -27,7 +27,7 @@ export async function runLanceMigrations(table: Table) { export async function runSqliteMigrations(db: Database) { await new Promise((resolve) => { - void migrate( + await migrate( "sqlite_modify_docs_columns_and_copy_to_config", async () => { try { @@ -52,7 +52,7 @@ export async function runSqliteMigrations(db: Database) { `ALTER TABLE ${DocsService.sqlitebTableName} RENAME COLUMN baseUrl TO startUrl;`, ); } - + const hasEmbeddingsProviderColumn = pragma.some( (pragma) => pragma.name === "embeddingsProviderId", ); @@ -77,5 +77,25 @@ export async function runSqliteMigrations(db: Database) { }, () => resolve(undefined), ); + await migrate( + "sqlite_delete_docs_with_no_embeddingsProviderId", + async () => { + try { + const pragma = await db.all( + `PRAGMA table_info(${DocsService.sqlitebTableName});`, + ); + const hasEmbeddingsProviderColumn = pragma.some( + (pragma) => pragma.name === "embeddingsProviderId", + ); + if (!hasEmbeddingsProviderColumn) { + // gotta just delete in this case since old docs will be unusable anyway + await db.exec(`DROP TABLE ${DocsService.sqlitebTableName};`); + } + } finally { + resolve(undefined); + } + }, + () => resolve(undefined), + ); }); } From 630d0fb76d16a2b23ececc6678778be371c3086a Mon Sep 17 00:00:00 2001 From: Dallin Romney Date: Tue, 7 Jan 2025 01:49:13 +0100 Subject: [PATCH 2/3] fix migration async logic sqlite docs --- core/indexing/docs/migrations.ts | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/core/indexing/docs/migrations.ts b/core/indexing/docs/migrations.ts index 1a09b8b5a..baa658940 100644 --- a/core/indexing/docs/migrations.ts +++ b/core/indexing/docs/migrations.ts @@ -27,7 +27,7 @@ export async function runLanceMigrations(table: Table) { export async function runSqliteMigrations(db: Database) { await new Promise((resolve) => { - await migrate( + void migrate( "sqlite_modify_docs_columns_and_copy_to_config", async () => { try { @@ -52,7 +52,7 @@ export async function runSqliteMigrations(db: Database) { `ALTER TABLE ${DocsService.sqlitebTableName} RENAME COLUMN baseUrl TO startUrl;`, ); } - + const hasEmbeddingsProviderColumn = pragma.some( (pragma) => pragma.name === "embeddingsProviderId", ); @@ -77,7 +77,10 @@ export async function runSqliteMigrations(db: Database) { }, () => resolve(undefined), ); - await migrate( + }); + + await new Promise((resolve) => { + void migrate( "sqlite_delete_docs_with_no_embeddingsProviderId", async () => { try { From c3bd2ca6c2cd5a006bae9c53c1ffb0d87a429601 Mon Sep 17 00:00:00 2001 From: Dallin Romney Date: Tue, 7 Jan 2025 01:50:12 +0100 Subject: [PATCH 3/3] docs sqlite migrations fix p3 --- core/indexing/docs/migrations.ts | 8 -------- 1 file changed, 8 deletions(-) diff --git a/core/indexing/docs/migrations.ts b/core/indexing/docs/migrations.ts index baa658940..38aa987b3 100644 --- a/core/indexing/docs/migrations.ts +++ b/core/indexing/docs/migrations.ts @@ -53,14 +53,6 @@ export async function runSqliteMigrations(db: Database) { ); } - const hasEmbeddingsProviderColumn = pragma.some( - (pragma) => pragma.name === "embeddingsProviderId", - ); - if (!hasEmbeddingsProviderColumn) { - // gotta just delete in this case since old docs will be unusable anyway - await db.exec(`DROP TABLE ${DocsService.sqlitebTableName};`); - } - const needsToUpdateConfig = !hasFaviconCol || hasBaseUrlCol; if (needsToUpdateConfig) { const sqliteDocs = await db.all<