MigrationRunner class final

Runs pending data migrations in version order.

On each run call the runner:

  1. Loads applied migration records from store.
  2. Filters migrations to those not yet applied (by version).
  3. Sorts pending migrations by ascending version.
  4. Executes each migration's Migration.up method sequentially.
  5. Appends a MigrationRecord after each successful migration.

If any migration throws, execution halts and the error is rethrown as a StorageException. Migrations already applied before the failure are retained in the store.

final runner = MigrationRunner(
  migrations: [
    AddUserTableMigration(),    // version: 1
    AddEmailIndexMigration(),   // version: 2
  ],
  store: SharedPrefsMigrationStore(),
);

await runner.run(); // runs pending migrations on app startup

Constructors

MigrationRunner({required List<Migration> migrations, MigrationStore? store})

Properties

currentVersion Future<int>
Returns the version number of the most recently applied migration, or 0 if no migrations have been applied.
no setter
executedMigrations Future<List<MigrationRecord>>
Returns an immutable list of all applied MigrationRecords.
no setter
hashCode int
The hash code for this object.
no setterinherited
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
run() Future<void>
Executes all pending migrations in ascending Migration.version order.
toString() String
A string representation of this object.
inherited

Operators

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