如何设置具有多个数据库的symfony 3理论迁移? [英] how set up symfony 3 doctrine migrations with multiple db?

查看:75
本文介绍了如何设置具有多个数据库的symfony 3理论迁移?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在努力使symfony / doctrine在验证和更新架构时排除数据库视图。

I am struggling to have symfony/doctrine exclude db views when validating and updating schema.

我首先尝试了不进行理论迁移(看到此问题),但那没有用。

I first tried without doctrine migrations ( see this question) but that did not work.

我发现,理论上的迁移会从验证/更新中过滤掉视图,实际上它确实可以,因此该步骤似乎适用于迁移。

I found out that doctrine migrations would filter out views from validation/update and it actually does, so that step seems to work with migrations.

因此,如果一个至少可以说,只有一个数据库理论迁移可以正常工作,但是至少可以说,使用多个数据库进行的设置并非一帆风顺。

So, if one has just one db doctrine migrations will work fine, but the set up with multiple db is not clean cut, to say the least.

这是一个众所周知的问题请参见此链接。不幸的是,当尝试遵循链接中描述的解决方案时,结果是混乱的。

This is a known issue as you can see on this link. Unfortunately when attempting to follow the solutions described in the link the results are messy.

即使命令migrations:update --em = default将指示已设置正确的数据库向上,当生成migrations:diff --em = default时,它将与其他数据库混合,并且同样与migrations:migrate --em = default混合,最终在另一个db上创建表。

Even though the command migrations:update --em=default will indicate the correct database is set up, when generating migrations:diff --em=default it will mingle with other db and likewise with migrations:migrate --em=default which ends up creating tables on the other db.

更具体的错误是:
-它将为迁移文件创建单独的目录,如配置文件中所示,但不会指向相应的em
-它将生成混合的mysql查询两个em
-因此它将更新db

More specifically the errors are: - it will create the separate directories for the migrations files as indicated in the config files, but not to the corresponding em - it will generate mysql queries mixing up the two em - consequently it will update db

我的设置如下:

config.yml

config.yml

imports:
....
- { resource: doctrine_migrations_default.yml }
- { resource: doctrine_migrations_used.yml }

doctrine:
  dbal:
    default_connection: default
    connections:
        default:      
            .....
            #schema_filter: "~^(?!view).*$~"
            schema_filter: ~^(?!view_)~
        used:
             ......

orm:
    auto_generate_proxy_classes: '%kernel.debug%'
    default_entity_manager: default
    entity_managers:
        default:
            naming_strategy: doctrine.orm.naming_strategy.underscore
            connection: default
            auto_mapping: true
            mappings:
                AppBundle:  ~
        used:
            naming_strategy: doctrine.orm.naming_strategy.underscore
            connection: used
            mappings:
                UsedBundle: ~ 

然后,用于迁移的特定配置文件为:

Then, the specific configuration files for migrations are:

doctrine_migrations_default.yml

doctrine_migrations_default.yml

doctrine_migrations: 
        dir_name: "%kernel.root_dir%/DoctrineMigrationsDefault"
        namespace: App\DoctrineMigrationsDefault
        table_name: migration_versions
        name: Application_Migrations_Default 

doctrine_migrations_used.yml

doctrine_migrations_used.yml

doctrine_migrations:
    dir_name: "%kernel.root_dir%/DoctrineMigrationsUsed"
    namespace: Used\DoctrineMigrationsUsed
    table_name: migration_versions
    name: Application Migrations Used
    organize_migrations: false

这是它如何混合配置的一个示例。数据库名称正确。它对应于em = default。但是其他信息来自em =二手

This is one example of how it mixes up the configs. The database name is correct. It corresponds to the em=default. But other info are coming from the em=used

谢谢

php bin/console doctrine:migrations:status --em=default

==配置

>> Name:                                               Application Migrations Used
>> Database Driver:                                    pdo_mysql
>> Database Name:                                      symfony_cars
>> Configuration Source:                               manually configured
>> Version Table Name:                                 migration_versions
>> Version Column Name:                                version
>> Migrations Namespace:                               Used\DoctrineMigrationsUsed
>> Migrations Directory:                               /Users/BAMAC/Sites/Symfony1/app/DoctrineMigrationsUsed
>> Previous Version:                                   Already at first version
>> Current Version:                                    0
>> Next Version:                                       2017-10-19 08:03:52 (20171019080352)
>> Latest Version:                                     2017-10-19 08:03:52 (20171019080352)
>> Executed Migrations:                                0
>> Executed Unavailable Migrations:                    0
>> Available Migrations:                               1
>> New Migrations:                                     1

此外,如果我尝试使用以下方式专门指出配置文件:

Also, if I try to specifically indicate the configuration file with:


php bin /控制台原则:migrations:status --em = default --configuration =。/ app / config / doctrine_migrations_default.yml

php bin/console doctrine:migrations:status --em=default --configuration=./app/config/doctrine_migrations_default.yml

即使直接从config.yml获取信息,它也不会识别文件信息。引发以下错误。

It will not recognize the file info, even though it does so when it gets the info directly from config.yml. The following error is thrown.


[Doctrine\DBAL\Migrations\MigrationException]

迁移配置密钥 doctrine_migrations不存在。

[Doctrine\DBAL\Migrations\MigrationException]
Migrations configuration key "doctrine_migrations" does not exists.

如果我拿出doctrine_migrations键,它将在遇到的下一个信息上产生错误。 / p>

If I take the doctrine_migrations key out it will generate an error on the next info it encounters.

推荐答案

不要将迁移设置导入到config.yml文件中。

Don't import the migrations settings in your config.yml file.

您的单个​​配置文件实际上没有正确配置,这就是为什么您收到有关配置密钥不存在的错误的原因。密钥与常规迁移配置中的密钥不同。我必须搜索代码以找到正确的设置。 (我在

Your individual configuration files aren't actually configured correctly which is why you are receiving the error about the configuration keys not existing. The keys are different than they are in the normal migrations config. I had to search the code to find the right settings. (I found them around ln35 of the AbstractFileConfiguration.php file)

尝试这些-

doctrine_migrations_default.yml

doctrine_migrations_default.yml

migrations_directory: "app/DoctrineMigrationsDefault"
migrations_namespace: App\DoctrineMigrationsDefault
table_name: migration_versions
name: Application_Migrations_Default 

doctrine_migrations_used.yml

doctrine_migrations_used.yml

migrations_directory: "app/DoctrineMigrationsUsed"
migrations_namespace: Used\DoctrineMigrationsUsed
table_name: migration_versions
name: Application Migrations Used
organize_migrations: false #valid entries are false, 'year', and 'year_and_month'

doctrine_migrations,dir_name和名称空间不是以下项的有效条目那配置文件。

doctrine_migrations, dir_name, and namespace are not valid entries for that configuration file.

此外,您不能在目录路径中使用%kernel.root_dir%,但对我有用的是将其更改为 app或提供完整路径。

Also, you can't use %kernel.root_dir% in your directory path but what worked for me was either changing it to 'app' or providing a full path.

这篇关于如何设置具有多个数据库的symfony 3理论迁移?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆