store.hydrate() when the persisted schema version lags behind the configured version. Migrations have full read/write access to records, collection states, outbox items, and metadata.
How migrations run
Whenhydrate() finds that the persisted schema version is less than schema.version, it runs each migration whose version number falls in the range (persistedVersion, configuredVersion], in ascending order. After all migrations complete, the new schema version is written to IndexedDB.
hydrate() throws a version mismatch error if the persisted schema version is newer than the configured one. This guards against data corruption when a user opens an older version of your app after upgrading. Always bump schema.version before shipping schema changes.The migration context
Every migration receives aSyncMigrationContext that exposes typed read/write helpers for every table CL Sync manages:
Defining migrations
Declare an array ofSyncMigration objects and pass them to createSyncStore. Each migration’s version is the version it migrates to.
Migration examples
Rename a field
Backfill a computed field
Prune stale outbox entries
Move collection state after rename
If you rename a collection, delete the old collection state so CL Sync doesn’t treat the stale key as valid:Full example
Here’s a store configured with two sequential migrations:1, both migrations run in order on the next hydrate() call. If their persisted version is already 2, only the version-3 migration runs.