MigrationBuilder<T extends Model> class
Fluent builder for creating migration sequences. Provides type-safe methods for common migration operations.
Example:
final migrations = table.migrate()
.addColumn(name: 'email', type: 'TEXT', version: 2)
.renameColumn(oldName: 'full_name', newName: 'name', version: 2)
.createIndex(name: 'idx_active', columns: ['is_active'], version: 3)
.custom(
description: 'Backfill data',
version: 2,
migrate: (db, table) async {
await db.execute('UPDATE ${table.name} SET status = "active"');
},
)
.build();
Constructors
-
MigrationBuilder(Table<
T> _table) - Creates a migration builder for the given table.
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
-
addCheckConstraint(
{required String constraint, required int version, String? description}) → MigrationBuilder< T> - Adds a CHECK constraint
-
addColumn(
{required String name, required String type, required int version, bool nullable = true, String? defaultValue, String? description}) → MigrationBuilder< T> - Adds a new column to the table
-
addForeignKey(
{required String column, required String referenceTable, required String referenceColumn, required int version, String onDelete = 'NO ACTION', String onUpdate = 'NO ACTION', String? description}) → MigrationBuilder< T> - Adds a foreign key constraint
-
build(
) → Table< T> - Builds the migration list
-
createIndex(
{required String name, required List< String> columns, required int version, bool unique = false, String? description}) → MigrationBuilder<T> - Creates an index
-
custom(
{required String description, required int version, required Future< void> migrate(PhormDatabaseExecutor db, Table<T> table)}) → MigrationBuilder<T> - Adds a custom migration with arbitrary logic
-
dropColumn(
{required String name, required int version, String? description}) → MigrationBuilder< T> - Drops a column from the table
-
dropIndex(
{required String name, required int version, String? description}) → MigrationBuilder< T> - Drops an index
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
raw(
String sql, {required int version, String description = ''}) → MigrationBuilder< T> - Adds a raw SQL migration
-
renameColumn(
{required String oldName, required String newName, required int version, String? description}) → MigrationBuilder< T> - Renames a column
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited