Skip to content

Commit

Permalink
Merge pull request #5861 from dmaicher/fix_mysql_comparator
Browse files Browse the repository at this point in the history
  • Loading branch information
greg0ire committed Jan 12, 2023
2 parents e106ee7 + 7af0e35 commit 88fa7e5
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 16 deletions.
9 changes: 9 additions & 0 deletions src/Platforms/MySQL/Comparator.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Doctrine\DBAL\Platforms\AbstractMySQLPlatform;
use Doctrine\DBAL\Schema\Comparator as BaseComparator;
use Doctrine\DBAL\Schema\Table;
use Doctrine\DBAL\Schema\TableDiff;

use function array_diff_assoc;
use function array_intersect_key;
Expand All @@ -29,6 +30,14 @@ public function __construct(AbstractMySQLPlatform $platform, CollationMetadataPr
$this->collationMetadataProvider = $collationMetadataProvider;
}

public function compareTables(Table $fromTable, Table $toTable): TableDiff
{
return parent::compareTables(
$this->normalizeColumns($fromTable),
$this->normalizeColumns($toTable),
);
}

/**
* {@inheritDoc}
*/
Expand Down
26 changes: 18 additions & 8 deletions src/Platforms/SQLServer/Comparator.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Doctrine\DBAL\Platforms\SQLServerPlatform;
use Doctrine\DBAL\Schema\Comparator as BaseComparator;
use Doctrine\DBAL\Schema\Table;
use Doctrine\DBAL\Schema\TableDiff;

/**
* Compares schemas in the context of SQL Server platform.
Expand All @@ -23,22 +24,29 @@ public function __construct(SQLServerPlatform $platform, string $databaseCollati
$this->databaseCollation = $databaseCollation;
}

public function compareTables(Table $fromTable, Table $toTable): TableDiff
{
return parent::compareTables(
$this->normalizeColumns($fromTable),
$this->normalizeColumns($toTable),
);
}

/**
* {@inheritDoc}
*/
public function diffTable(Table $fromTable, Table $toTable)
{
$fromTable = clone $fromTable;
$toTable = clone $toTable;

$this->normalizeColumns($fromTable);
$this->normalizeColumns($toTable);

return parent::diffTable($fromTable, $toTable);
return parent::diffTable(
$this->normalizeColumns($fromTable),
$this->normalizeColumns($toTable),
);
}

private function normalizeColumns(Table $table): void
private function normalizeColumns(Table $table): Table
{
$table = clone $table;

foreach ($table->getColumns() as $column) {
$options = $column->getPlatformOptions();

Expand All @@ -49,5 +57,7 @@ private function normalizeColumns(Table $table): void
unset($options['collation']);
$column->setPlatformOptions($options);
}

return $table;
}
}
26 changes: 18 additions & 8 deletions src/Platforms/SQLite/Comparator.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Doctrine\DBAL\Platforms\SqlitePlatform;
use Doctrine\DBAL\Schema\Comparator as BaseComparator;
use Doctrine\DBAL\Schema\Table;
use Doctrine\DBAL\Schema\TableDiff;

use function strcasecmp;

Expand All @@ -21,22 +22,29 @@ public function __construct(SqlitePlatform $platform)
parent::__construct($platform);
}

public function compareTables(Table $fromTable, Table $toTable): TableDiff
{
return parent::compareTables(
$this->normalizeColumns($fromTable),
$this->normalizeColumns($toTable),
);
}

/**
* {@inheritDoc}
*/
public function diffTable(Table $fromTable, Table $toTable)
{
$fromTable = clone $fromTable;
$toTable = clone $toTable;

$this->normalizeColumns($fromTable);
$this->normalizeColumns($toTable);

return parent::diffTable($fromTable, $toTable);
return parent::diffTable(
$this->normalizeColumns($fromTable),
$this->normalizeColumns($toTable),
);
}

private function normalizeColumns(Table $table): void
private function normalizeColumns(Table $table): Table
{
$table = clone $table;

foreach ($table->getColumns() as $column) {
$options = $column->getPlatformOptions();

Expand All @@ -47,5 +55,7 @@ private function normalizeColumns(Table $table): void
unset($options['collation']);
$column->setPlatformOptions($options);
}

return $table;
}
}

0 comments on commit 88fa7e5

Please sign in to comment.