doctrine/DoctrineMigrationsBundle

option --em does nothing for me

lbcd opened this issue · 1 comments

lbcd commented

Hello,

I use "doctrine/doctrine-migrations-bundle": "3.2.4" in a Symfony project with two databases.

Here is my configuration:

doctrine:
    dbal:
        connections:
            default:
                url: '%env(resolve:DATABASE_URL)%'
            bordereau:
                url: '%env(resolve:DATABASE_BORDEREAU_URL)%'
        default_connection: default
    orm:
        auto_generate_proxy_classes: true
        default_entity_manager: default
        entity_managers:
            default:
                connection: default
                auto_mapping: true
                naming_strategy: doctrine.orm.naming_strategy.underscore_number_aware
            bordereau:
                connection: bordereau
                naming_strategy: doctrine.orm.naming_strategy.underscore_number_aware
                mappings:
                    Bordereau:
                        is_bundle: false
                        type: attribute
                        dir: '%kernel.project_dir%/src/Entity/Bordereau'
                        prefix: 'App\Entity\Bordereau'
                        alias: Bordereau
doctrine_migrations:
    em: default
    migrations_paths:
        # namespace is arbitrary but should be different from App\Migrations
        # as migrations classes should NOT be autoloaded
        DoctrineMigrations: '%kernel.project_dir%/migrations/gli-agrement'
        DoctrineMigrationsBordereau: '%kernel.project_dir%/migrations/bordereau'

Project work perfect, but I have executed query on database without migration bundle. And I would like to reset this important functionality.

First question : how it can detect which migrations directory go with which entityManager ?

It is ok when I execute command bin/console doctrine:m:diff -v --em=bordereau but it put a file in '%kernel.project_dir%/migrations/gli-agrement' while I would like to get it in bordereau directory.

Then when I execute bin/console doctrine:m:m -v --em=bordereau it try to play '%kernel.project_dir%/migrations/gli-agrement' migrations in my bordereau database.

I didn't find the way to associate migrations to an entityManager. The config doc doesn't explain how to configure that. I suppose we should have something like it was specified here : #364 (comment)

doctrine_migrations:
    # default_connection: foo #(to specify a connection if there is not a "default" named connection there?)
    connections:
        default:
            migrations_paths:
                'DoctrineMigrations\Main': '%kernel.project_dir%/migrations/Main'
        geonames:
            migrations_paths:
                'DoctrineMigrations\Geonames': '%kernel.project_dir%/migrations/Geonames'

Something missing here : https://symfony.com/doc/current/doctrine/multiple_entity_managers.html
And here too : https://symfony.com/bundles/DoctrineMigrationsBundle/current/index.html
about multiple connections.

I have tried another way:

bin/console d:m:m --configuration=config/packages/doctrine_migrations_bordereau.yaml --dry-run --em=bordereau

with this config :

# config/packages/doctrine_migrations_bordereau.yaml
doctrine_migrations:
    em: bordereau
    migrations_paths:
        # namespace is arbitrary but should be different from App\Migrations
        # as migrations classes should NOT be autoloaded
        DoctrineMigrations: '%kernel.project_dir%/migrations/bordereau'

But I get this error : Migrations configuration key "doctrine_migrations" does not exist. which is mentioned in this thread #341 and should have been fixed since 2020. So I don't understand

Many thanks in advance for your help.

lbcd commented

I find a way to make it work with --configuration

I move config/packages/doctrine_migrations_bordereau.yaml to root of my project => /doctrine_migrations_bordereau.yaml then I remove doctrine_migrations: and %kernel.project_dir% that doesn't work so I get this

# /doctrine_migrations_bordereau.yaml -- !!! don't put this file in config/packages

em: bordereau
migrations_paths:
    # namespace is arbitrary but should be different from App\Migrations
    # as migrations classes should NOT be autoloaded
    DoctrineMigrations: 'migrations/bordereau'

And this commande works:

bin/console d:m:m --configuration=doctrine_migrations_bordereau.yaml --dry-run --em=bordereau -vv

So I can use :
bin/console d:m:m for my default db
and bin/console d:m:m --configuration=doctrine_migrations_bordereau.yaml --dry-run --em=bordereau for my second

But I think it would be usefull to not have a configuration file that is not in package and it would be great to have abilities to configure migrations path for specifics entityManager.