3

I've installed the DoctrineMigrationsBundle to my Symfony2 app, however when I try to deploy to my development server I'm getting the following error:

    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)

Any idea what's causing this?

Here is my deploy.rb file:

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

UPDATE

The issue was because I hadn't commited the doctrine migration version files and pushed them to GitHub. Is this the correct process after making a change to an entity:

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
user1961082
  • 1,015
  • 17
  • 41
  • Have you check the migration_versions table ? – Benjamin Lazarecki Apr 14 '13 at 19:35
  • Yes, there was nothing in there. I've fixed it now, I hadn't committed the version files from my local machine to GitHub. I've updated my original question, can you please confirm the process is correct? (BOttom of original question) – user1961082 Apr 14 '13 at 20:12

1 Answers1

11

It's not php app/console doctrine:schema:update --force but php app/console doctrine:migration:migrate.

And you may use cap development deploy:migrations in order to execute the migrations after the deployment.

Hope it's helpful. Best regard.

Benjamin Lazarecki
  • 2,950
  • 1
  • 20
  • 27
  • Thanks. Few questions: 1. Do you have to add each version to GitHUb? I suppose you do. 2. If you use `cap development deploy:migrations` does that mean I wouldn't need before "symfony:cache:warmup", "symfony:doctrine:migrations:migrate" in my deploy.rb script? So you deploy and then migrate? 3. If the answer to 2 is yes, then should you put a maintenance page up when you deploy until the migrations are complete? Thanks again. – user1961082 Apr 14 '13 at 22:17
  • 1. Yes because your code is clone from github. 2. Yes I think so. 3. It's depends of your application. If your migrations script is very long or complex, you can use this bundle https://github.com/lexik/LexikMaintenanceBundle – Benjamin Lazarecki Apr 14 '13 at 22:32
  • I don't suppose you can help with this question - http://stackoverflow.com/questions/15943276/symfony2-capistrano-deploying-to-cdn :) – user1961082 Apr 14 '13 at 22:44