Symfony2 + Capifony Doctrine迁移

3

我已经将DoctrineMigrationsBundle安装到我的Symfony2应用程序中,但是当我尝试部署到开发服务器时,出现以下错误:

    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,            "git@github.xyz/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

更新

问题在于我没有提交Doctrine迁移版本文件并将其推送到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

你有检查过 migration_versions 表吗? - Benjamin Lazarecki
是的,里面什么也没有。我已经修复了,我没有将版本文件从我的本地机器提交到GitHub。我已更新原始问题,请确认过程是否正确?(原始问题底部) - user1961082
1个回答

11

这不是 php app/console doctrine:schema:update --force,而是 php app/console doctrine:migration:migrate

并且您可以在部署后使用 cap development deploy:migrations 来执行迁移。

希望对你有所帮助。 最好的问候。


谢谢。几个问题:
  1. 您是否必须将每个版本添加到GitHub?我想是的。
  2. 如果您使用 cap development deploy:migrations,那么在我的deploy.rb脚本中之前就不需要“symfony:cache:warmup”,“symfony:doctrine:migrations:migrate”了吗?所以您先部署,然后再迁移?
  3. 如果问题2的答案是肯定的,那么在迁移完成之前,您应该放置一个维护页面吗?
再次感谢。
- user1961082
  1. 是的,因为你的代码是从Github克隆的。
  2. 是的,我想是这样。
  3. 这取决于你的应用程序。如果你的迁移脚本非常长或复杂,你可以使用这个bundle https://github.com/lexik/LexikMaintenanceBundle。
- Benjamin Lazarecki
我不确定你是否能帮忙回答这个问题 - http://stackoverflow.com/questions/15943276/symfony2-capistrano-deploying-to-cdn :) - user1961082

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接