Skip to content
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

Draft
wants to merge 1 commit into
base: 3.4.x
Choose a base branch
from

Conversation

greg0ire
Copy link
Member

@greg0ire greg0ire commented Mar 14, 2024

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.

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"

<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>
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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);

@greg0ire
Copy link
Member Author

Cc @FlyingDR :)

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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants