$db = new FluidSchema($schema);
$posts = $db->table('posts');
$posts->id() // Let's create a default autoincremented ID column
->column('description')->string(50)->null() // Let's create a 'description' column
->column('user_id')->references('users'); // Let's create a foreign key.
// We only specify the table name.
// FluidSchema infers the column type and the "remote" column.
$table = $db->table('foo');
// Supported types
$table->column('xxxx')->string(50) // VARCHAR(50)
->column('xxxx')->integer()
->column('xxxx')->float()
->column('xxxx')->text() // Long string
->column('xxxx')->boolean()
->column('xxxx')->smallInt()
->column('xxxx')->bigInt()
->column('xxxx')->decimal(10, 2) // DECIMAL(10, 2)
->column('xxxx')->guid()
->column('xxxx')->binary(255)
->column('xxxx')->blob() // Long binary
->column('xxxx')->date()
->column('xxxx')->datetime()
->column('xxxx')->datetimeTz()
->column('xxxx')->time()
->column('xxxx')->dateImmutable() // From Doctrine DBAL 2.6+
->column('xxxx')->datetimeImmutable() // From Doctrine DBAL 2.6+
->column('xxxx')->datetimeTzImmutable() // From Doctrine DBAL 2.6+
->column('xxxx')->timeImmutable() // From Doctrine DBAL 2.6+
->column('xxxx')->dateInterval() // From Doctrine DBAL 2.6+
->column('xxxx')->array()
->column('xxxx')->simpleArray()
->column('xxxx')->json() // From Doctrine DBAL 2.6+
->column('xxxx')->jsonArray() // Deprecated in Doctrine DBAL 2.6+
->column('xxxx')->object(); // Serialized PHP object
// Create an 'id' primary key that is an autoincremented integer
$table->id();
// Don't like autincrements? No problem!
// Create an 'uuid' primary key that is of the DBAL 'guid' type
$table->uuid();
// Create "created_at" and "updated_at" columns
$table->timestamps();
// Directly on a column:
$table->column('login')->string(50)->index();
// Or on the table object (if there are several columns to add to an index):
$table->index(['category1', 'category2']);
// Directly on a column:
$table->column('login')->string(50)->unique();
// Or on the table object (if there are several columns to add to the constraint):
$table->unique(['login', 'status']);
$db->junctionTable('users', 'roles');
// This will create a 'users_roles' table with 2 foreign keys:
// - 'user_id' pointing on the PK of 'users'
// - 'role_id' pointing on the PK of 'roles'
$db->table('contacts')
->id()
->column('date')->datetime(); // Will most likely fail, because "date" is a reserved keyword!
use TheCodingMachine\FluidSchema\DefaultNamingStrategy;
// Assuming $connection is your DBAL connection
$db = new FluidSchema($schema, new DefaultNamingStrategy($connection->getDatabasePlatform()));
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.