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

option --em does nothing for me #507

Open
lbcd opened this issue Sep 2, 2023 · 1 comment
Open

option --em does nothing for me #507

lbcd opened this issue Sep 2, 2023 · 1 comment

Comments

@lbcd
Copy link

lbcd commented Sep 2, 2023

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

lbcd commented Sep 2, 2023

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.

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

No branches or pull requests

1 participant