Skip to content

Commit 0304a7c

Browse files
committed
Merge branch '4.4.x' into 5.0.x
2 parents c1f4e8b + e07f21d commit 0304a7c

File tree

11 files changed

+69
-28
lines changed

11 files changed

+69
-28
lines changed

UPGRADE.md

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -360,10 +360,26 @@ all drivers and middleware.
360360

361361
# Upgrade to 4.4
362362

363+
## Deprecated extension of schema classes
364+
365+
Extending the following classes has been deprecated. Use them directly.
366+
367+
- `Schema`
368+
- `Sequence`
369+
- `Table`
370+
- `View`
371+
372+
## Deprecated features of `Table::getIndexes()`, `Table::getUniqueConstraints()` and `Table::getForeignKeys()`
373+
374+
Using the keys of the arrays returned by `Table::getIndexes()`, `Table::getUniqueConstraints()` and
375+
`Table::getForeignKeys()` as index or constraint names is deprecated. Instead, retrieve the name from the index or
376+
constraint object using `NamedObject::getObjectName()` or `OptionallyNamedObject::getObjectName()`. In order to retrieve
377+
an object by name, use `Table::getIndex()`, `Table::getUniqueConstraint()` or `Table::getForeignKey()` respectively.
378+
363379
## Deprecated `AbstractAsset::getName()`
364380

365381
The `AbstractAsset::getName()` method has been deprecated. Instead, use `NamedObject::getObjectName()` or
366-
`OptionallyQualifiedName::getObjectName()` to get the object representation of the name. SQL context, convert the
382+
`OptionallyQualifiedName::getObjectName()` to get the object representation of the name. In SQL context, convert the
367383
resulting `Name` to SQL using `Name::toSQL()`. In other contexts, convert the resulting name to string using
368384
`Name::toString()`.
369385

src/Platforms/SQLitePlatform.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -803,8 +803,9 @@ private function getIndexesInAlteredTable(TableDiff $diff): array
803803
$nameMap = $this->getDiffColumnNameMap($diff);
804804

805805
foreach ($indexes as $key => $index) {
806+
$indexName = $index->getObjectName()->getIdentifier()->getValue();
806807
foreach ($diff->getRenamedIndexes() as $oldIndexName => $renamedIndex) {
807-
if (strtolower($key) !== strtolower($oldIndexName)) {
808+
if (strtolower($indexName) !== strtolower($oldIndexName)) {
808809
continue;
809810
}
810811

src/Schema/Collections/ObjectSet.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,17 @@
77
use Doctrine\DBAL\Schema\Collections\Exception\ObjectAlreadyExists;
88
use Doctrine\DBAL\Schema\Collections\Exception\ObjectDoesNotExist;
99
use Doctrine\DBAL\Schema\Name\UnqualifiedName;
10+
use IteratorAggregate;
1011

1112
/**
1213
* A set of objects where each object is uniquely identified by its {@link UnqualifiedName}.
1314
*
1415
* @internal
1516
*
1617
* @template E of object
18+
* @template-extends IteratorAggregate<int, E>
1719
*/
18-
interface ObjectSet
20+
interface ObjectSet extends IteratorAggregate
1921
{
2022
/**
2123
* Checks if the set is empty.

src/Schema/Collections/OptionallyUnqualifiedNamedObjectSet.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use Doctrine\DBAL\Schema\Collections\Exception\ObjectDoesNotExist;
99
use Doctrine\DBAL\Schema\Name\UnqualifiedName;
1010
use Doctrine\DBAL\Schema\OptionallyNamedObject;
11+
use Traversable;
1112

1213
use function array_splice;
1314
use function count;
@@ -110,6 +111,12 @@ public function toList(): array
110111
return $this->elements;
111112
}
112113

114+
/** {@inheritDoc} */
115+
public function getIterator(): Traversable
116+
{
117+
yield from $this->elements;
118+
}
119+
113120
/**
114121
* Replaces the element corresponding to the old key with the provided element.
115122
*

src/Schema/Collections/UnqualifiedNamedObjectSet.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use Doctrine\DBAL\Schema\Collections\Exception\ObjectDoesNotExist;
99
use Doctrine\DBAL\Schema\Name\UnqualifiedName;
1010
use Doctrine\DBAL\Schema\NamedObject;
11+
use Traversable;
1112

1213
use function array_combine;
1314
use function array_keys;
@@ -97,6 +98,14 @@ public function toList(): array
9798
return array_values($this->elements);
9899
}
99100

101+
/** {@inheritDoc} */
102+
public function getIterator(): Traversable
103+
{
104+
foreach ($this->elements as $element) {
105+
yield $element;
106+
}
107+
}
108+
100109
/**
101110
* Replaces the element corresponding to the old key with the provided element. The position of the element in the
102111
* set is preserved.

src/Schema/Comparator.php

Lines changed: 24 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -228,31 +228,35 @@ public function compareTables(Table $oldTable, Table $newTable): TableDiff
228228
$folding = $this->platform->getUnquotedIdentifierFolding();
229229

230230
// See if all the indexes from the old table exist in the new one
231-
foreach ($newIndexes as $newIndexName => $newIndex) {
232-
if ($oldTable->hasIndex($newIndexName)) {
231+
foreach ($newIndexes as $newIndex) {
232+
$newIndexName = $newIndex->getObjectName();
233+
234+
if ($oldTable->hasIndex($newIndexName->toString())) {
233235
continue;
234236
}
235237

236-
$addedIndexes[$newIndexName] = $newIndex;
238+
$addedIndexes[] = $newIndex;
237239
}
238240

239241
// See if there are any removed indexes in the new table
240-
foreach ($oldIndexes as $oldIndexName => $oldIndex) {
241-
if (! $newTable->hasIndex($oldIndexName)) {
242-
$droppedIndexes[$oldIndexName] = $oldIndex;
242+
foreach ($oldIndexes as $oldIndex) {
243+
$oldIndexName = $oldIndex->getObjectName();
244+
245+
if (! $newTable->hasIndex($oldIndexName->toString())) {
246+
$droppedIndexes[] = $oldIndex;
243247

244248
continue;
245249
}
246250

247251
// See if index has changed in the new table.
248-
$newIndex = $newTable->getIndex($oldIndexName);
252+
$newIndex = $newTable->getIndex($oldIndexName->toString());
249253

250254
if ($oldIndex->equals($newIndex, $folding)) {
251255
continue;
252256
}
253257

254-
$droppedIndexes[$oldIndexName] = $oldIndex;
255-
$addedIndexes[$oldIndexName] = $newIndex;
258+
$droppedIndexes[] = $oldIndex;
259+
$addedIndexes[] = $newIndex;
256260
}
257261

258262
if ($this->config->getDetectRenamedIndexes()) {
@@ -376,8 +380,8 @@ private function primaryKeyConstraintsEqual(
376380
* Try to find indexes that only changed their name, rename operations maybe cheaper than add/drop
377381
* however ambiguities between different possibilities should not lead to renaming at all.
378382
*
379-
* @param array<string,Index> $addedIndexes
380-
* @param array<string,Index> $removedIndexes
383+
* @param array<Index> $addedIndexes
384+
* @param array<Index> $removedIndexes
381385
*
382386
* @return array<string,Index>
383387
*/
@@ -389,15 +393,15 @@ private function detectRenamedIndexes(
389393
$candidatesByName = [];
390394

391395
// Gather possible rename candidates by comparing each added and removed index based on semantics.
392-
foreach ($addedIndexes as $addedIndexName => $addedIndex) {
393-
foreach ($removedIndexes as $removedIndex) {
396+
foreach ($addedIndexes as $addedIndexKey => $addedIndex) {
397+
foreach ($removedIndexes as $removedIndexKey => $removedIndex) {
394398
if (! $addedIndex->equals($removedIndex, $folding)) {
395399
continue;
396400
}
397401

398402
$candidatesByName[$addedIndex->getObjectName()
399403
->getIdentifier()
400-
->getValue()][] = [$removedIndex, $addedIndex, $addedIndexName];
404+
->getValue()][] = [$removedIndexKey, $addedIndexKey];
401405
}
402406
}
403407

@@ -412,28 +416,25 @@ private function detectRenamedIndexes(
412416
continue;
413417
}
414418

415-
[$removedIndex, $addedIndex] = $candidates[0];
419+
[$removedIndexKey, $addedIndexKey] = $candidates[0];
416420

421+
$removedIndex = $removedIndexes[$removedIndexKey];
417422
$removedIndexName = strtolower(
418423
$removedIndex->getObjectName()
419424
->getIdentifier()
420425
->getValue(),
421426
);
422427

423-
$addedIndexName = strtolower(
424-
$addedIndex->getObjectName()
425-
->getIdentifier()
426-
->getValue(),
427-
);
428-
429428
if (isset($renamedIndexes[$removedIndexName])) {
430429
continue;
431430
}
432431

432+
$addedIndex = $addedIndexes[$addedIndexKey];
433+
433434
$renamedIndexes[$removedIndexName] = $addedIndex;
434435
unset(
435-
$addedIndexes[$addedIndexName],
436-
$removedIndexes[$removedIndexName],
436+
$addedIndexes[$addedIndexKey],
437+
$removedIndexes[$removedIndexKey],
437438
);
438439
}
439440

src/Schema/Schema.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@
5353
* the CREATE/DROP SQL visitors will just filter this queries and do not
5454
* execute them. Only the queries for the currently connected database are
5555
* executed.
56+
*
57+
* @final
5658
*/
5759
class Schema
5860
{

src/Schema/Sequence.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
/**
1313
* Sequence structure.
1414
*
15+
* @final
1516
* @extends AbstractNamedObject<OptionallyQualifiedName>
1617
*/
1718
class Sequence extends AbstractNamedObject

src/Schema/Table.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
/**
4949
* Object Representation of a table.
5050
*
51+
* @final
5152
* @extends AbstractNamedObject<OptionallyQualifiedName>
5253
*/
5354
class Table extends AbstractNamedObject

src/Schema/TableEditor.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ public function renameColumn(UnqualifiedName $oldColumnName, UnqualifiedName $ne
156156

157157
private function renameColumnInIndexes(UnqualifiedName $oldColumnName, UnqualifiedName $newColumnName): void
158158
{
159-
foreach ($this->indexes->toList() as $index) {
159+
foreach ($this->indexes as $index) {
160160
$modified = false;
161161
$columns = [];
162162

@@ -264,7 +264,7 @@ private function renameColumnInConstraints(
264264
$constraints = [];
265265
$anyModified = false;
266266

267-
foreach ($collection->toList() as $constraint) {
267+
foreach ($collection as $constraint) {
268268
$newColumnNames = [];
269269
$modified = false;
270270

0 commit comments

Comments
 (0)