Search code examples
mysqlcakephpmigrationphinx

How to migrate column type DOUBLE via cakephp phinx migrations?


I'm trying to migrate table from db1 to db2 with using Phinx migrations, but i have a problem with one table where i have column type DOUBLE. I know that supported types are there Phinx column type, but it is possible to specify FLOAT type to get DOUBLE in diff_migration ? I use cakephp version 3.5.6.

My example migration_diff

<?php
   use Migrations\AbstractMigration;

   class Diff003 extends AbstractMigration
{

public function up()
{

    $this->table('test_double')
        ->addColumn('double1', 'float', [ // here type DOUBLE is changing to  FLOAT
            'default' => null,
            'limit' => null,
            'null' => true,
        ])
        ->addColumn('double2', 'float', [
            'default' => null,
            'limit' => null,
            'null' => true,
        ])
        ->create();
}

public function down()
{

    $this->dropTable('test_double');
}

}


Solution

  • The DOUBLE type has been implemented recently, and will probably be available in the next Phinx release (it's been added as of version 0.10.7), see https://github.com/cakephp/phinx/pull/1493.

    Until then you can for example use the custom column type feature:

    ->addColumn('double1', \Phinx\Util\Literal::from('DOUBLE'), [
        // ...
    ])
    

    or manually add the columns via raw SQL, something like:

    $this->execute('ALTER TABLE test_double ADD COLUMN double1 DOUBLE NULL');
    

    or if you're adventurous, use the Phinx master branch until the stable release is available:

    composer require robmorgan/phinx:dev-master
    
    ->addColumn('double1', 'double', [
        // ...
    ])