Fixes #15167: Fixed loading of default value current_timestamp() for MariaDB >= 10.2.3

This commit is contained in:
Pavel Ivanov
2019-01-12 00:47:40 +02:00
committed by Alexander Makarov
parent c59df914c1
commit 7ccadb4a79
3 changed files with 40 additions and 1 deletions

View File

@ -61,4 +61,35 @@ SQL;
$result['4: check'][2] = false;
return $result;
}
/**
* When displayed in the INFORMATION_SCHEMA.COLUMNS table, a default CURRENT TIMESTAMP is displayed
* as CURRENT_TIMESTAMP up until MariaDB 10.2.2, and as current_timestamp() from MariaDB 10.2.3.
*
* @see https://mariadb.com/kb/en/library/now/#description
* @see https://github.com/yiisoft/yii2/issues/15167
*/
public function testAlternativeDisplayOfDefaultCurrentTimestampInMariaDB()
{
/**
* We do not have a real database MariaDB >= 10.2.3 for tests, so we emulate the information that database
* returns in response to the query `SHOW FULL COLUMNS FROM ...`
*/
$schema = new \yii\db\mysql\Schema();
$column = $this->invokeMethod($schema, 'loadColumnSchema', [[
'field' => 'emulated_MariaDB_field',
'type' => 'timestamp',
'collation' => NULL,
'null' => 'NO',
'key' => '',
'default' => 'current_timestamp()',
'extra' => '',
'privileges' => 'select,insert,update,references',
'comment' => '',
]]);
$this->assertInstanceOf(\yii\db\mysql\ColumnSchema::className(), $column);
$this->assertInstanceOf(Expression::className(), $column->defaultValue);
$this->assertEquals('CURRENT_TIMESTAMP', $column->defaultValue);
}
}