Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Column options aliasing do not work for options defined by alias #44

Open
AnrDaemon opened this issue Dec 21, 2022 · 0 comments
Open

Column options aliasing do not work for options defined by alias #44

AnrDaemon opened this issue Dec 21, 2022 · 0 comments

Comments

@AnrDaemon
Copy link
Contributor

<?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.

@roxblnfk roxblnfk added this to Cycle Dec 21, 2022
@roxblnfk roxblnfk moved this to Discuss in Cycle Dec 21, 2022
@roxblnfk roxblnfk moved this from Discuss to Backlog in Cycle Sep 7, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Backlog
Development

No branches or pull requests

1 participant