Blueprint class

The Blueprint Class.

Provides a fluent API for defining table schemas programmatically. Think of it as a Laravel migration's Schema facade.

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');
});

Available Column Types

  • id() - Auto-incrementing primary key
  • string(name, [length]) - VARCHAR/TEXT column
  • text(name) - TEXT column for long content
  • integer(name) - INTEGER column
  • bigInteger(name) - INTEGER column (same in SQLite)
  • boolean(name) - INTEGER column (0/1)
  • real(name) - REAL/FLOAT column
  • blob(name) - BLOB column for binary data
  • timestamps() - created_at and updated_at columns

Constructors

Blueprint(String tableName, {bool isModification = false})
Create a new blueprint for a table.

Properties

hashCode int
The hash code for this object.
no setterinherited
isModification bool
Whether this is a modification blueprint (not create).
final
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
tableName String
The table name.
final

Methods

bigInteger(String name) ColumnDefinition
Add a big integer column.
blob(String name) ColumnDefinition
Add a blob column for binary data.
boolean(String name) ColumnDefinition
Add a boolean column.
dropColumn(String name) → void
Drop a column from the table.
execute() → void
Execute the CREATE TABLE statement.
id([String name = 'id']) ColumnDefinition
Add an auto-incrementing primary key column.
integer(String name) ColumnDefinition
Add an integer column.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
real(String name) ColumnDefinition
Add a real (float) column.
renameColumn(String from, String to) → void
Rename a column.
string(String name, [int? length]) ColumnDefinition
Add a string (TEXT) column.
text(String name) ColumnDefinition
Add a text column for long content.
timestamps() → void
Add timestamp columns (created_at and updated_at).
toSql() String
Generate the CREATE TABLE SQL statement.
toString() String
A string representation of this object.
inherited

Operators

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