How to Seed the Production Database Using the Capistrano Gem

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}"
end
end

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'

Rails seed file not loading for me in production profile after 3.16 and capistrano 3.1 upgrade

After some insomnia and some more varied google searches I stumbled on this website: http://community.activestate.com/node/9065 and
Rails 3.2.11 asset precompile fails if threadsafe! enabled where they give clues that threadsafe is important.

Sure enough; if I comment out the threadsafe line in config/environments/production.rb:

  # Enable threaded mode
# config.threadsafe!

My rake db:seed tasks work in production.

the solutions in those articles, for some reason didn't work. I ended up doing this to fix it in config/environments/production.rb

 # Enable threaded mode
config.threadsafe! unless $rails_rake_task

I hope this helps somebody else out who is upgrading.

How do I create a seed file based on my development database?

There are a couple of gems that will probably provide what you're looking for e.g. seed_dump, https://github.com/rroblak/seed_dump. Also this question may help - Create seed file from data already in the database

the deploying with capistrano and uploads directory with ruby on rails

You want to make sure you set :linked_dirs in your deploy.rb e.g. for one of my sites paperclip uploads to the public/system directory so I need to make sure I symlink that one:

set :linked_dirs, ['log', 'tmp/pids', 'tmp/cache', 'tmp/sockets', 'vendor/bundle', 'public/system']

EDIT: For me this creates a symlink in [cap deploy dir]/current/public/system which goes to [cap deploy dir]/shared/public/system

Incase you didn't know before you deploy again check your [cap deploy dir]/releases you should find some of your old deploys so you might be able to recover your uploads.


From the gem github page (https://github.com/capistrano/rails):

Symlinks

You'll probably want to symlink Rails shared files and directories like log, tmp and public/uploads. Make sure you enable it by setting linked_dirs and linked_files options:

# deploy.rb
set :linked_dirs, fetch(:linked_dirs, []).push('log', 'tmp/pids', 'tmp/cache', 'tmp/sockets', 'vendor/bundle', 'public/system', 'public/uploads')
set :linked_files, fetch(:linked_files, []).push('config/database.yml', 'config/secrets.yml')

Capistrano commands for creating database

Capistrano doesn't provide any recipes for creating the database. As mentioned in this capistrano googlegroups thread:

it's not something that is generic enough to warrant inclusion in the
core, and it really falls under the domain of "administration" which
we try to avoid

Others have succeeded in automating the creation of database via capistrano by directly invoking the database creation command from the script.

The same thread mentioned above provides a link to a capistrano script which creates a mysql database by running the mysql command from capistrano.

Here is another useful blogpost: Create MySQL database with Capistrano

newbie: how to get some database columns with data on production server database?

Sounds like you just want a restore, so I would just:

You should do a database backup using your dbms tools, copy the file locally, and restore it.

How to seed a model (using the seed-fu gem) that has been translated using the globalize3 gem (Rails)

I've never used seed-fu, but I know globalize3 fairly well and Product_translation doesn't look right to me. Shouldn't it be Product::Translation (or Product.translation_class)?

Maybe this would work:

product_translations.rb

Product::Translation.seed(:id,
{ :id => 1, :product_id => 1, :locale => "en", :name => "foo"},
{ :id => 2, :product_id => 1, :locale => "en", :name => "bar"}
)


Related Topics



Leave a reply



Submit