-
-
Notifications
You must be signed in to change notification settings - Fork 6.9k
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
Default expression is not loaded into ColumnSchema #19747
Comments
Doesn't look good. Do you have a time for a fix? |
What doesn't look good?
cannot say concretely. But I will try. If I take this issue in hand, can I introduce breaking change if it is needed? At this moment I cannot say that my PR will have breaking change (also I will try to avoid as much as possible) but if I need to choose a path for solution that might break something (e.g. method signature of public method), can I proceed on that path? |
@SOHELAHMED7 if breaking change is unavoidable, feel free to do it. But it's better to avoid it. |
I came to know that for MariaDB I don't get DEFAULT_GENERATED in Extra column (see this image for MySQL for corresponding data) I just get empty data in Extra So for Mariadb it is very hard to detect that default value is constant or expression: At this moment I am skipping implementation for this issue for Mariadb Any hint to fix this issue for Mariadb is more than welcome |
For MariadbWhile getting info from INFORMATION_SCHEMA I get default value
It will allow me to check if it is non-empty string without quotes it is expression. Though I don't think it is 💯 perfect solution, but I will proceed with this in case of Mariadb |
Note: For table CREATE TABLE IF NOT EXISTS `datetime_test` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`dt` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
`ts` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 for column 'ts', in Extra column for MySQL we get 'DEFAULT_GENERATED on update CURRENT_TIMESTAMP' for Maria we get 'on update current_timestamp()' |
Tests for MariadbI am facing difficulties mocking methods/properties (below) that make db = mariadb in tests public function isMysql()
{
return ($this->db->schema instanceof static && !$this->isMariaDb());
}
public function isMariaDb()
{
return strpos($this->db->schema->getServerVersion(), 'MariaDB') !== false;
} Also if I use real MariaDB server, I have to setup Mariadb in Github action. So I have decided to proceed with tests for Mariadb in below way: I will write tests for Mariadb that will connect with my real local Mariadb server. I will add condition, if db !== mariadb; skip this tests. So theses tests will always be skipped in Github actions but will run if connected to local Mariadb server. |
After several attempts and a question at Stack Overflow, detecting default value is constant or expression in PgSQL is complex/not possible/requires lots of unreliable if condition. So I will skip implementation of this issue for PgSQL. |
When column schema is loaded from DB, for columns having default value as expression but not constant, I get expression as string as default value instead of object of \yii\db\Expression.
Example:
What steps will reproduce the problem?
yii\db\TableSchema::$columns
ts7
column from example$ts7ColumnSchema = (object of yii\db\TableSchema)::$columns['ts7']
What is the expected result?
Now I expect
$ts7ColumnSchema->defaultValue
should be equal to object of\yii\db\Expression('(CURRENT_DATE + INTERVAL 2 YEAR)'')
for MysqlWhat do you get instead?
I get
$ts7ColumnSchema->defaultValue
as '(CURRENT_DATE + INTERVAL 2 YEAR)' as stringHint for solution
For MySQL we get
DEFAULT_GENERATED
in Extra column, we can use that when weloadColumnSchema()
For PgSQL for default constant, its value is suffixed by
::data_type
e.g.::text
Additional info
The text was updated successfully, but these errors were encountered: