cycle/migrations

Column options aliasing do not work for options defined by alias

AnrDaemon opened this issue · 0 comments

<?php

use Cycle\Migrations\Migration;

class example_table_0001 extends Migration {

    protected const DATABASE = '[default]';

    /**
     * Create tables, add columns or insert data here
     */
    public function up() {
        $this->table('example_table');
        ->addColumn('created', 'timestamp', [
            'nullable' => false,
            'defaultValue' => \Cycle\Database\Injection\Fragment::__set_state(array(
   'fragment' => 'CURRENT_TIMESTAMP',
)),
        ])
                ->create();
    }

    /**
     * Drop created, columns and etc here
     */
    public function down() {
        $this->table('example_table')->drop();
    }
};

The defaultValue alias of default option is not picked up by hasOption() because it checks…

  1. If an option with requested name exists (it is not, but alias present).
  2. If requested name has aliases (it do have, but it is not a terminating check, if successful).
  3. If requested name is in the any list of aliases (it is not, but the option IS declared by an alias).

The check connecting 3 back to 2 is missing, thus declaring column with "defaultValue" simply skips default values entirely.

I did not hit it initially because of MariaDB 10.4 setting timestamp columns as … DEFAULT NOW(). 10.10 does not, and entire system collapses.