Add support for --complete#526
Conversation
| <service id="doctrine_migrations.schema_filter_listener" class="Doctrine\Migrations\EventListener\SchemaFilterListener"> | ||
| <tag name="kernel.event_listener" event="console.command" method="onConsoleCommand" /> | ||
| <tag name="doctrine.dbal.schema_filter" /> | ||
| </service> |
There was a problem hiding this comment.
This is the part I am not sure about, because I have been enable to test it. I've tried accessing the schema filter manager definition in order to inspect it after the compiler pass, like this:
public function testItRegistersTheSchemaFilterListener(): void
{
$container = $this->getContainer([]);
$container->getDefinition('doctrine.dbal.schema_asset_filter_manager')->setPublic(true);
$container->compile();
$container->get('doctrine.dbal.schema_asset_filter_manager');
}That last line results in
Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException: The "doctrine.dbal.schema_asset_filter_manager" service or alias has been removed or inlined when the container was compiled. You should either make it public, or stop using the container directly and use dependency injection instead.
Any ideas how to test this?
There was a problem hiding this comment.
doctrine.dbal.schema_asset_filter_manager is defined as an abstract. The container builder removes unused and/or abstract definitions during its compilation causing the service to be hidden.
An example fix, not per se the wanted fix, could be:
$container
->getDefinition('doctrine.dbal.schema_asset_filter_manager')
->setAbstract(false)
->setArgument(0, [])
->setPublic(true);There was a problem hiding this comment.
OK… I guess since it's abstract, I should try to retrieve a concrete definition inheriting from it. I inspected the container, and there does not seem to be any :(
feca975 to
2cfbb72
Compare
8ad6f64 to
656c9ee
Compare
|
Cc @FlyingDR :) |
656c9ee to
c356a12
Compare
|
Anything I can do to get this over the finish line? Would love to be able to remove the workaround we've got in our app 🙂 |
|
You could test it on your application and confirm whether it works or not. |
|
@greg0ire Ok, I will. Are the conflicts which are mentioned by the PR going to be a stumbling block for it? |
|
@greg0ire Unfortunately it already fails on The service is mentioned in Fixing it to be the following seems to be necessary: <service id="doctrine_migrations.schema_filter_listener" class="Doctrine\Bundle\MigrationsBundle\EventListener\SchemaFilterListener">But even with this added, when running: |
|
@greg0ire Is there anything that needs to be configured for it to work? |
No. Thanks for your suggestion, I applied it. I will need to fix the conflicts for this to get merged though.
No, I don't think so… |
8d4e01b to
2e7a3f7
Compare
|
|
||
| if (! isset($config['services'][MetadataStorage::class])) { | ||
| if (isset($config['services'][MetadataStorage::class])) { | ||
| $container->removeDefinition('doctrine_migrations.schema_filter_listener'); |
There was a problem hiding this comment.
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.
2e7a3f7 to
065d980
Compare
|
@greg0ire Awesome, now it's working. Now I get what I should get: |
|
Thanks for helping moving this forward! Let's get this reviewed now. |
| public function testItFiltersNothingWhenDisabled(): void | ||
| { | ||
| $listener = new SchemaFilterListener('doctrine_migration_versions'); | ||
| $listener->disable(); | ||
|
|
||
| self::assertTrue($listener(new Table('doctrine_migration_versions'))); | ||
| self::assertTrue($listener(new Table('some_other_table'))); | ||
| } |
There was a problem hiding this comment.
I don't understand this use case. When do you need to disable it in userland by calling the public disable-method?
There was a problem hiding this comment.
🤔 I suspect I might have written that one before writing the next use case. I'll remove it and make the method private, if it's needed in userland, people can make it public later.
When using orm:schema-tool:update together with --complete, all assets not described by the current metadata is dropped. This is an issue when using doctrine/migrations, because not using that option is deprecated, and because when it is used, the table that holds the migrations is dropped as well since it is not described by ORM metadata. A solution to that is configuring an asset filter that filters out the metadata table except when running commands inside the migrations namespace.
065d980 to
c85cd25
Compare
|
EDIT: posted as new bug report in #586 |
| if ($storageConfiguration['table_name'] !== null) { | ||
| if ($storageConfiguration['table_name'] === null) { | ||
| $filterDefinition->addArgument('doctrine_migration_versions'); | ||
| } else { |
There was a problem hiding this comment.
After implementing these changes, running the migration results in the following exception:
SQLSTATE[42P07]: Duplicate table: 7 ERROR: relation "doctrine_migration_versions" already exists.
When using
orm:schema-tool:updatetogether with--complete, all assets not described by the current metadata are dropped.This is an issue when using doctrine/migrations, because not using that option is deprecated, and because when it is used, the table that holds the migrations is dropped as well since it is not described by ORM metadata.
A solution to that is configuring an asset filter that filters out the metadata table except when running commands inside the migrations namespace.
How can I test this?
composer config repositories.greg0ire vcs https://github.com/greg0ire/DoctrineMigrationsBundle composer require doctrine/doctrine-migrations-bundle "dev-complete-compat as 3.3.0"