migrations icon indicating copy to clipboard operation
migrations copied to clipboard

Command diff is not defined

Open danielspk opened this issue 5 years ago • 6 comments

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 avatar Aug 06 '20 15:08 danielspk

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 avatar Aug 06 '20 16:08 danielspk

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

danielspk avatar Aug 06 '20 16:08 danielspk

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.

stof avatar Aug 07 '20 07:08 stof

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 avatar Aug 03 '22 08:08 pbek

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

pbek avatar Aug 03 '22 10:08 pbek

how do you know the em name?

sirber avatar Jun 27 '24 15:06 sirber