From 95dd2db45f69ff1d7fe9e6ba9fddfaeff324ba09 Mon Sep 17 00:00:00 2001 From: Zach Nanninga Date: Mon, 16 Nov 2020 12:56:44 -0600 Subject: [PATCH 1/2] ISSUE-30304 - Create a distinct class for index removal during schema operations processing. Mark it as non-destructive so it's not dependent on whitelist json. --- app/etc/di.xml | 1 + .../Declaration/Schema/Diff/DiffManager.php | 4 + .../Schema/Operations/DropIndex.php | 79 +++++++++++++++++++ 3 files changed, 84 insertions(+) create mode 100644 lib/internal/Magento/Framework/Setup/Declaration/Schema/Operations/DropIndex.php diff --git a/app/etc/di.xml b/app/etc/di.xml index d4651499e6fce..d8908814960f6 100644 --- a/app/etc/di.xml +++ b/app/etc/di.xml @@ -1555,6 +1555,7 @@ Magento\Framework\Setup\Declaration\Schema\Operations\ModifyColumn Magento\Framework\Setup\Declaration\Schema\Operations\AddColumn Magento\Framework\Setup\Declaration\Schema\Operations\DropElement + Magento\Framework\Setup\Declaration\Schema\Operations\DropIndex Magento\Framework\Setup\Declaration\Schema\Operations\AddComplexElement Magento\Framework\Setup\Declaration\Schema\Operations\ModifyTable diff --git a/lib/internal/Magento/Framework/Setup/Declaration/Schema/Diff/DiffManager.php b/lib/internal/Magento/Framework/Setup/Declaration/Schema/Diff/DiffManager.php index af1a35542603e..4b65d9b27bc38 100644 --- a/lib/internal/Magento/Framework/Setup/Declaration/Schema/Diff/DiffManager.php +++ b/lib/internal/Magento/Framework/Setup/Declaration/Schema/Diff/DiffManager.php @@ -10,11 +10,13 @@ use Magento\Framework\Setup\Declaration\Schema\Dto\Column; use Magento\Framework\Setup\Declaration\Schema\Dto\Constraints\Reference; use Magento\Framework\Setup\Declaration\Schema\Dto\ElementInterface; +use Magento\Framework\Setup\Declaration\Schema\Dto\Index; use Magento\Framework\Setup\Declaration\Schema\Dto\Table; use Magento\Framework\Setup\Declaration\Schema\Operations\AddColumn; use Magento\Framework\Setup\Declaration\Schema\Operations\AddComplexElement; use Magento\Framework\Setup\Declaration\Schema\Operations\CreateTable; use Magento\Framework\Setup\Declaration\Schema\Operations\DropElement; +use Magento\Framework\Setup\Declaration\Schema\Operations\DropIndex; use Magento\Framework\Setup\Declaration\Schema\Operations\DropReference; use Magento\Framework\Setup\Declaration\Schema\Operations\DropTable; use Magento\Framework\Setup\Declaration\Schema\Operations\ModifyColumn; @@ -107,6 +109,8 @@ public function registerRemoval( $diff->register($generatedElement, DropReference::OPERATION_NAME, $generatedElement); } elseif ($generatedElement instanceof Table) { $diff->register($generatedElement, DropTable::OPERATION_NAME, $generatedElement); + } elseif ($generatedElement instanceof Index) { + $diff->register($generatedElement, DropIndex::OPERATION_NAME, $generatedElement); } else { $diff->register($generatedElement, DropElement::OPERATION_NAME, $generatedElement); } diff --git a/lib/internal/Magento/Framework/Setup/Declaration/Schema/Operations/DropIndex.php b/lib/internal/Magento/Framework/Setup/Declaration/Schema/Operations/DropIndex.php new file mode 100644 index 0000000000000..f29b12700af82 --- /dev/null +++ b/lib/internal/Magento/Framework/Setup/Declaration/Schema/Operations/DropIndex.php @@ -0,0 +1,79 @@ +dbSchemaWriter = $dbSchemaWriter; + } + + /** + * {@inheritdoc} + */ + public function getOperationName() + { + return self::OPERATION_NAME; + } + + /** + * {@inheritdoc} + */ + public function isOperationDestructive() + { + return false; + } + + /** + * {@inheritdoc} + */ + public function doOperation(ElementHistory $elementHistory) + { + /** + * @var TableElementInterface | ElementInterface $element + */ + $element = $elementHistory->getNew(); + + return [ + $this->dbSchemaWriter->dropElement( + $element->getTable()->getResource(), + $element->getName(), + $element->getTable()->getName(), + $element->getType() + ) + ]; + } +} From 7960fee41817cc9c94723dac40635cc01efffbc0 Mon Sep 17 00:00:00 2001 From: Zach Nanninga Date: Wed, 18 Nov 2020 09:30:54 -0600 Subject: [PATCH 2/2] ISSUE-30304 - Update unit test with correct operation name. Add visibility to drop index operation constant. --- .../Framework/Setup/Declaration/Schema/Operations/DropIndex.php | 2 +- .../Setup/Test/Unit/Declaration/Schema/Diff/DiffManagerTest.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/internal/Magento/Framework/Setup/Declaration/Schema/Operations/DropIndex.php b/lib/internal/Magento/Framework/Setup/Declaration/Schema/Operations/DropIndex.php index f29b12700af82..37488378b3f82 100644 --- a/lib/internal/Magento/Framework/Setup/Declaration/Schema/Operations/DropIndex.php +++ b/lib/internal/Magento/Framework/Setup/Declaration/Schema/Operations/DropIndex.php @@ -23,7 +23,7 @@ class DropIndex implements OperationInterface /** * Operation name. */ - const OPERATION_NAME = 'drop_index'; + public const OPERATION_NAME = 'drop_index'; /** * @var DbSchemaWriterInterface diff --git a/lib/internal/Magento/Framework/Setup/Test/Unit/Declaration/Schema/Diff/DiffManagerTest.php b/lib/internal/Magento/Framework/Setup/Test/Unit/Declaration/Schema/Diff/DiffManagerTest.php index 016aff1bfe7c8..edd1e2b071384 100644 --- a/lib/internal/Magento/Framework/Setup/Test/Unit/Declaration/Schema/Diff/DiffManagerTest.php +++ b/lib/internal/Magento/Framework/Setup/Test/Unit/Declaration/Schema/Diff/DiffManagerTest.php @@ -116,7 +116,7 @@ public function testRegisterIndexModification() $generatedIndex = new Index('index_type', 'index', $table, [$column], 'hash', 'index_type'); $diff->expects(self::exactly(2)) ->method('register') - ->withConsecutive([$generatedIndex, 'drop_element', $generatedIndex], [$index, 'add_complex_element']); + ->withConsecutive([$generatedIndex, 'drop_index', $generatedIndex], [$index, 'add_complex_element']); $this->model->registerModification($diff, $index, $generatedIndex); }