2013-04-13 62 views
3

我已經安裝了DoctrineMigrationsBundle我Symfony2的應用程序,但是當我嘗試部署到我的開發服務器,我發現了以下錯誤:的Symfony2 + Capifony主義遷移

Do you really want to migrate dev's database? (y/N) 
y 
    * executing "sh -c ' cd /var/www/vhosts/xyz.co.uk/releases/20130413181722 && php app/console doctrine:migrations:migrate --env=dev --no-interaction'" 
    servers: ["x.xx.xx.xxx"] 
    [x.xx.xx.xxx] executing command 
** [out :: x.xx.xx.xxx]                
** [out :: x.xx.xx.xxx]      Application Migrations      
** [out :: x.xx.xx.xxx]                
** [out :: x.xx.xx.xxx] 
** [out :: x.xx.xx.xxx] Migrating up to 0 from 0 
** [out :: x.xx.xx.xxx] 
** [out :: x.xx.xx.xxx] 
** [out :: x.xx.xx.xxx]             
** [out :: x.xx.xx.xxx] [Doctrine\DBAL\Migrations\MigrationException] 
** [out :: x.xx.xx.xxx] Could not find any migrations to execute.  
** [out :: x.xx.xx.xxx]             
** [out :: x.xx.xx.xxx] 
** [out :: x.xx.xx.xxx] 
** [out :: x.xx.xx.xxx] doctrine:migrations:migrate [--write-sql] [--dry-run] [--configuration[="..."]] [--db-configuration[="..."]] [--em[="..."]] [version] 
** [out :: x.xx.xx.xxx] 
** [out :: x.xx.xx.xxx] 
    command finished in 802ms 
*** [symfony:doctrine:migrations:migrate] rolling back 
Do you really want to migrate dev's database back to version 0? (y/N) 

任何想法是什麼引起的?

這裏是我的deploy.rb文件:

set :stage_dir, 'app/config/deploy' 
set :stages, %w(production staging development) 
require 'capistrano/ext/multistage' 

set :application,   "xyz.co.uk" 
set :user,     "deployer" # The server's user for deploys 

set :normalize_asset_timestamps, false 

set :repository,   "[email protected]/xyz.co.uk.git" 
set :scm,     :git 
set :keep_releases,   3 
after "deploy:update",  "deploy:cleanup" 
set :use_sudo,    false 
set :web_path,    "web" 
set :shared_files,   ["app/config/parameters.yml"] 
set :shared_children,  [app_path + "/logs", web_path + "/uploads"] 
set :use_composer,   true 
set :update_vendors,  true 
set :dump_assetic_assets, true 
set :deploy_via,   :remote_cache 

#logger.level = Logger::MAX_LEVEL 

before "symfony:cache:warmup", "symfony:doctrine:migrations:migrate" 

after "deploy:update_code" do 
    capifony_pretty_print "--> Ensuring cache directory permissions" 
    run "setfacl -R -m u:www-data:rwX -m u:`whoami`:rwX #{latest_release}/#{cache_path}" 
    run "setfacl -dR -m u:www-data:rwX -m u:`whoami`:rwX #{latest_release}/#{cache_path}" 
    capifony_puts_ok 
end 

UPDATE

的問題是因爲我還沒有COMMITED學說遷移版本的文件,並將它們推到GitHub上。這是在更改實體後正確的過程:

php app/console doctrine:migrations:diff 
php app/console doctrine:schema:update --force 
git add app/DoctrineMigrations/Version1234.php 
git commit -a -m "migration" 
git push origin develop 
cap development deploy 
+0

你檢查過migration_versions表嗎? –

+0

是的,那裏什麼都沒有。我現在修復了它,我沒有將我的本地機器上的版本文件提交給GitHub。我已經更新了我原來的問題,您能否確認這個過程是正確的? (原問題的BOttom) – user1961082

回答

10

這不是php app/console doctrine:schema:update --forcephp app/console doctrine:migration:migrate

而且您可以使用cap development deploy:migrations以在部署之後執行遷移。

希望它有幫助。 最好的方面。

+0

謝謝。幾個問題: 1.您是否需要將每個版本添加到GitHUb?我想你是。 2.如果你使用'cap development deploy:migrations',這是否意味着我不需要在我的deploy.rb腳本中的「symfony:cache:warmup」,「symfony:doctrine:migrations:migrate」之前?那麼你部署然後遷移? 3.如果對2的回答是肯定的,那麼在部署之前是否應該將維護頁面向上放置,直到遷移完成? 再次感謝。 – user1961082

+0

1.是的,因爲你的代碼是從github克隆的。 2.是的,我認爲是。 3.這取決於您的應用程序。如果你的遷移腳本很長或很複雜,你可以使用這個包https://github.com/lexik/LexikMaintenanceBundle –

+0

真棒,謝謝! – user1961082