X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=lib%2Fmysqlschema.php;h=e284d1eb1851542ff573aff36cc77745f80b710b;hb=586fb5a5175d7a10f5f78dd026434e48202e5451;hp=30c808ab3d83981395dcb94610645b251f545c4e;hpb=dd8e17a3874aa99063b62b51e9a637a5abb0b923;p=quix0rs-gnu-social.git diff --git a/lib/mysqlschema.php b/lib/mysqlschema.php index 30c808ab3d..e284d1eb18 100644 --- a/lib/mysqlschema.php +++ b/lib/mysqlschema.php @@ -271,7 +271,7 @@ class MysqlSchema extends Schema $engine = $this->preferredEngine($def); return ") ENGINE=$engine CHARACTER SET utf8mb4 COLLATE utf8mb4_bin"; } - + function preferredEngine($def) { /* MyISAM is no longer required for fulltext indexes, fortunately @@ -386,7 +386,7 @@ class MysqlSchema extends Schema $map = array('serial' => 'int', 'integer' => 'int', 'numeric' => 'decimal'); - + $type = $column['type']; if (isset($map[$type])) { $type = $map[$type]; @@ -436,13 +436,32 @@ class MysqlSchema extends Schema */ function filterDef(array $tableDef) { + $version = $this->conn->getVersion(); foreach ($tableDef['fields'] as $name => &$col) { if ($col['type'] == 'serial') { $col['type'] = 'int'; $col['auto_increment'] = true; } - if ($col['type'] == 'datetime' && isset($col['default']) && $col['default'] == 'CURRENT_TIMESTAMP') { - $col['type'] = 'timestamp'; + + // Avoid invalid date errors in MySQL 5.7+ + if ($col['type'] == 'timestamp' && !isset($col['default']) + && $version >= 50605) { + $col['default'] = 'CURRENT_TIMESTAMP'; + } + if ($col['type'] == 'datetime') { + // Avoid invalid date errors in MySQL 5.7+ + if (!isset($col['default']) && $version >= 50605) { + $col['default'] = 'CURRENT_TIMESTAMP'; + } + + // If we are using MySQL 5.5, convert datetime to timestamp if + // default value is CURRENT_TIMESTAMP. Not needed for MySQL 5.6+ + // and MariaDB 10.0+ + if (isset($col['default']) + && $col['default'] == 'CURRENT_TIMESTAMP' + && $version < 50605) { + $col['type'] = 'timestamp'; + } } $col['type'] = $this->mapType($col); unset($col['size']);