EzDevInfo.com

phinx

PHP Database Migrations for Everyone Phinx phinx makes it ridiculously easy to manage the database migrations for your php app.

Phinx and pt-online-schema-change

Does Phinx support pt-online-schema-change?

I realize Phinx is supposed to handle DB migrations. But in the live environment, running a simple ALTER TABLE command on a huge table might lead to a table lock and temporary service unavailability.

There is a tool from Percona Toolkit called pt-online-schema-change which can handle the schema migration without any downtime, by creating a temporary table, copying the data and re-applying the log.

Is there a way to easily integrate these two, in order to get nice DB migration management from Phinx, and the production zero downtime from Percona Toolkit? Is there any other DB migration management tool, which supports pt-online-schema-change?


Source: (StackOverflow)

Adding a Foreign Key Using Phinx

I'm trying to add foreign keys to a table using a Phinx migration. My intention is to create a table ('sales_order_attachment') and add two foreign keys. There's not too much Phinx documentation, so I haven't found an answer on the internet or through tinkering (yet). What am I doing wrong here? Both tables and keys the migration is pointing to exist.

Migration:

public function up()
{
    $table = $this->table('sales_order_attachment', array('id' => 'sales_order_attachment_id'));
    $table->addColumn('file_upload_id', 'integer')
        ->addForeignKey('file_upload_id', 'file_upload', 'id');
    $table->addColumn('sales_order_id', 'integer')
        ->addForeignKey('sales_order_id', 'sales_order', 'id')
        ->save();
}

public function down()
{
    $this->table('sales_order_attachment')->drop();
}

Error:

[PDOException]                                                                                            
SQLSTATE[HY000]: General error: 1005 Can't create table 'table.sales_order_attachment' (errno: 150)  

Source: (StackOverflow)

Advertisements