Schema migration¶
SCHEMA_VERSION (in particles/core/schema.py) is the version of the
particle record format, and every particle records the version it was
written under. It is MAJOR.MINOR.PATCH. Two versions with the same
major are compatible; a different major is breaking.
Two things version a store, and they move independently:
| What it versions | How it moves | |
|---|---|---|
SCHEMA_VERSION |
what a particle record means | an ADR that changes the record format |
| the Alembic revision | the tables and columns that hold it | particles db init / alembic upgrade head |
Minor and patch versions¶
A minor version only adds: new optional fields whose absence means what a record meant before. An SDK reads and writes a store holding any minor of its own major, in either direction:
- A newer SDK on an older store reads the older particles with the
new fields at their defaults.
particles lintreports them asSCHEMA_VERSION_OLDER_MINOR(INFO). The release that added the fields names the command that fills them in;particles reindex --include-schema-stalere-extracts those particles' sources instead, which is a paid run (the dry run reports its size first). - An older SDK on a newer store reads the newer particles without the
fields it does not know, and writes new particles at its own version.
particles lintreports the newer ones asSCHEMA_VERSION_NEWER_MINOR(INFO). It can still retract or overrule a newer particle, but it never replaces one with its own copy (a reindex re-extraction, a dated restatement, a duplicate merge): those are skipped and counted, and wait for a current SDK.
A patch version changes nothing about the record and is ignored by every comparison. Moving between minors needs no rebuild. The storage half is the ordinary migration chain:
The migration registry centralises every ORM module's metadata via
particles/_orm_modules.py. Adding a new table is one Alembic
revision + an entry in _orm_modules.py. A migration shipped with a
minor schema version is additive (nullable columns, columns with a
server default, new tables or indexes), so an older SDK keeps writing to
the migrated tables.
SDKs released before same-major compatibility (see the changelog entry
that introduced it) refuse a store holding any version other than
1.0.0, so upgrade every installation that shares a store before
running a release that moves SCHEMA_VERSION.
Major bumps¶
A 1.x.y → 2.0.0 schema bump means the particle on-disk shape
changed in a way that's not backwards-compatible. The operator path:
- Read the release notes / ADR for the major bump. It will document what changed and the migration cost.
- Backup the corpus. The corpus blobs +
corpus_entries/snapshotstables survive major bumps; only particle-store tables get scrapped. - Run
particles db init --force. This drops every particle-store table (particles, subjects, particle_subjects, relations, source_trust_statements, extractor records) and resets every snapshot'sextraction_statustoPENDING. The corpus itself is preserved. The command confirms before dropping. - Re-extract with
particles extract --all-pending. For aMUTABLEsource with several snapshots (a memory or rule file edited over time), only the newest is re-extracted, so the rebuilt store holds the same current beliefs but not thePROVENANCE_STALEhistory of each intermediate version. Setextraction.collapse_superseded_pending: falsebefore re-extracting if you want that history rebuilt, at one LLM call per version. See Mutable local sources.
The "scrap-and-re-extract" path is what --force exists for. It's
the supported migration mechanism between schema major versions
because the corpus is the durable record and particles are
rebuildable from corpus + extractor.
Mid-migration safety¶
If the store holds particles of another major SCHEMA_VERSION, the CLI
fails fast with a message that says which way the store differs, rather
than silently running incompatible code. See troubleshooting
for the exact error and recovery path.
What's NOT preserved¶
- Particles, subjects, the particle_subjects join table, relations
- SourceTrustStatements
- Extractor calibration history
- Particle embeddings (regenerated on first query after reindex)
What IS preserved¶
- Corpus entries + every snapshot
- The blob directory contents
corpus_follow_edges- Conformance baseline JSON files under
docs/conformance/baseline/