-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
/
Comparator.php
56 lines (45 loc) · 1.48 KB
/
Comparator.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
<?php
namespace Doctrine\DBAL\Platforms\SQLServer;
use Doctrine\DBAL\Platforms\SQLServer2012Platform;
use Doctrine\DBAL\Schema\Comparator as BaseComparator;
use Doctrine\DBAL\Schema\Table;
/**
* Compares schemas in the context of SQL Server platform.
*
* @link https://docs.microsoft.com/en-us/sql/t-sql/statements/collations?view=sql-server-ver15
*/
class Comparator extends BaseComparator
{
/** @var string */
private $databaseCollation;
/**
* @internal The comparator can be only instantiated by a schema manager.
*/
public function __construct(SQLServer2012Platform $platform, string $databaseCollation)
{
parent::__construct($platform);
$this->databaseCollation = $databaseCollation;
}
/**
* {@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);
}
private function normalizeColumns(Table $table): void
{
foreach ($table->getColumns() as $column) {
$options = $column->getPlatformOptions();
if (! isset($options['collation']) || $options['collation'] !== $this->databaseCollation) {
continue;
}
unset($options['collation']);
$column->setPlatformOptions($options);
}
}
}