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

Symfony 7.2 and Doctrine Migrations with two different databases #11831

Open
nnikolay opened this issue Feb 9, 2025 · 0 comments
Open

Symfony 7.2 and Doctrine Migrations with two different databases #11831

nnikolay opened this issue Feb 9, 2025 · 0 comments

Comments

@nnikolay
Copy link

nnikolay commented Feb 9, 2025

I have troubles to execute properly the migrations between two different databases with Doctrine.

Here my Doctrine debug information:

Current configuration for extension with alias "doctrine_migrations"
====================================================================

doctrine_migrations:
    migrations_paths:
        App\Module\Module1\Resource\Migration: /var/www/html/src/Module/Module1/Resource/Migration
        App\Module\Module2\Resource\Migration: /var/www/html/src/Module/Module2/Resource/Migration
    em: module1
    enable_profiler: false
    services: {  }
    factories: {  }
    storage:
        table_storage:
            table_name: null
            version_column_name: null
            version_column_length: null
            executed_at_column_name: null
            execution_time_column_name: null
    migrations: {  }
    connection: null
    all_or_nothing: false
    check_database_platform: true
    custom_template: null
    organize_migrations: false
    transactional: true

The migration paths are detected but when I try to execute the migration with the corresponding entity manager it executes both migrations in one database:

php bin/console doctrine:migrations:migrate --env=dev --no-interaction --em=module1

My doctrine.yaml

doctrine:
    dbal:
        connections:
            module1:
                url: '%env(resolve:DATABASE_MODULE1_URL)%'
                driver: 'pdo_mysql'
                server_version: '8.0'
                charset: utf8mb4
                mapping_types:
                    enum: string
            module2:
                url: '%env(resolve:DATABASE_MODULE2_URL)%'
                driver: 'pdo_mysql'
                server_version: '8.0'
                charset: utf8mb4
                mapping_types:
                    enum: string

    orm:
        auto_generate_proxy_classes: true
        default_entity_manager: module1
        entity_managers:
            module1:
                connection: module1
                naming_strategy: doctrine.orm.naming_strategy.underscore_number_aware
                mappings:
                    Module1:
                        is_bundle: false
                        dir: '%kernel.project_dir%/src/Module/Module1/Entity'
                        prefix: 'App\Module\Module1\Entity'
                        alias: Module1
            module2:
                connection: module2
                naming_strategy: doctrine.orm.naming_strategy.underscore_number_aware
                mappings:
                    Module2:
                        is_bundle: false
                        dir: '%kernel.project_dir%/src/Module/Module2/Entity'
                        prefix: 'App\Module\Module2\Entity'
                        alias: Module2

Here is my doctrine_migrations.yaml

imports:
    - { resource: '../../src/Module/Module1/Resource/Config/Package/doctrine_migrations.yaml' }
    - { resource: '../../src/Module/Module2/Resource/Config/Package/doctrine_migrations.yaml' }

doctrine_migrations:
    enable_profiler: false

And the single configurations:

Module1:

doctrine_migrations:
  migrations_paths:
    'App\Module\Module1\Resource\Migration': '%kernel.project_dir%/src/Module/Module1/Resource/Migration'
  em: module1

What I am missing?

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