How to seed the production database using the Capistrano gem?

后端 未结 6 1979
不思量自难忘°
不思量自难忘° 2021-01-30 01:47

I am using Ruby on Rails 3.0.9 and I would like to seed the production database in order to add some record without re-building all the database (that is, with

6条回答
  •  离开以前
    2021-01-30 02:35

    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! :)

提交回复
热议问题