| 148 |
lars |
1 |
<?php
|
|
|
2 |
|
|
|
3 |
namespace Doctrine\DBAL\Platforms\SQLite;
|
|
|
4 |
|
|
|
5 |
use Doctrine\DBAL\Platforms\SqlitePlatform;
|
|
|
6 |
use Doctrine\DBAL\Schema\Comparator as BaseComparator;
|
|
|
7 |
use Doctrine\DBAL\Schema\Table;
|
|
|
8 |
use Doctrine\DBAL\Schema\TableDiff;
|
|
|
9 |
|
|
|
10 |
use function strcasecmp;
|
|
|
11 |
|
|
|
12 |
/**
|
|
|
13 |
* Compares schemas in the context of SQLite platform.
|
|
|
14 |
*
|
|
|
15 |
* BINARY is the default column collation and should be ignored if specified explicitly.
|
|
|
16 |
*/
|
|
|
17 |
class Comparator extends BaseComparator
|
|
|
18 |
{
|
|
|
19 |
/** @internal The comparator can be only instantiated by a schema manager. */
|
|
|
20 |
public function __construct(SqlitePlatform $platform)
|
|
|
21 |
{
|
|
|
22 |
parent::__construct($platform);
|
|
|
23 |
}
|
|
|
24 |
|
|
|
25 |
public function compareTables(Table $fromTable, Table $toTable): TableDiff
|
|
|
26 |
{
|
|
|
27 |
return parent::compareTables(
|
|
|
28 |
$this->normalizeColumns($fromTable),
|
|
|
29 |
$this->normalizeColumns($toTable),
|
|
|
30 |
);
|
|
|
31 |
}
|
|
|
32 |
|
|
|
33 |
/**
|
|
|
34 |
* {@inheritDoc}
|
|
|
35 |
*/
|
|
|
36 |
public function diffTable(Table $fromTable, Table $toTable)
|
|
|
37 |
{
|
|
|
38 |
return parent::diffTable(
|
|
|
39 |
$this->normalizeColumns($fromTable),
|
|
|
40 |
$this->normalizeColumns($toTable),
|
|
|
41 |
);
|
|
|
42 |
}
|
|
|
43 |
|
|
|
44 |
private function normalizeColumns(Table $table): Table
|
|
|
45 |
{
|
|
|
46 |
$table = clone $table;
|
|
|
47 |
|
|
|
48 |
foreach ($table->getColumns() as $column) {
|
|
|
49 |
$options = $column->getPlatformOptions();
|
|
|
50 |
|
|
|
51 |
if (! isset($options['collation']) || strcasecmp($options['collation'], 'binary') !== 0) {
|
|
|
52 |
continue;
|
|
|
53 |
}
|
|
|
54 |
|
|
|
55 |
unset($options['collation']);
|
|
|
56 |
$column->setPlatformOptions($options);
|
|
|
57 |
}
|
|
|
58 |
|
|
|
59 |
return $table;
|
|
|
60 |
}
|
|
|
61 |
}
|