MigrationRunner class final
Runs pending data migrations in version order.
On each run call the runner:
- Loads applied migration records from
store. - Filters
migrationsto those not yet applied (by version). - Sorts pending migrations by ascending version.
- Executes each migration's Migration.up method sequentially.
- 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
0if 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