diff --git a/CHANGELOG.md b/CHANGELOG.md index db775061..99163978 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Fixed - Fixed spurious infinite loads with explore panel, file tree, and file search command. [#617](https://github.com/sourcebot-dev/sourcebot/pull/617) +- Wipe search context on init if entitlement no longer exists [#618](https://github.com/sourcebot-dev/sourcebot/pull/618) ## [4.9.2] - 2025-11-13 diff --git a/packages/web/src/initialize.ts b/packages/web/src/initialize.ts index fa27febd..97efc9ea 100644 --- a/packages/web/src/initialize.ts +++ b/packages/web/src/initialize.ts @@ -62,6 +62,18 @@ const initSingleTenancy = async () => { } } + // If we don't have the search context entitlement then wipe any existing + // search contexts that may be present in the DB. This could happen if a deployment had + // the entitlement, synced search contexts, and then no longer had the entitlement + const hasSearchContextEntitlement = hasEntitlement("search-contexts") + if(!hasSearchContextEntitlement) { + await prisma.searchContext.deleteMany({ + where: { + orgId: SINGLE_TENANT_ORG_ID, + }, + }); + } + // Sync anonymous access config from the config file const config = await loadConfig(env.CONFIG_PATH); const forceEnableAnonymousAccess = config.settings?.enablePublicAccess ?? env.FORCE_ENABLE_ANONYMOUS_ACCESS === 'true';