Symfony 和 Doctrine 迁移

问题描述 投票:0回答:1

这就是我被困住的地方:

我正在调用一个执行教条迁移的 API,使用最新版本。

它运行命令。

当我手动执行命令时,输出如下(工作已完成): ==配置

>> Name:                                               Application Migrations
>> Database Driver:                                    pdo_sqlsrv
>> Database Name:                                      xxxxxxxxxx
>> Configuration Source:                               manually configured
>> Version Table Name:                                 Dsys_migration_versions
>> Version Column Name:                                version
>> Migrations Namespace:                               Application\Migrations
>> Migrations Directory:                               /var/www/xxxx/app/DoctrineMigrations
>> Previous Version:                                    (20170503101946CreateSettingTable)
>> Current Version:                                     (20170621150818CreateCalculatedfieldQuery)
>> Next Version:                                       Already at latest version
>> Latest Version:                                      (20170621150818CreateCalculatedfieldQuery)
>> Executed Migrations:                                19
>> Executed Unavailable Migrations:                    0
>> Available Migrations:                               19
>> New Migrations:                                     0

== 可用的迁移版本

>>  (20170307111115CreateCustomTableTable)             migrated
>>  (20170307111322CreateCustomFieldTable)             migrated
>>  (20170307111324CreatePresetFieldTable)             migrated
>>  (20170307111326CreateDimensionTable)               migrated
>>  (20170307111328CreateCustomFieldChoiceTable)       migrated
>>  (20170307111329CreateImportScheduleTable)          migrated
>>  (20170307111331CreateMappedFieldTable)             migrated
>>  (20170307111332CreateImportTaskTable)              migrated
>>  (20170307111334CreateSegmentationQueryTable)       migrated
>>  (20170307111335CreateSegmentationQueryJoinTable)   migrated
>>  (20170307111336CreateCalculatedFieldSettingTable)  migrated
>>  (20170307111338CreateBlacklistTable)               migrated
>>  (20170307151829CreateCalculatedFieldFilterTable)   migrated
>>  (20170315105949CreateImportTable)                  migrated
>>  (20170403134126CreateFamilyTable)                  migrated
>>  (20170410124309CreateUserTable)                    migrated
>>  (20170412103331CreateCalculatedFieldJoinTable)     migrated
>>  (20170503101946CreateSettingTable)                 migrated
>>  (20170621150818CreateCalculatedfieldQuery)         migrated

当我调用运行命令的 api 时(似乎遵循完全相同的路径)(工作未完成):

==配置

>> Name:                                               Application Migrations
>> Database Driver:                                    pdo_sqlsrv
>> Database Name:                                      xxxxxxxxxxxx
>> Configuration Source:                               manually configured
>> Version Table Name:                                 Dsys_migration_versions
>> Version Column Name:                                version
>> Migrations Namespace:                               Application\Migrations
>> Migrations Directory:                               /var/www/xxxxxx/app/DoctrineMigrations
>> Previous Version:                                   Already at first version
>> Current Version:                                    0
>> Next Version:                                        (20170307111115CreateCustomTableTable)
>> Latest Version:                                      (20170621150818CreateCalculatedfieldQuery)
>> Executed Migrations:                                0
>> Executed Unavailable Migrations:                    0
>> Available Migrations:                               19
>> New Migrations:                                     19

== 可用的迁移版本

>>  (20170307111115CreateCustomTableTable)             not migrated
>>  (20170307111322CreateCustomFieldTable)             not migrated
>>  (20170307111324CreatePresetFieldTable)             not migrated
>>  (20170307111326CreateDimensionTable)               not migrated
>>  (20170307111328CreateCustomFieldChoiceTable)       not migrated
>>  (20170307111329CreateImportScheduleTable)          not migrated
>>  (20170307111331CreateMappedFieldTable)             not migrated
>>  (20170307111332CreateImportTaskTable)              not migrated
>>  (20170307111334CreateSegmentationQueryTable)       not migrated
>>  (20170307111335CreateSegmentationQueryJoinTable)   not migrated
>>  (20170307111336CreateCalculatedFieldSettingTable)  not migrated
>>  (20170307111338CreateBlacklistTable)               not migrated
>>  (20170307151829CreateCalculatedFieldFilterTable)   not migrated
>>  (20170315105949CreateImportTable)                  not migrated
>>  (20170403134126CreateFamilyTable)                  not migrated
>>  (20170410124309CreateUserTable)                    not migrated
>>  (20170412103331CreateCalculatedFieldJoinTable)     not migrated
>>  (20170503101946CreateSettingTable)                 not migrated
>>  (20170621150818CreateCalculatedfieldQuery)         not migrated

我可以通过 bin/console 条令:migrations:migrate 命令执行等待的迁移。我不知道为什么没有这个就无法完成工作。

这是最后一个函数调用doctrine:migrations:migrate:

private function migrateDatabase(OutputInterface $output, string $version = 'latest')
{
    $command = $this->getApplication()->find('doctrine:migrations:migrate');
    $arguments = ['version' => $version];
    $inputCommand = new ArrayInput($arguments);
    $inputCommand->setInteractive(false);
    if ($command->run($inputCommand, $output) !== 0) {
        $output->writeln('<error>Fail : errors in database migrations.</error>');
    }
}

如果我在调用 api 时转储 $output,它会提示:没有可用的迁移。当显然在 constole 一个主义:migrations:status 输出 19migrations waiting...

另外,你必须知道,这个该死的东西,在针对某个数据库时有效,但在我针对其他数据库时失败。我绝对无法区分它们,因为它们是彼此的复制和过去......这就是为什么我需要调试,我可以忽略它,只是将其视为一个随机错误,但是当这个东西上线时,我不想要一个糟糕的惊喜.

[编辑] 它的 getMigrationsToExecute($direction, $to) 在我正在调试的情况下返回空,开始查找原因。如果你有任何线索。

如有任何帮助,我们将不胜感激,

感谢您的阅读。

php symfony doctrine
1个回答
0
投票

终于找到问题所在了,还没找到解决办法。

在挖掘 symfony 和学说的分支时,我停止了这个功能:

public function getMigratedVersions()
{
    $this->connect();
    $this->createMigrationTable();

    $ret = $this->connection->fetchAll("SELECT " . $this->migrationsColumnName . " FROM " . $this->migrationsTableName);

    return array_map('current', $ret);
}

它会返回一些不应该返回的东西。

为什么?因为它在错误的数据库上执行......为什么?我不知道, 我转储了 $this->connection->getDatabase();并将其设置为正确的一个,但对另一个执行查询。

这就是现在的重点,为什么即使正确输入数据库,它也没有选择正确的数据库?

干杯。

© www.soinside.com 2019 - 2024. All rights reserved.