From c32b6178c306c0066ef3c85dd7e8173fc0fb4f3d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9goire=20Paris?= Date: Sun, 19 Jan 2025 22:23:10 +0100 Subject: [PATCH] Apply schema filter more selectively It is more careful, since there seems to be a lot of situations where we do not want to apply the filter. Let us take the opposite approach and: - Have the filter disabled by default, instead of enabled by default. - Enable it for precise commands where we know we need it. This means the ORM is no longer just a dev dependency. --- composer.json | 2 +- src/EventListener/SchemaFilterListener.php | 13 +++++++------ 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/composer.json b/composer.json index ee7c51f..48bad17 100644 --- a/composer.json +++ b/composer.json @@ -27,13 +27,13 @@ "php": "^7.2 || ^8.0", "doctrine/doctrine-bundle": "^2.4", "doctrine/migrations": "^3.2", + "doctrine/orm": "^2.6 || ^3", "symfony/deprecation-contracts": "^2.1 || ^3", "symfony/framework-bundle": "^5.4 || ^6.0 || ^7.0" }, "require-dev": { "composer/semver": "^3.0", "doctrine/coding-standard": "^12", - "doctrine/orm": "^2.6 || ^3", "doctrine/persistence": "^2.0 || ^3", "phpstan/phpstan": "^1.4 || ^2", "phpstan/phpstan-deprecation-rules": "^1 || ^2", diff --git a/src/EventListener/SchemaFilterListener.php b/src/EventListener/SchemaFilterListener.php index 203739b..f0ff37c 100644 --- a/src/EventListener/SchemaFilterListener.php +++ b/src/EventListener/SchemaFilterListener.php @@ -5,7 +5,8 @@ namespace Doctrine\Bundle\MigrationsBundle\EventListener; use Doctrine\DBAL\Schema\AbstractAsset; -use Doctrine\Migrations\Tools\Console\Command\DoctrineCommand; +use Doctrine\ORM\Tools\Console\Command\SchemaTool\UpdateCommand; +use Doctrine\ORM\Tools\Console\Command\ValidateSchemaCommand; use Symfony\Component\Console\Event\ConsoleCommandEvent; /** @@ -24,7 +25,7 @@ public function __construct(string $configurationTableName) } /** @var bool */ - private $enabled = true; + private $enabled = false; /** @param AbstractAsset|string $asset */ public function __invoke($asset): bool @@ -40,19 +41,19 @@ public function __invoke($asset): bool return $asset !== $this->configurationTableName; } - private function disable(): void + private function enable(): void { - $this->enabled = false; + $this->enabled = true; } public function onConsoleCommand(ConsoleCommandEvent $event): void { $command = $event->getCommand(); - if (! $command instanceof DoctrineCommand) { + if ($command instanceof ValidateSchemaCommand || $command instanceof UpdateCommand) { return; } - $this->disable(); + $this->enable(); } }