From 00b6b92b4912eca003b7bc202e3a07d1edd36522 Mon Sep 17 00:00:00 2001 From: Maxime Leclercq Date: Fri, 29 Mar 2024 14:11:53 +0100 Subject: [PATCH 1/3] feat: improve migration dependencies --- ...sylius_labs_doctrine_migrations_extra.yaml | 4 --- .../MonsieurBizSyliusAntiSpamExtension.php | 28 ++++++++++++++++++- 2 files changed, 27 insertions(+), 5 deletions(-) delete mode 100644 dist/config/packages/sylius_labs_doctrine_migrations_extra.yaml diff --git a/dist/config/packages/sylius_labs_doctrine_migrations_extra.yaml b/dist/config/packages/sylius_labs_doctrine_migrations_extra.yaml deleted file mode 100644 index 93ecc82..0000000 --- a/dist/config/packages/sylius_labs_doctrine_migrations_extra.yaml +++ /dev/null @@ -1,4 +0,0 @@ -sylius_labs_doctrine_migrations_extra: - migrations: - 'MonsieurBiz\SyliusAntiSpamPlugin\Migrations': ~ - 'App\Migrations': ['MonsieurBiz\SyliusAntiSpamPlugin\Migrations'] diff --git a/src/DependencyInjection/MonsieurBizSyliusAntiSpamExtension.php b/src/DependencyInjection/MonsieurBizSyliusAntiSpamExtension.php index 1eaea4a..0047289 100644 --- a/src/DependencyInjection/MonsieurBizSyliusAntiSpamExtension.php +++ b/src/DependencyInjection/MonsieurBizSyliusAntiSpamExtension.php @@ -14,13 +14,17 @@ namespace MonsieurBiz\SyliusAntiSpamPlugin\DependencyInjection; use MonsieurBiz\SyliusAntiSpamPlugin\Validator\ValidatorInterface; +use Sylius\Bundle\CoreBundle\DependencyInjection\PrependDoctrineMigrationsTrait; use Symfony\Component\Config\FileLocator; use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\Extension\Extension; +use Symfony\Component\DependencyInjection\Extension\PrependExtensionInterface; use Symfony\Component\DependencyInjection\Loader\YamlFileLoader; -final class MonsieurBizSyliusAntiSpamExtension extends Extension +final class MonsieurBizSyliusAntiSpamExtension extends Extension implements PrependExtensionInterface { + use PrependDoctrineMigrationsTrait; + /** * @inheritdoc */ @@ -47,4 +51,26 @@ public function getAlias(): string { return str_replace('monsieur_biz', 'monsieurbiz', parent::getAlias()); } + + public function prepend(ContainerBuilder $container): void + { + $this->prependDoctrineMigrations($container); + } + + protected function getMigrationsNamespace(): string + { + return 'MonsieurBiz\SyliusAntiSpamPlugin\Migrations'; + } + + protected function getMigrationsDirectory(): string + { + return '@MonsieurBizSyliusAntiSpamPlugin/Migrations'; + } + + protected function getNamespacesOfMigrationsExecutedBefore(): array + { + return [ + 'Sylius\Bundle\CoreBundle\Migrations', + ]; + } } From 3cf93ea7896d3beff03f7a6943d068769a76f79a Mon Sep 17 00:00:00 2001 From: Maxime Leclercq Date: Fri, 29 Mar 2024 14:17:28 +0100 Subject: [PATCH 2/3] chore: add migration to change json type --- src/Migrations/Version20240329131510.php | 28 ++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 src/Migrations/Version20240329131510.php diff --git a/src/Migrations/Version20240329131510.php b/src/Migrations/Version20240329131510.php new file mode 100644 index 0000000..5102ada --- /dev/null +++ b/src/Migrations/Version20240329131510.php @@ -0,0 +1,28 @@ +addSql('ALTER TABLE monsieurbiz_anti_spam_quarantine_item CHANGE reason_codes reason_codes JSON NOT NULL'); + } + + public function down(Schema $schema): void + { + // this down() migration is auto-generated, please modify it to your needs + $this->addSql('ALTER TABLE monsieurbiz_anti_spam_quarantine_item CHANGE reason_codes reason_codes LONGTEXT NOT NULL COMMENT \'(DC2Type:json_array)\''); + } +} From bcfa7a9f111367bae94ae470e2fa339ef8fa7f60 Mon Sep 17 00:00:00 2001 From: Maxime Leclercq Date: Fri, 29 Mar 2024 14:17:51 +0100 Subject: [PATCH 3/3] feat(dev): add makefile target to generate migration file --- Makefile | 9 +++++++++ src/Migrations/Version20240329131510.php | 9 +++++++++ 2 files changed, 18 insertions(+) diff --git a/Makefile b/Makefile index 31813b3..aae578a 100644 --- a/Makefile +++ b/Makefile @@ -9,6 +9,7 @@ export COMPOSE_PROJECT_NAME=anti-spam PLUGIN_NAME=sylius-${COMPOSE_PROJECT_NAME}-plugin COMPOSE=docker-compose YARN=yarn +DOCTRINE_MIGRATIONS_NAMESPACE=MonsieurBiz\SyliusAntiSpamPlugin\Migrations ### ### DEVELOPMENT @@ -142,6 +143,14 @@ test.schema: ## Validate MySQL Schema test.twig: ## Validate Twig templates ${CONSOLE} lint:twig --no-debug templates/ ../../src/Resources/views/ +### +### MIGRATIONS +### ¯¯¯¯¯¯¯¯¯¯ + +doctrine.migration.diff: ## create a diff migration file for the plugin + ${CONSOLE} doctrine:migrations:diff --namespace="${DOCTRINE_MIGRATIONS_NAMESPACE}" +.PHONY: doctrine.migration.diff + ### ### SYLIUS ### ¯¯¯¯¯¯ diff --git a/src/Migrations/Version20240329131510.php b/src/Migrations/Version20240329131510.php index 5102ada..b0a9857 100644 --- a/src/Migrations/Version20240329131510.php +++ b/src/Migrations/Version20240329131510.php @@ -1,5 +1,14 @@ + * + * For the full copyright and license information, please view the LICENSE.txt + * file that was distributed with this source code. + */ + declare(strict_types=1); namespace MonsieurBiz\SyliusAntiSpamPlugin\Migrations;