Schema class
Laravel-style Schema Facade.
Provides a clean API for database schema operations like creating, modifying, and dropping tables.
Creating Tables
Schema.create('users', (Blueprint table) {
table.id();
table.string('name');
table.string('email').unique();
table.boolean('is_active').defaultValue(true);
table.timestamps();
});
Modifying Tables
Schema.table('users', (Blueprint table) {
table.string('avatar_url').nullable();
table.dropColumn('old_field');
table.renameColumn('name', 'full_name');
});
Dropping Tables
Schema.dropIfExists('users');
Checking Structure
if (await Schema.hasTable('users')) {
// Table exists
}
if (await Schema.hasColumn('users', 'email')) {
// Column exists
}
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
-
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
Static Methods
-
create(
String table, void callback(Blueprint)) → void - Create a new table.
-
drop(
String table) → void - Drop a table (throws if it doesn't exist).
-
dropIfExists(
String table) → void - Drop a table if it exists.
-
getColumns(
String table) → Future< List< String> > - Get all column names for a table.
-
hasColumn(
String table, String column) → Future< bool> - Check if a table has a specific column.
-
hasTable(
String table) → Future< bool> - Check if a table exists.
-
rename(
String from, String to) → void - Rename a table.
-
table(
String tableName, void callback(Blueprint)) → void - Modify an existing table.