db:schema:load vs db:migrate with capistrano

前端 未结 4 1879
说谎
说谎 2021-01-31 18:54

I have a rails app that I\'m moving to another server and I figure I should use db:schema:load to create the mysql database because it\'s recommended. My problem is that I\'m u

4条回答
  •  礼貌的吻别
    2021-01-31 19:25

    In Capistrano 3 / Rails 4, the default deploy syntax has changed. You can do this instead:

    desc 'Deploy app for first time'
    task :cold do
      invoke 'deploy:starting'
      invoke 'deploy:started'
      invoke 'deploy:updating'
      invoke 'bundler:install'
      invoke 'deploy:db_setup' # This replaces deploy:migrations
      invoke 'deploy:compile_assets'
      invoke 'deploy:normalize_assets'
      invoke 'deploy:publishing'
      invoke 'deploy:published'
      invoke 'deploy:finishing'
      invoke 'deploy:finished'
    end
    
    desc 'Setup database'
    task :db_setup do
      on roles(:db) do
        within release_path do
          with rails_env: (fetch(:rails_env) || fetch(:stage)) do
            execute :rake, 'db:setup' # This creates the database tables AND seeds
          end
        end
      end
    end
    

    If you're cautious of invoking the standard deploy tasks manually in the :cold task (as they may change in upcoming version or if you have a custom deploy task), you can also simply call deploy:db_setup before running deploy.

    To perform db:schema:load instead of db:setup, you can simply change the rake task, like so:

    desc 'Load DB Schema'
    task :db_schema_load do
      ...
            execute :rake, 'db:schema:load'
      ...
    end
    

提交回复
热议问题