-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Description
Bug Report
| Q | A |
|---|---|
| Version | 4.2.2 |
Summary
When performing SchemaDiff between two schemas and then generating SQL statements that will represent the same schema diff performed, type TIMESTAMP(N) is replaced with DATETIME.
Current behavior
The current behavior is that the migrating SQL statement determines the wrong type of the column. I have a type timestamp(6) and the default value for this column current_timestamp(6). When executing the following code:
$comparator = $fromSchemaManager->createComparator();
$schemaDiff = $comparator->compareSchemas($fromSchemaManager->introspectSchema(), $toSchemamanager->introspectSchema());$alterSchemaSQL = $platform->getAlterSchemaSQL($schemaDiff);In the alterSchemaSQL there is a query that looks like (I omitted unrelevant columns):
CREATE TABLE test (
id INT UNSIGNED AUTO_INCREMENT NOT NULL,
time DATETIME DEFAULT 'current_timestamp(6)' NOT NULL,
PRIMARY KEY (id)
) The query won't even execute.
Expected behavior
It executes if I remove ' around current_timestamp(6), but then the default value turns to be just current_timestamp(). Only when I rewrite the query as:
CREATE TABLE test (
id INT UNSIGNED AUTO_INCREMENT NOT NULL,
time TIMESTAMP(6) DEFAULT current_timestamp(6) NOT NULL,
PRIMARY KEY (id)
) It executes and the table has all columns with expected properties.
How to reproduce
The code I'm executing:
$fromConn = DriverManager::getConnection([
'dbname' => 'test_db',
'user' => 'root',
'password' => 'root',
'host' => 'localhost',
'port' => 3306,
'driver' => 'mysqli',
]);
$toConn = DriverManager::getConnection([
'dbname' => 'test_db2',
'user' => 'root',
'password' => 'root',
'host' => 'localhost',
'port' => 3306,
'driver' => 'mysqli',
]);
$fromSchemaManager = $fromConn->createSchemaManager();
$toSchemaManager = $toConn->createSchemaManager();
$platform = $toConn->getDatabasePlatform();
$comparator = $fromSchemaManager->createComparator();
$schemaDiff = $comparator->compareSchemas($fromSchemaManager->introspectSchema(), $toSchemamanager->introspectSchema());
$alterSchemaSQL = $platform->getAlterSchemaSQL($schemaDiff);
foreach ($alterSchemaSQL as $v) {
echo $v . "\n";
}