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

Incorrect mapping of default expression for MySQL >= 5.6.4 CURRENT_TIME #17744

Closed
bizley opened this issue Dec 18, 2019 · 2 comments
Closed

Incorrect mapping of default expression for MySQL >= 5.6.4 CURRENT_TIME #17744

bizley opened this issue Dec 18, 2019 · 2 comments
Milestone

Comments

@bizley
Copy link
Member

bizley commented Dec 18, 2019

What steps will reproduce the problem?

Create MySQL >= 5.6.4 table with timestamp(3) column and CURRENT_TIMESTAMP(3) as default value.
Fetch this schema in Yii 2.

What is the expected result?

$column->defaultValue = new Expression('CURRENT_TIMESTAMP(3)');

What do you get instead?

$column->defaultValue = 'CURRENT_TIMESTAMP(3)';

Additional info

Q A
Yii version *
PHP version *
Operating system *

These lines are too strict now. I'll prepare PR with regex match and see if it's enough.

@alex-code
Copy link
Contributor

Quick and easy would be to use stripos and check if it matches 0.

if (($column->type === 'timestamp' || $column->type === 'datetime') &&
  stripos($info['default'], 'current_timestamp') === 0) {
  $column->defaultValue = new Expression('CURRENT_TIMESTAMP');
} elseif (isset($type) && $type === 'bit') {

@bizley
Copy link
Member Author

bizley commented Dec 18, 2019

Yes, if this is enough and matches all possibilities. I haven't dig into MySQL and MariaDB docs yet ;)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants