ManualMigration class
A migration that uses callbacks for up/down operations
Example:
final migrations = [
ManualMigration(
version: 2,
description: 'Seed initial data',
onUp: (connection, schemaManager) async {
await connection.execute(
"INSERT INTO users (name, email) VALUES ('Admin', 'admin@example.com')",
);
},
onDown: (connection, schemaManager) async {
await connection.execute(
"DELETE FROM users WHERE email = 'admin@example.com'",
);
},
),
];
- Inheritance
-
- Object
- DatabaseMigration
- ManualMigration
Constructors
- ManualMigration({required int version, required String description, required MigrationCallback onUp, MigrationCallback? onDown})
- Create a manual migration with callbacks
Properties
- connection ↔ DatabaseConnection
-
getter/setter pairinherited
- dbType → DatabaseType
-
no setterinherited
- description → String
-
no setteroverride
- hashCode → int
-
The hash code for this object.
no setterinherited
- onDown → MigrationCallback?
-
final
- onUp → MigrationCallback
-
final
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- schemaManager ↔ SchemaManager
-
getter/setter pairinherited
- version → int
-
no setteroverride
Methods
-
addColumn(
{required String table, required String column, required String type, bool nullable = true, String? defaultValue}) → Future< void> -
Helper to add column (skips if exists)
inherited
-
createIndex(
{required String name, required String table, required List< String> columns, bool unique = false}) → Future<void> -
Helper to create index (skips if exists)
inherited
-
createTable(
DatabaseSchema schema) → Future< void> -
Helper to create a table from schema (skips if exists)
inherited
-
down(
) → Future< void> -
Migration down - rollback schema
override
-
dropColumn(
{required String table, required String column}) → Future< void> -
Helper to drop column (skips if not exists)
inherited
-
dropIndex(
String name) → Future< void> -
Helper to drop index (skips if not exists)
inherited
-
dropTable(
String tableName) → Future< void> -
Helper to drop a table (skips if not exists)
inherited
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
setConnection(
DatabaseConnection conn) → void -
inherited
-
tableExists(
String tableName) → Future< bool> -
Helper to check if table exists
inherited
-
toString(
) → String -
A string representation of this object.
inherited
-
up(
) → Future< void> -
Migration up - create/modify schema
override
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited