Regression with MariaDB 10.5.1+ with old temporal types in CDbColumnSchema $dbType
marcovtwout opened this issue · 1 comments
Problem
Starting from MariaDB 10.5.1 columns with old temporal formats are marked with a /* mariadb-5.3 */ comment in the output of SHOW CREATE TABLE, SHOW COLUMNS, DESCRIBE statements, as well as in the COLUMN_TYPE column of the INFORMATION_SCHEMA.COLUMNS Table. (https://mariadb.com/kb/en/datetime/#internal-format). MySQL 5.6.24+ has a similar feature, but it is disabled by default (https://dev.mysql.com/doc/refman/8.0/en/server-system-variables.html#sysvar_show_old_temporals. This affects column types DATETIME
, TIME
and TIMESTAMP
for tables that have been created with the old temporal type and haven't been manually upgraded.
Yii 1 uses SHOW COLUMNS
to extract the column type into CDbColumnSchema->dbType
.
Before the change: $dbType = 'datetime';
After the change: $dbType = 'datetime /* mariadb-5.3 */';
CDbColumnSchema defines $dbType
as: "the DB type of this column.". This is not very strict and values vary per database system. However, problems occur where code relies on exact values of dbType:
- CMysqlColumnSchema fails to set a null a default value for these columns in combination with a default expression of CURRENT_TIMESTAMP(): https://github.com/yiisoft/yii/blob/master/framework/db/schema/mysql/CMysqlColumnSchema.php#L47
- CTimestampBehavior fails to map a default value expression for these columns: https://github.com/yiisoft/yii/blob/master/framework/zii/behaviors/CTimestampBehavior.php#L130
- User code may have similar problems if they are expecting the same values as these framework classes.
Possible solutions
-
Do nothing. Users can find and convert their columns from the old temporal type to the new one, but this must be done manually with ALTER TABLE statements: https://mariadb.com/kb/en/datetime/#internal-format:~:text=In%20order%20to%20update%20table%20columns%20from%20the%20older%20format%20to%20the%20newer%20format%2C%20execute%20an%20ALTER%20TABLE...%20MODIFY%20COLUMN%20statement%20that%20changes%20the%20column%20to%20the%20*same*%20data%20type, https://dev.mysql.com/blog-archive/mysql-8-0-removing-support-for-old-temporal-datatypes/#:~:text=How%20to%20Fix%20Old%20Temporals
-
Keep dbType as-is, but modify CTimestampBehavior and CMySQLColumnSchema to deal with the problem. This is easy to apply but users still have to check their application code.
-
Strip the comments out of dbType to restore the old behavior. Other framework usages and user code can stay the same, but dbType no longer is a 1:1 value taken from the database engine.
Additional info
Q | A |
---|---|
Yii version | 1.1.* |
PHP version | any |
Operating system | any |
Database | MariaDB 10.5.1+ or MySQL 5.6.24+ with option show_old_temporals enabled. |
I'm gonna close this as a wontfix
and suggest solution #1 to anyone who runs into this problem.