|
@@ 316-340 (lines=25) @@
|
| 313 |
|
* |
| 314 |
|
* @return void |
| 315 |
|
*/ |
| 316 |
|
private function detectColumnRenamings(TableDiff $tableDifferences) |
| 317 |
|
{ |
| 318 |
|
$renameCandidates = []; |
| 319 |
|
foreach ($tableDifferences->addedColumns as $addedColumnName => $addedColumn) { |
| 320 |
|
foreach ($tableDifferences->removedColumns as $removedColumn) { |
| 321 |
|
if (count($this->diffColumn($addedColumn, $removedColumn)) == 0) { |
| 322 |
|
$renameCandidates[$addedColumn->getName()][] = [$removedColumn, $addedColumn, $addedColumnName]; |
| 323 |
|
} |
| 324 |
|
} |
| 325 |
|
} |
| 326 |
|
|
| 327 |
|
foreach ($renameCandidates as $candidateColumns) { |
| 328 |
|
if (count($candidateColumns) == 1) { |
| 329 |
|
list($removedColumn, $addedColumn) = $candidateColumns[0]; |
| 330 |
|
$removedColumnName = strtolower($removedColumn->getName()); |
| 331 |
|
$addedColumnName = strtolower($addedColumn->getName()); |
| 332 |
|
|
| 333 |
|
if ( ! isset($tableDifferences->renamedColumns[$removedColumnName])) { |
| 334 |
|
$tableDifferences->renamedColumns[$removedColumnName] = $addedColumn; |
| 335 |
|
unset($tableDifferences->addedColumns[$addedColumnName]); |
| 336 |
|
unset($tableDifferences->removedColumns[$removedColumnName]); |
| 337 |
|
} |
| 338 |
|
} |
| 339 |
|
} |
| 340 |
|
} |
| 341 |
|
|
| 342 |
|
/** |
| 343 |
|
* Try to find indexes that only changed their name, rename operations maybe cheaper than add/drop |
|
@@ 350-381 (lines=32) @@
|
| 347 |
|
* |
| 348 |
|
* @return void |
| 349 |
|
*/ |
| 350 |
|
private function detectIndexRenamings(TableDiff $tableDifferences) |
| 351 |
|
{ |
| 352 |
|
$renameCandidates = []; |
| 353 |
|
|
| 354 |
|
// Gather possible rename candidates by comparing each added and removed index based on semantics. |
| 355 |
|
foreach ($tableDifferences->addedIndexes as $addedIndexName => $addedIndex) { |
| 356 |
|
foreach ($tableDifferences->removedIndexes as $removedIndex) { |
| 357 |
|
if (! $this->diffIndex($addedIndex, $removedIndex)) { |
| 358 |
|
$renameCandidates[$addedIndex->getName()][] = [$removedIndex, $addedIndex, $addedIndexName]; |
| 359 |
|
} |
| 360 |
|
} |
| 361 |
|
} |
| 362 |
|
|
| 363 |
|
foreach ($renameCandidates as $candidateIndexes) { |
| 364 |
|
// If the current rename candidate contains exactly one semantically equal index, |
| 365 |
|
// we can safely rename it. |
| 366 |
|
// Otherwise it is unclear if a rename action is really intended, |
| 367 |
|
// therefore we let those ambiguous indexes be added/dropped. |
| 368 |
|
if (count($candidateIndexes) === 1) { |
| 369 |
|
list($removedIndex, $addedIndex) = $candidateIndexes[0]; |
| 370 |
|
|
| 371 |
|
$removedIndexName = strtolower($removedIndex->getName()); |
| 372 |
|
$addedIndexName = strtolower($addedIndex->getName()); |
| 373 |
|
|
| 374 |
|
if (! isset($tableDifferences->renamedIndexes[$removedIndexName])) { |
| 375 |
|
$tableDifferences->renamedIndexes[$removedIndexName] = $addedIndex; |
| 376 |
|
unset($tableDifferences->addedIndexes[$addedIndexName]); |
| 377 |
|
unset($tableDifferences->removedIndexes[$removedIndexName]); |
| 378 |
|
} |
| 379 |
|
} |
| 380 |
|
} |
| 381 |
|
} |
| 382 |
|
|
| 383 |
|
/** |
| 384 |
|
* @param \Doctrine\DBAL\Schema\ForeignKeyConstraint $key1 |