doctrine / migrations

Doctrine Database Migrations Library
https://www.doctrine-project.org/projects/migrations.html
MIT License
4.67k stars 385 forks source link

Command diff is not defined #1042

Open danielspk opened 4 years ago

danielspk commented 4 years ago

BC Break Report

After update from version 2.2.1 to 3.0.1 the command diff nor found.

Q A
BC Break yes
Version 3.0.1

Summary

If I run:

./vendor/bin/doctrine-migrations diff

The output is Command "diff" is not defined.

If I update my custom integration to:

        // application console definitions...

        // PSR-11 Doctrine ORM Entity Manager instance
        $entityManager = $container->get('EntityManager');

        $config = new XmlFile('migrations.xml');
        $connection = new ExistingConnection($entityManager->getConnection());
        $dependencyFactory = DependencyFactory::fromConnection($config, $connection);

        $console->addCommands([
            new DiffCommand($dependencyFactory),
            // others commands work
        ]);

The output is The entity manager is not available.

Previous behavior

Custom integration worked correctly when creating a helperset:

        $helperSet = new HelperSet();
        $helperSet->set(new QuestionHelper(), 'question');
        $helperSet->set(new ConnectionHelper($entityManager->getConnection()), 'db');
        $helperSet->set(new EntityManagerHelper($entityManager), 'entityManager');

        $console->setHelperSet($helperSet);

Currently that does not apply

danielspk commented 4 years ago

Sorry it works like this

        // application console definitions...

        // PSR-11 Doctrine ORM Entity Manager instance
        $entityManager = $container->get('EntityManager');

        $config = new XmlFile('migrations.xml');
        $existingEntityManager = new ExistingEntityManager($entityManager);
        $dependencyFactoryORM = DependencyFactory::fromEntityManager($config, $existingEntityManager);

        $console->addCommands([
            new DiffCommand($dependencyFactoryORM),
        ]);

This behavior would need to be documented.

danielspk commented 4 years ago

Will this behavior be definitive or will it change in future pull requests?

stof commented 4 years ago

well, if you create a dependency factory not knowing about the ORM but only about the connection, the diff cannot work (unless you provide a custom implementation of the schema provider). This command is about diffing the existing database schema and the expected schema defined by the mapping.

Registering a dependency factory based on a connection only rather than based on an entity manager is equivalent to not registering the EntityManagerHelper in the 2.x version of the library, where the diff command would not work either.

pbek commented 2 years ago

The documentation, like https://www.doctrine-project.org/projects/doctrine-migrations/en/3.2/reference/generating-migrations.html#diffing-using-the-orm still uses diff. Does it do that by accident? How is it currently possible to create a migration class from entity changes?

pbek commented 2 years ago

In Symfony ./console doctrine:migrations:diff --em=your-em does the trick.

sirber commented 2 months ago

how do you know the em name?