Migrator class

Schema migration framework for Rift.

The Migrator handles the process of migrating box data from one schema version to another. It reads the current schema version from the box (stored as the special key __rift_schema_version__), then applies migration steps in order until the target version is reached.

Migration is idempotent — if the box is already at the target version, no migrations are applied.

Usage:

await rift.openBox('users', migrations: [
  MigrationStep(
    fromVersion: 1,
    toVersion: 2,
    migrate: (data) {
      data['email'] = data['email'] ?? '';
      return data;
    },
  ),
  MigrationStep(
    fromVersion: 2,
    toVersion: 3,
    migrate: (data) {
      data['fullName'] = data.remove('name');
      return data;
    },
  ),
]);

Constructors

Migrator(List<MigrationStep> steps)
Creates a new migrator with the given steps.

Properties

hashCode int
The hash code for this object.
no setterinherited
maxReachableVersion int
Gets the highest version that can be reached with the registered migration steps.
no setter
minReachableVersion int
Gets the lowest version that can be reached with the registered migration steps.
no setter
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
steps List<MigrationStep>
The ordered list of migration steps.
final

Methods

migrate(BoxBaseImpl box, int currentVersion, int targetVersion) Future<void>
Performs migration on the given box from currentVersion to targetVersion.
needsMigration(BoxBaseImpl box, int targetVersion) Future<bool>
Checks if migration is needed for the given box.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() String
A string representation of this object.
inherited
validateChain(int startVersion, int endVersion) List<String>
Validates that the migration steps form a continuous chain from startVersion to endVersion.

Operators

operator ==(Object other) bool
The equality operator.
inherited