Merge pull request #3623 from continuedev/dallin/docs-embedding-id

Separate Docs EmbeddingProviderId migration
This commit is contained in:
Nate Sesti 2025-01-07 15:25:11 -08:00 • committed by GitHub
commit a4bde28558
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 40 additions and 10 deletions

View file

@ -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,
);
}

View file

@ -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<
@ -78,4 +70,27 @@ export async function runSqliteMigrations(db: Database) {
() => resolve(undefined),
);
});
await new Promise((resolve) => {
void 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),
);
});
}