Migration
See source codeDefines a single migration that transforms data from one schema version to another.
A migration can operate at two different scopes:
record
: Transforms individual records, with optional filtering to target specific recordsstore
: Transforms the entire serialized store structure
Each migration has a unique ID and can declare dependencies on other migrations that must
be applied first. The up
function performs the forward transformation, while the optional
down
function can reverse the migration if needed.
type Migration = {
readonly dependsOn?: readonly MigrationId[] | undefined
readonly id: MigrationId
} & (
| {
readonly down?: (
newState: SerializedStore<UnknownRecord>
) => SerializedStore<UnknownRecord> | void
readonly scope: 'store'
readonly up: (
oldState: SerializedStore<UnknownRecord>
) => SerializedStore<UnknownRecord> | void
}
| {
readonly down?: (newState: UnknownRecord) => UnknownRecord | void
readonly filter?: (record: UnknownRecord) => boolean
readonly scope: 'record'
readonly up: (oldState: UnknownRecord) => UnknownRecord | void
}
)
Prev
IdOfNext
MigrationId