Schema class
A fluent, type-safe schema builder for database migrations.
Instead of writing raw SQL in migrations, use the Schema class to define tables declaratively:
class CreateUsersTable extends Migration {
@override
Future<void> up(DatabaseExecutor db) async {
await Schema(db).create('users', (table) {
table.id();
table.string('name');
table.string('email').unique();
table.integer('age').nullable();
table.boolean('is_active').defaultsTo('true');
table.timestamps();
});
}
@override
Future<void> down(DatabaseExecutor db) async {
await Schema(db).drop('users');
}
}
Constructors
- Schema(DatabaseExecutor _db)
-
Creates a new Schema tied to the given database
executor.
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
-
alter(
String name, void callback(Blueprint table)) → Future< void> - Modifies an existing table by adding new columns.
-
create(
String name, void callback(Blueprint table)) → Future< void> -
Creates a new table with the given
nameusing thecallbackto define columns. -
drop(
String name) → Future< void> - Drops a table if it exists.
-
dropIfExists(
String name) → Future< void> - Drops a table only if it exists (safe version).
-
hasColumn(
String table, String column) → Future< bool> - Checks if a column exists on a table.
-
hasTable(
String name) → Future< bool> - Checks if a table exists.
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
rename(
String from, String to) → Future< void> - Renames a table.
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited