-
-
Notifications
You must be signed in to change notification settings - Fork 216
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support for --complete #526
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -90,15 +90,21 @@ public function load(array $configs, ContainerBuilder $container): void | |
$diDefinition->addMethodCall('setDefinition', [$doctrineId, new Reference($symfonyId)]); | ||
} | ||
|
||
if (! isset($config['services'][MetadataStorage::class])) { | ||
if (isset($config['services'][MetadataStorage::class])) { | ||
$container->removeDefinition('doctrine_migrations.schema_filter_listener'); | ||
} else { | ||
$filterDefinition = $container->getDefinition('doctrine_migrations.schema_filter_listener'); | ||
$storageConfiguration = $config['storage']['table_storage']; | ||
|
||
$storageDefinition = new Definition(TableMetadataStorageConfiguration::class); | ||
$container->setDefinition('doctrine.migrations.storage.table_storage', $storageDefinition); | ||
$container->setAlias('doctrine.migrations.metadata_storage', 'doctrine.migrations.storage.table_storage'); | ||
|
||
if ($storageConfiguration['table_name'] !== null) { | ||
if ($storageConfiguration['table_name'] === null) { | ||
$filterDefinition->addArgument('doctrine_migration_versions'); | ||
} else { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. After implementing these changes, running the migration results in the following exception: |
||
$storageDefinition->addMethodCall('setTableName', [$storageConfiguration['table_name']]); | ||
$filterDefinition->addArgument($storageConfiguration['table_name']); | ||
} | ||
|
||
if ($storageConfiguration['version_column_name'] !== null) { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Doctrine\Bundle\MigrationsBundle\EventListener; | ||
|
||
use Doctrine\DBAL\Schema\AbstractAsset; | ||
use Doctrine\Migrations\Tools\Console\Command\DoctrineCommand; | ||
use Symfony\Component\Console\Event\ConsoleCommandEvent; | ||
|
||
/** | ||
* Acts as a schema filter that hides the migration metadata table except | ||
* when the execution context is that of command inside the migrations | ||
* namespace. | ||
*/ | ||
final class SchemaFilterListener | ||
{ | ||
/** @var string */ | ||
private $configurationTableName; | ||
|
||
public function __construct(string $configurationTableName) | ||
{ | ||
$this->configurationTableName = $configurationTableName; | ||
} | ||
|
||
/** @var bool */ | ||
private $enabled = true; | ||
|
||
/** @param AbstractAsset|string $asset */ | ||
public function __invoke($asset): bool | ||
{ | ||
if (! $this->enabled) { | ||
return true; | ||
} | ||
|
||
if ($asset instanceof AbstractAsset) { | ||
$asset = $asset->getName(); | ||
} | ||
|
||
return $asset !== $this->configurationTableName; | ||
} | ||
|
||
private function disable(): void | ||
{ | ||
$this->enabled = false; | ||
} | ||
|
||
public function onConsoleCommand(ConsoleCommandEvent $event): void | ||
{ | ||
$command = $event->getCommand(); | ||
|
||
if (! $command instanceof DoctrineCommand) { | ||
return; | ||
} | ||
|
||
$this->disable(); | ||
} | ||
} |
39 changes: 39 additions & 0 deletions
39
tests/Collector/EventListener/SchemaFilterListenerTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Doctrine\Bundle\MigrationsBundle\Tests\Collector\EventListener; | ||
|
||
use Doctrine\Bundle\MigrationsBundle\EventListener\SchemaFilterListener; | ||
use Doctrine\DBAL\Schema\Table; | ||
use Doctrine\Migrations\Tools\Console\Command\DoctrineCommand; | ||
use PHPUnit\Framework\TestCase; | ||
use Symfony\Component\Console\Event\ConsoleCommandEvent; | ||
use Symfony\Component\Console\Input\ArrayInput; | ||
use Symfony\Component\Console\Output\NullOutput; | ||
|
||
class SchemaFilterListenerTest extends TestCase | ||
{ | ||
public function testItFiltersOutMigrationMetadataTableByDefault(): void | ||
{ | ||
$listener = new SchemaFilterListener('doctrine_migration_versions'); | ||
|
||
self::assertFalse($listener(new Table('doctrine_migration_versions'))); | ||
self::assertTrue($listener(new Table('some_other_table'))); | ||
} | ||
|
||
public function testItDisablesItselfWhenTheCurrentCommandIsAMigrationsCommand(): void | ||
{ | ||
$listener = new SchemaFilterListener('doctrine_migration_versions'); | ||
$migrationsCommand = new class extends DoctrineCommand { | ||
}; | ||
|
||
$listener->onConsoleCommand(new ConsoleCommandEvent( | ||
$migrationsCommand, | ||
new ArrayInput([]), | ||
new NullOutput() | ||
)); | ||
|
||
self::assertTrue($listener(new Table('doctrine_migration_versions'))); | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When a user defines their own storage class, there is no telling what they are going to do… they might even not store it in a database. At this point they're one their own.