Download the PHP package jmsfwk/fluent-phinx without Composer
On this page you can find all versions of the php package jmsfwk/fluent-phinx. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download jmsfwk/fluent-phinx
More information about jmsfwk/fluent-phinx
Files in jmsfwk/fluent-phinx
Package fluent-phinx
Short Description Laravel style migrations with Phinx
License proprietary
Informations about the package fluent-phinx
Fluent Phinx
Laravel-style migrations for Phinx.
- Introduction
- Migration Structure
- Tables
- Creating Tables
- Updating Tables
- Table Options
- Indexes
- Creating Indexes
Introduction
Phinx provides a way to declare schemas in migrations, but it's somewhat difficult to use because of the array of options that vary by column type.
Fluent Phinx provides a fluent Laravel-style schema builder to simplify writing and reading migrations.
Migration Structure
Fluent Phinx relies on regular Phinx migration files,
with either a change
method or up
/down
method pair.
The Fluent
trait can be used to add fluent functionality to the migration file.
Tables
Creating Tables
To create a new database table, use the create
method on from the Fluent
trait. The create method accepts two
arguments: the first is the name of the table, while the second is a closure which receives a Blueprint
object
that may be used to define the new table:
When creating the table, you may use any of the schema builder's column methods to define the table's columns.
Updating Tables
To update a table the update
method from the Fluent
trait can be used. Like the create
method this will accept
two arguments: the name of the table, and a closure that receives a Blueprint
object to define the changes.
Table Options
You may use the following properties on the schema builder to define the table's options:
Command | Description |
---|---|
$table->engine = 'InnoDB'; |
Specify the table storage engine (MySQL). |
$table->collation = 'utf8mb4_unicode_ci'; |
Specify a default collation for the table (MySQL). |
$table->comment = 'Explain something'; |
Specify a comment for the table. |
$table->id = 'id' |
The name of the automatically created id field (set to false to disable). |
$table->primary_key = 'id' |
The column to use as the primary key (can be set to an array of columns). |
$table->signed = false |
Whether the primary key is signed (defaults to true ). |
Indexes
Creating Indexes
Indexes can be added in two places, from the column definition and from the Blueprint
object.
From the column you can pass the index name to the index method.
To create an index after defining the column, you should call the unique
method on the schema builder
blueprint. This method accepts the name of the column that should receive a unique index:
You may pass an array of columns to an index method to create a compound (or composite) index:
When creating an index you may pass a second argument to the method to specify the index name:
Available Index Types
Command | Description |
---|---|
$table->primary('id'); |
Adds a primary key. |
$table->primary(['id', 'parent_id']); |
Adds composite keys. |
$table->unique('email'); |
Adds a unique index. |
$table->index('state'); |
Adds an index. |