Bug Report
| Q |
A |
| BC Break |
yes |
| Version |
2.9.* |
Summary
I've tried to upgrade a project to DBAL 2.9.2 from 2.8.1, however the Doctrine bundle schema diff command constantly outputs schema changes. This is triggered as we've overloaded the default datetime type with datetime_immutable.
Current behaviour
Schema diff constantly generates the following query:
ALTER TABLE test CHANGE dt dt DATETIME NOT NULL COMMENT '(DC2Type:datetime_immutable)'
How to reproduce
Given schema:
CREATE TABLE test (dt DATETIME NOT NULL COMMENT '(DC2Type:datetime_immutable)') DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB;
Running the following, will exit 0 on 2.8.1 and error on 2.9.2.
<?php
use Doctrine\DBAL\Schema\Comparator;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\DBAL\Types\Type;
use Doctrine\DBAL\DriverManager;
require 'vendor/autoload.php';
Type::overrideType('datetime', \Doctrine\DBAL\Types\DateTimeImmutableType::class);
$conn = DriverManager::getConnection([
'url' => 'mysql://root@127.0.0.1:3306/main',
]);
$conn->connect();
$platform = $conn->getDatabasePlatform();
$schemaManager = $conn->getSchemaManager();
$schema1 = $schemaManager->createSchema();
$schema2 = new Schema();
$table2 = $schema2->createTable('test');
$table2->addColumn('dt', 'datetime');
$diff = Comparator::compareSchemas($schema1, $schema2)->toSql($platform);
var_dump($diff);
exit($diff === [] ? 0 : 1);
Expected behaviour
No update queries should be generated.
Patch
Cause: dca1465#diff-6a252b2e905db4e03fc6a121a41e6466L415
This fixes the problem, not entirely sure if this is the correct resolution though.
diff --git a/lib/Doctrine/DBAL/Schema/Comparator.php b/lib/Doctrine/DBAL/Schema/Comparator.php
index 8297e05..33ee482 100644
--- a/lib/Doctrine/DBAL/Schema/Comparator.php
+++ b/lib/Doctrine/DBAL/Schema/Comparator.php
@@ -11,6 +11,7 @@
use function array_shift;
use function array_unique;
use function count;
+use function get_class;
use function strtolower;
/**
@@ -419,7 +420,11 @@ public function diffColumn(Column $column1, Column $column2)
$changedProperties = [];
- foreach (['type', 'notnull', 'unsigned', 'autoincrement'] as $property) {
+ if (get_class($properties1['type']) !== get_class($properties2['type'])) {
+ $changedProperties[] = 'type';
+ }
+
+ foreach (['notnull', 'unsigned', 'autoincrement'] as $property) {
if ($properties1[$property] === $properties2[$property]) {
continue;
}
Bug Report
Summary
I've tried to upgrade a project to DBAL 2.9.2 from 2.8.1, however the Doctrine bundle schema diff command constantly outputs schema changes. This is triggered as we've overloaded the default
datetimetype withdatetime_immutable.Current behaviour
Schema diff constantly generates the following query:
How to reproduce
Given schema:
Running the following, will exit 0 on 2.8.1 and error on 2.9.2.
Expected behaviour
No update queries should be generated.
Patch
Cause: dca1465#diff-6a252b2e905db4e03fc6a121a41e6466L415
This fixes the problem, not entirely sure if this is the correct resolution though.