[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
committed by Diogo Peralta Cordeiro
parent eb993df072
commit 26115482ef
73 changed files with 1130 additions and 756 deletions

View File

@@ -36,7 +36,7 @@ class Usage_stats extends Managed_DataObject
public $__table = 'usage_stats'; // table name
public $type; // varchar(191) unique_key not 255 because utf8mb4 takes more space
public $count; // int(4)
public $modified; // datetime() not_null default_CURRENT_TIMESTAMP
public $modified; // timestamp() not_null default_CURRENT_TIMESTAMP
/**
* Table Definition for usage_stats
@@ -50,7 +50,7 @@ class Usage_stats extends Managed_DataObject
'fields' => [
'type' => ['type' => 'varchar', 'not null' => true, 'length' => 191, 'description' => 'Type of countable entity'],
'count' => ['type' => 'int', 'size' => 'int', 'default' => 0, 'description' => 'Number of entities of this type'],
'modified' => ['type' => 'datetime', 'not null' => true, 'default' => 'CURRENT_TIMESTAMP', 'description' => 'date this record was modified'],
'modified' => ['type' => 'timestamp', 'not null' => true, 'description' => 'date this record was modified'],
],
'primary key' => ['type'],
'indexes' => [