From 5356484ae46e270f4e10f6dee453d9f28c83c2da Mon Sep 17 00:00:00 2001 From: Jacques Bodin-Hullin Date: Wed, 15 Sep 2021 23:05:20 +0200 Subject: [PATCH] On shipment deletion cascade slot deletion & remove orphan slots. --- src/Migrations/Version20210915210206.php | 38 ++++++++++++++++++++++ src/Resources/config/doctrine/Slot.orm.xml | 2 +- 2 files changed, 39 insertions(+), 1 deletion(-) create mode 100644 src/Migrations/Version20210915210206.php diff --git a/src/Migrations/Version20210915210206.php b/src/Migrations/Version20210915210206.php new file mode 100644 index 0000000..3076023 --- /dev/null +++ b/src/Migrations/Version20210915210206.php @@ -0,0 +1,38 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +declare(strict_types=1); + +namespace MonsieurBiz\SyliusShippingSlotPlugin\Migrations; + +use Doctrine\DBAL\Schema\Schema; +use Doctrine\Migrations\AbstractMigration; + +final class Version20210915210206 extends AbstractMigration +{ + public function getDescription(): string + { + return 'Cascade shipment deletion to slot deletion. Also remove slots without shipment.'; + } + + public function up(Schema $schema): void + { + $this->addSql('DELETE FROM monsieurbiz_shipping_slot_slot WHERE shipment_id IS NULL'); + $this->addSql('ALTER TABLE monsieurbiz_shipping_slot_slot DROP FOREIGN KEY FK_3BD6F1F67BE036FC'); + $this->addSql('ALTER TABLE monsieurbiz_shipping_slot_slot ADD CONSTRAINT FK_3BD6F1F67BE036FC FOREIGN KEY (shipment_id) REFERENCES sylius_shipment (id) ON DELETE CASCADE'); + } + + public function down(Schema $schema): void + { + $this->addSql('ALTER TABLE monsieurbiz_shipping_slot_slot DROP FOREIGN KEY FK_3BD6F1F67BE036FC'); + $this->addSql('ALTER TABLE monsieurbiz_shipping_slot_slot ADD CONSTRAINT FK_3BD6F1F67BE036FC FOREIGN KEY (shipment_id) REFERENCES sylius_shipment (id) ON DELETE SET NULL'); + } +} diff --git a/src/Resources/config/doctrine/Slot.orm.xml b/src/Resources/config/doctrine/Slot.orm.xml index 00bd5f4..a7b9b5f 100644 --- a/src/Resources/config/doctrine/Slot.orm.xml +++ b/src/Resources/config/doctrine/Slot.orm.xml @@ -16,7 +16,7 @@ - +