Migrator class
The Migrator Service.
Handles running and tracking database migrations. The migrator keeps track
of which migrations have already been executed using a magic_migrations
table in the database.
Running Migrations
final migrator = Migrator();
await migrator.run([
CreateUsersTable(),
CreatePostsTable(),
AddAvatarToUsers(),
]);
How It Works
- Creates the
magic_migrationstracking table if it doesn't exist - Loads all previously executed migrations
- Filters the provided migrations to only pending ones
- Executes each pending migration's
upmethod - Records each successful migration in the tracking table
- Clears the schema cache for affected tables
Rolling Back
// Rollback the last batch
await migrator.rollback([
CreateUsersTable(),
CreatePostsTable(),
]);
Constructors
- Migrator()
-
Factory constructor returns the singleton.
factory
Properties
- hashCode → int
-
The hash code for this object.
no setterinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
getExecuted(
) → Future< List< String> > - Get the list of executed migrations.
-
getPending(
List< Migration> migrations) → Future<List< String> > - Get pending migrations.
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
refresh(
List< Migration> migrations) → Future<void> - Refresh the database (reset then run all migrations).
-
reset(
List< Migration> migrations) → Future<List< String> > - Reset the database by rolling back all migrations.
-
rollback(
List< Migration> migrations) → Future<List< String> > - Rollback the last batch of migrations.
-
run(
List< Migration> migrations) → Future<List< String> > - Runs every pending migration, or none of them.
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited