2017-10-04 149 views
1

這裏就是我堅持:的Symfony和學說遷移

我打電話是執行學說遷移的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那運行命令(似乎遵循完全相同的路徑)(JOB NOT DONE):

==配置

>> 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 

我可以通過倉/控制檯教義執行等待遷移:遷移:遷移命令。我不知道爲什麼這項工作沒有完成。

這裏是最後的函數調用學說:遷移:遷移:

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它prompte:沒有遷移aviailable。當明顯地構造一個主義:遷移:狀態輸出19遷移正在等待...

另外,你必須知道,這個該死的東西,適用於某個目標數據庫,但失敗時,我瞄準別人。我絕對不能說出區別,因爲他們是彼此的複製和過去......這就是爲什麼我需要調試,我可以忽略它,只是把它看作是一個隨機錯誤,但當這件事情上線時,我不想要一個不好的驚喜。

[編輯] 它的getMigrationsToExecute($方向,$到),在我調試的情況下返回空,開始查找原因。如果你有任何線索。

任何幫助,將不勝感激,

感謝您的閱讀。

+0

從api和控制檯輸出'數據庫名稱'是否相同? Doctrine使用表(migration_versions)來存儲已執行的遷移。 – Mcsky

+0

是的,它是一樣的...我已經setInteractive爲false,所以這不是理論上的提示。 另外,我已經有了在api調用中正確創建的存儲過程,因此它確認了DB是正確的。 – Culdz

+0

你能告訴我們在你的api上執行最新教條遷移的代碼部分嗎? – Mcsky

回答

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();並將其設置爲正確的,但對另一個執行查詢。

這就是問題所在,爲什麼它沒有選擇正確的數據庫,即使它被正確地餵食?

乾杯。