Skip to content

Commit

Permalink
Apply schema filter more selectively
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
greg0ire committed Jan 19, 2025
1 parent 9872551 commit c32b617
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
13 changes: 7 additions & 6 deletions src/EventListener/SchemaFilterListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand All @@ -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
Expand All @@ -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();
}
}

0 comments on commit c32b617

Please sign in to comment.