Skip to content

Commit a7c97ea

Browse files
committed
Fixed more errors
1 parent 3b51e17 commit a7c97ea

File tree

4 files changed

+62
-8
lines changed

4 files changed

+62
-8
lines changed

lib/Doctrine/DBAL/Schema/Comparator.php

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
use function array_unique;
1313
use function assert;
1414
use function count;
15+
use function strcasecmp;
1516
use function strtolower;
1617

1718
/**
@@ -259,7 +260,10 @@ public function diffTable(Table $table1, Table $table2)
259260
if ($this->diffForeignKey($constraint1, $constraint2) === false) {
260261
unset($fromFkeys[$key1], $toFkeys[$key2]);
261262
} else {
262-
if (strtolower($constraint1->getName()) === strtolower($constraint2->getName())) {
263+
$name1 = $constraint1->getName();
264+
$name2 = $constraint2->getName();
265+
266+
if ($name1 !== null && $name2 !== null && strcasecmp($name1, $name2) === 0) {
263267
$tableDifferences->changedForeignKeys[] = $constraint2;
264268
$changes++;
265269
unset($fromFkeys[$key1], $toFkeys[$key2]);
@@ -349,8 +353,20 @@ private function detectIndexRenamings(TableDiff $tableDifferences) : void
349353

350354
[$removedIndex, $addedIndex] = $candidateIndexes[0];
351355

352-
$removedIndexName = strtolower($removedIndex->getName());
353-
$addedIndexName = strtolower($addedIndex->getName());
356+
$removedIndexName = $removedIndex->getName();
357+
358+
if ($removedIndexName === null) {
359+
continue;
360+
}
361+
362+
$addedIndexName = $addedIndex->getName();
363+
364+
if ($addedIndexName === null) {
365+
continue;
366+
}
367+
368+
$removedIndexName = strtolower($removedIndexName);
369+
$addedIndexName = strtolower($addedIndexName);
354370

355371
if (isset($tableDifferences->renamedIndexes[$removedIndexName])) {
356372
continue;

lib/Doctrine/DBAL/Schema/SchemaException.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,17 @@ public static function namedForeignKeyRequired(Table $localTable, ForeignKeyCons
116116
);
117117
}
118118

119+
public static function namedIndexRequired(Table $table, Index $index) : self
120+
{
121+
return new self(
122+
sprintf(
123+
'The performed schema operation on %s requires a named index, but the given index on (%s) is currently unnamed.',
124+
$table->getName(),
125+
implode(', ', $index->getColumns())
126+
)
127+
);
128+
}
129+
119130
public static function alterTableChangeNotSupported(string $changeName) : self
120131
{
121132
return new self(

lib/Doctrine/DBAL/Schema/Visitor/RemoveNamespacedAssets.php

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use Doctrine\DBAL\Schema\ForeignKeyConstraint;
66
use Doctrine\DBAL\Schema\Schema;
7+
use Doctrine\DBAL\Schema\SchemaException;
78
use Doctrine\DBAL\Schema\Sequence;
89
use Doctrine\DBAL\Schema\Table;
910

@@ -57,14 +58,17 @@ public function acceptSequence(Sequence $sequence) : void
5758

5859
/**
5960
* {@inheritdoc}
61+
*
62+
* @throws SchemaException
6063
*/
6164
public function acceptForeignKey(Table $localTable, ForeignKeyConstraint $fkConstraint) : void
6265
{
6366
// The table may already be deleted in a previous
6467
// RemoveNamespacedAssets#acceptTable call. Removing Foreign keys that
6568
// point to nowhere.
6669
if (! $this->schema->hasTable($fkConstraint->getForeignTableName())) {
67-
$localTable->removeForeignKey($fkConstraint->getName());
70+
$this->removeForeignKey($localTable, $fkConstraint);
71+
6872
return;
6973
}
7074

@@ -73,6 +77,20 @@ public function acceptForeignKey(Table $localTable, ForeignKeyConstraint $fkCons
7377
return;
7478
}
7579

76-
$localTable->removeForeignKey($fkConstraint->getName());
80+
$this->removeForeignKey($localTable, $fkConstraint);
81+
}
82+
83+
/**
84+
* @throws SchemaException
85+
*/
86+
private function removeForeignKey(Table $table, ForeignKeyConstraint $constraint) : void
87+
{
88+
$name = $constraint->getName();
89+
90+
if ($name === null) {
91+
throw SchemaException::namedForeignKeyRequired($table, $constraint);
92+
}
93+
94+
$table->removeForeignKey($name);
7795
}
7896
}

lib/Doctrine/DBAL/Sharding/SQLAzure/Schema/MultiTenantVisitor.php

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
use Doctrine\DBAL\Schema\ForeignKeyConstraint;
77
use Doctrine\DBAL\Schema\Index;
88
use Doctrine\DBAL\Schema\Schema;
9+
use Doctrine\DBAL\Schema\SchemaException;
910
use Doctrine\DBAL\Schema\Sequence;
1011
use Doctrine\DBAL\Schema\Table;
1112
use Doctrine\DBAL\Schema\Visitor\Visitor;
@@ -62,6 +63,8 @@ public function __construct(array $excludedTables = [], string $tenantColumnName
6263

6364
/**
6465
* {@inheritdoc}
66+
*
67+
* @throws SchemaException
6568
*/
6669
public function acceptTable(Table $table) : void
6770
{
@@ -82,9 +85,15 @@ public function acceptTable(Table $table) : void
8285
$table->dropPrimaryKey();
8386
$table->setPrimaryKey($indexColumns);
8487
} else {
85-
$table->dropIndex($clusteredIndex->getName());
86-
$table->addIndex($indexColumns, $clusteredIndex->getName());
87-
$table->getIndex($clusteredIndex->getName())->addFlag('clustered');
88+
$name = $clusteredIndex->getName();
89+
90+
if ($name === null) {
91+
throw SchemaException::namedIndexRequired($table, $clusteredIndex);
92+
}
93+
94+
$table->dropIndex($name);
95+
$table->addIndex($indexColumns, $name);
96+
$table->getIndex($name)->addFlag('clustered');
8897
}
8998
}
9099

0 commit comments

Comments
 (0)