MigrationRunner class

A lightweight SQL migration runner.

Scans a directory for *.sql migration files (sorted alphabetically), tracks which ones have been applied in a _dartapi_migrations table, and applies any pending migrations in order.

Convention: name files with a numeric prefix so they sort correctly:

migrations/
├── 0001_create_users.sql
├── 0002_add_email_index.sql
└── 0003_create_products.sql

Usage:

final runner = MigrationRunner(db);
await runner.migrate();

Call dartapi db migrate from the CLI instead of calling this directly when running from the project root.

Constructors

MigrationRunner(DartApiDB db, {String migrationsPath = 'migrations'})

Properties

db DartApiDB
final
hashCode int
The hash code for this object.
no setterinherited
migrationsPath String
Path to the directory containing .sql migration files.
final
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

appliedMigrations() Future<Set<String>>
Returns the list of migration names that have already been applied.
migrate({bool dryRun = false}) Future<void>
Applies all pending migrations.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() String
A string representation of this object.
inherited

Operators

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