blob: f27e1b4571c883a9cf8e74e29ed06c4af10dd340 (
plain)
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
|
<?php
declare(strict_types=1);
namespace Doctrine\DBAL\Platforms\SQLite;
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;
/**
* Compares schemas in the context of SQLite platform.
*
* BINARY is the default column collation and should be ignored if specified explicitly.
*/
class Comparator extends BaseComparator
{
/** @internal The comparator can be only instantiated by a schema manager. */
public function __construct(SQLitePlatform $platform)
{
parent::__construct($platform);
}
public function compareTables(Table $oldTable, Table $newTable): TableDiff
{
return parent::compareTables(
$this->normalizeColumns($oldTable),
$this->normalizeColumns($newTable),
);
}
private function normalizeColumns(Table $table): Table
{
$table = clone $table;
foreach ($table->getColumns() as $column) {
$options = $column->getPlatformOptions();
if (! isset($options['collation']) || strcasecmp($options['collation'], 'binary') !== 0) {
continue;
}
unset($options['collation']);
$column->setPlatformOptions($options);
}
return $table;
}
}
|