Skip to content

ADR-0003. Detect schema drift but never auto-rebuild collections

FieldValue
StatusAccepted
Date2026-03-01
Deciders@search-team
Supersedes

Context

  • On bootstrap, TypesenseSearchEngineComponent compares each registered collection config against the live Typesense collection.
  • Typesense cannot alter most field definitions in place; applying a changed schema generally means dropping and recreating the collection.
  • Recreating a collection deletes all its documents, which would silently wipe the search index on a routine deploy.
  • Reindexing from CDC/source after a drop can take a long time and leaves a window of empty/partial results.

Decision

We will create a collection if it is missing, but on divergence we only log an error ("manual migration required") and leave the live collection untouched. Additive field changes are rolled out via the explicit backfill scripts (migrate:references, migrate:denorm); destructive recreations are a deliberate, human-run operation.

Consequences

ProsCons
A deploy can never silently wipe the indexSchema changes require a manual step + operator awareness
Operators choose a safe reindex windowConfig and live schema can stay diverged until acted on
Backfill scripts handle the common additive caseNew destructive changes need a documented runbook step

Alternatives Considered

OptionProsConsWhy rejected
Auto drop + recreate on divergenceFully automatedWipes documents on every schema change deployUnacceptable data-loss risk
Block bootstrap on divergenceForces actionTakes the whole host down for a search schema diffToo blunt; search is non-critical-path
Versioned alias swap (blue/green collections)Zero-downtime reindexMore moving parts, alias managementDeferred — overkill for current scale

References

  • packages/search/src/components/typesense-search-engine.component.tsensureCollectionsWithMigration
  • packages/search/src/helpers/schema-migration.helper.ts
  • Operations

Proprietary and Confidential. Unauthorized copying, distribution, or use of this software is strictly prohibited.