forked from GNUsocial/gnu-social
[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:
@@ -413,24 +413,9 @@ class PgsqlSchema extends Schema
|
||||
// No convenient support for field descriptions
|
||||
unset($col['description']);
|
||||
|
||||
switch ($col['type']) {
|
||||
case 'serial':
|
||||
$col['type'] = 'int';
|
||||
$col['auto_increment'] = true;
|
||||
break;
|
||||
case 'timestamp':
|
||||
// FIXME: ON UPDATE CURRENT_TIMESTAMP
|
||||
if (!array_key_exists('default', $col)) {
|
||||
$col['default'] = 'CURRENT_TIMESTAMP';
|
||||
}
|
||||
// no break
|
||||
case 'datetime':
|
||||
// Replace archaic MySQL-specific zero dates with NULL
|
||||
if (($col['default'] ?? null) === '0000-00-00 00:00:00') {
|
||||
$col['default'] = null;
|
||||
$col['not null'] = false;
|
||||
}
|
||||
break;
|
||||
if ($col['type'] === 'serial') {
|
||||
$col['type'] = 'int';
|
||||
$col['auto_increment'] = true;
|
||||
}
|
||||
|
||||
$col['type'] = $this->mapType($col);
|
||||
|
Reference in New Issue
Block a user