Skip to content

@statesync/persistence


@statesync/persistence / createSimpleMigration

Function: createSimpleMigration()

ts
function createSimpleMigration<T>(config): MigrationHandler<T>;

Defined in: persistence/src/migration.ts:230

Creates a MigrationHandler directly from a plain configuration object, without using the builder pattern.

This is a convenience function for simple cases where the builder's fluent API is unnecessary.

Type Parameters

Type ParameterDescription
TThe shape of the application state in the current schema version.

Parameters

ParameterTypeDescription
configOmit<MigrationHandler<T>, "validate"> & objectThe migration configuration including currentVersion, migrations record, and an optional validate type-guard.

Returns

MigrationHandler<T>

A migration handler ready to be used with loadPersistedSnapshot or migrateData.

Example

typescript
const migration = createSimpleMigration<AppState>({
  currentVersion: 2,
  migrations: {
    1: (old) => ({ ...old, newField: 'default' }),
  },
});

Released under the MIT License.