[SCHEMA] Improve timestamp storage

Avoid the use of deprecated MariaDB "zero dates" globally. If they're present
as attribute defaults somewhere, they will be replaced with NULL implicitly.
The existing "zero dates" in MariaDB storage will be left intact and this
should not present any issues.

The "timestamp" type in table definitions now corresponds to DATETIME in
MariaDB with "DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP", which
should be close enough to the original behaviour for compatibility purposes.
It is now the recommended type for "modified" attributes, because of the
update trigger on MariaDB. But there is no such trigger implemented on
PostgreSQL as of this moment.
This commit is contained in:
Alexei Sorokin
2020-06-29 01:41:46 +03:00
parent b924c180ae
commit 9a515b9234
73 changed files with 1130 additions and 756 deletions

View File

@@ -145,8 +145,12 @@ class MysqlSchema extends Schema
if (preg_match('/(^|\s)auto_increment(\s|$)/i', $extra)) {
$field['auto_increment'] = true;
}
// $row['EXTRA'] may contain 'on update CURRENT_TIMESTAMP'
// ^ ...... how to specify?
if (preg_match(
'/(^|\s)on update CURRENT_TIMESTAMP(\(\))?(\s|$)/i',
$extra
)) {
$field['auto_update_timestamp'] = true;
}
}
$table_props = $this->getTableProperties($table, ['TABLE_COLLATION']);
@@ -457,13 +461,17 @@ class MysqlSchema extends Schema
$line = [];
$line[] = parent::columnSql($name, $cd);
// This'll have been added from our transform of 'serial' type
// This'll have been added from our transform of "serial" type
if (!empty($cd['auto_increment'])) {
$line[] = 'auto_increment';
$line[] = 'AUTO_INCREMENT';
}
// This'll have been added from our transform of "timestamp" type
if (!empty($cd['auto_update_timestamp'])) {
$line[] = 'ON UPDATE CURRENT_TIMESTAMP';
}
if (!empty($cd['description'])) {
$line[] = 'comment';
$line[] = 'COMMENT';
$line[] = $this->quoteValue($cd['description']);
}