capistrano / symfony

Capistrano tasks for deploying the Symfony standard edition
MIT License
353 stars 65 forks source link

How to run doctrine:migrations:migrate on demand #47

Closed webdevilopers closed 8 years ago

webdevilopers commented 8 years ago

Current setup following readme:

namespace :tasks do
  task :migrate do
    invoke 'symfony:console', 'doctrine:migrations:migrate'
  end
end

namespace :deploy do
  after :starting, 'composer:install_executable'
  after :updated, 'tasks:migrate'
end

I don't always have migrations. I tried removing the '--no-interaction flag but the interaction never runs if no migrations are present. My cap aborts:

(Backtrace restricted to imported tasks)
cap aborted!
SSHKit::Runner::ExecuteError: Exception while executing as ...@...: php exit status: 4
php stdout: Application Migrations                    

Migrating up to 0 from 0
php stderr: [Doctrine\DBAL\Migrations\MigrationException]  
  Could not find any migrations to execute.      

doctrine:migrations:migrate [--write-sql] [--dry-run] [--query-time] [--configuration[="..."]] [--db-configuration[="..."]] [--em[="..."]] [version]

SSHKit::Command::Failed: php exit status: 4
php stdout: Application Migrations                    

Migrating up to 0 from 0
php stderr: [Doctrine\DBAL\Migrations\MigrationException]  
  Could not find any migrations to execute.

Is there any way to run the task on demand like with Capifony those days? http://capifony.org/#useful-tasks

Possibly related to https://github.com/capistrano/symfony/issues/28 by @jurgenweber

greg0ire commented 8 years ago

Strange. I have almost the same as you and there is no problem, here is the output I get when there is no migration :

DEBUG[d15e3ef5] Command: cd /home/www/bnf_mednum/releases/20151113171923 && ( SYMFONY_ENV=prod /usr/bin/env php app/console doctrine:migrations:migrate --no-interaction --no-debug )
DEBUG[d15e3ef5]                                                                       
DEBUG[d15e3ef5]                             Application Migrations                    
DEBUG[d15e3ef5]                                                                       
DEBUG[d15e3ef5]         
DEBUG[d15e3ef5]         No migrations to execute.

Here how migrations are plugged in : after 'deploy:finishing', 'mycompany:migrations:migrate'

And here is the task I'm using :

namespace :mycompany do
  desc 'Executes a migration to the latest available version'
  namespace :migrations do
    task :migrate do
      invoke 'symfony:console', 'doctrine:migrations:migrate', '--no-interaction'
    end
  end
end
greg0ire commented 8 years ago

Notice how it does not seem to go to stderr… here is what I am using :

c show --installed|grep migration
doctrine/doctrine-migrations-bundle      1.0.1                Symfony DoctrineMigrationsBundle
doctrine/migrations                      v1.0.0               Database Schema migrations using Doctrine DBAL
webdevilopers commented 8 years ago

That hint helped @greg0ire . The current version was missing the initial DoctrineMigrations folder. No the error is gone. Thanks!

greg0ire commented 8 years ago

Oh I see. Good job finding that!