2. @MICHAELPEACOCK
CTO @ Ground Six
www.michaelpeacock.co.uk
@michaelpeacock
Author: latest book 'Creating development environments
with Vagrant' due to be published within the next few
weeks
Occasionally yabbers on at conferences and user groups
3. DATABASE MIGRATIONS
Easily manage changes to your database schema
Roll back if you need to
Store them in version control, share with colleagues
11. TABLE API
Powerful table API lets you create migrations in a relatively
database agnostic way. Underlying functionality differs per
database.
12. TABLE API: CAVEATS
Not all field types are supported; typically follows ANSI SQL
column types
id field is automatically created (primary key, auto
increment)
13. A DIFFERENT PRIMARY KEY
$users = $this->table('users', array('id' => 'user_id'));
Non autoincrement primary keys
$user_profiles = $this->table('user_profiles', array('primary_key' => 'user_id'));
14. ABSTRACT ADAPTER
All implemented database engines implement these (and
more)
public function query($sql);
public function createTable(Table $table);
public function renameTable($tableName, $newName);
public function dropTable($tableName);
public function hasColumn($tableName, $columnName);
public function addColumn(Table $table, Column $column);
public function renameColumn($tableName, $columnName, $newColumnName);
public function changeColumn($tableName, $columnName, Column $newColumn);
public function dropColumn($tableName, $columnName);
public function hasIndex($tableName, $columns);
public function addIndex(Table $table, Index $index);
public function dropIndex($tableName, $columns);
public function dropDatabase($name);
15. CHANGE
Phinx has a change method which, provided it uses create()
and update() methods from the table API, it will work out how
to either up or down based off the change() code. Requires the
change method to be present. Doesn't work with the save()
method we have used.