How to seed the production database using the Capistrano gem? How to seed the production database using the Capistrano gem? ruby-on-rails ruby-on-rails

How to seed the production database using the Capistrano gem?


If you are using bundler, then the capistrano task should be:

namespace :deploy do  desc "reload the database with seed data"  task :seed do    run "cd #{current_path}; bundle exec rake db:seed RAILS_ENV=#{rails_env}"  endend

and it might be placed in a separate file, such as lib/deploy/seed.rb and included in your deploy.rb file using following command:

load 'lib/deploy/seed'


This worked for me:

task :seed do puts "\n=== Seeding Database ===\n" on primary :db do  within current_path do    with rails_env: fetch(:stage) do      execute :rake, 'db:seed'    end  end endend

capistrano 3, Rails 4


Using Capistrano 3, Rails 4, and SeedMigrations, I created a Capistrano seed.rb task under /lib/capistrano/tasks:

namespace :deploy do  desc 'Runs rake db:seed for SeedMigrations data'  task :seed => [:set_rails_env] do    on primary fetch(:migration_role) do      within release_path do        with rails_env: fetch(:rails_env) do          execute :rake, "db:seed"        end      end    end  end  after 'deploy:migrate', 'deploy:seed'end

My seed migrations are now completely separate from my schema migrations, and ran following the db:migrate process. What a joy! :)