0

When mina deploy runs an error occurs during migration that pg gem is not loaded.The problem is that the gem is loaded in my gem file but during the mina's bundle install pg gem doesn't get installed.

Any ideas how to fix this issue?

-----> Migrating database
   $ RAILS_ENV="production" bundle exec rake db:migrate
   rake aborted!
   Gem::LoadError: Specified 'postgresql' for database adapter, but the gem is not loaded. Add `gem 'pg'` to your Gemfile (and ensure its version is at the minimum required by ActiveRecord).

Gemfile

gem 'mail_form'
gem 'devise'
gem 'cancancan'

group :production do
     gem 'pg'
     gem 'therubyracer' 
   end

database.yml

production:  
    adapter: postgresql
    encoding: unicode
    database: tech
    username: admin
    password: PASSWORD
    host: localhost

mina deploy --verbose

 -----> Loading rbenv
       $ export RBENV_ROOT="$HOME/.rbenv"
       $ export PATH="$HOME/.rbenv/bin:$PATH"
       $ eval "$(rbenv init -)"

-----> Creating a temporary build path
       $ touch "deploy.lock"
       $ mkdir -p "$build_path"
       $ cd "$build_path"

-----> Fetching new git commits
       $ (cd "/home/deployer/tech/scm" && git fetch "git@bitbucket.org:gns/tech.git" "master:m       
       $ (cd "/home/deployer/tech/scm" && git fetch "git@bitbucket.org:gns/tech.git" "master:master" --force)

-----> Using git branch 'master'
       $ git clone "/home/deployer/tech/scm" . --recursive --branch "master"
       Cloning into '.'...
       done.

-----> Using this git commit

       $ git --no-pager log --format='%aN (%h):%n> %s' -n 1
       yiannis (4ef997e):
       > Gemfile
       $ rm -rf .git


-----> Symlinking shared paths
       $ mkdir -p "./config"
       $ mkdir -p "."
       $ rm -rf "./config/database.yml"
       $ ln -s "/home/deployer/tech/shared/config/database.yml" "./config/database.yml"
       $ rm -rf "./log"
       $ ln -s "/home/deployer/tech/shared/log" "./log"
       $ rm -rf "./config/secrets.yml"
       $ ln -s "/home/deployer/tech/shared/config/secrets.yml" "./config/secrets.yml"

-----> Installing gem dependencies using Bundler
       $ mkdir -p "/home/deployer/tech/shared/bundle"
       $ mkdir -p "./vendor"
       $ ln -s "/home/deployer/tech/shared/bundle" "./vendor/bundle"
       $ bundle install --without development:test --path "./vendor/bundle" --deployment
       Fetching gem metadata from http://rubygems.org/........
       Using rake 10.4.2
       Using i18n 0.6.11
       Using json 1.8.1
       Using minitest 5.5.0
       Using thread_safe 0.3.4
       Using tzinfo 1.2.2
       Using activesupport 4.1.8
       Using builder 3.2.2
       Using erubis 2.7.0
       Using actionview 4.1.8
       Using rack 1.5.2
       Using rack-test 0.6.2
       Using actionpack 4.1.8
       Using mime-types 2.4.3
       Using mail 2.6.3
       Using actionmailer 4.1.8
       Using activemodel 4.1.8
       Using arel 5.0.1.20140414130214
       Using activerecord 4.1.8
       Using bundler 1.8.0.pre
       Using thor 0.19.1
       Using railties 4.1.8
       Using hike 1.2.3
       Using multi_json 1.10.1
       Using tilt 1.4.1
       Using sprockets 2.12.3
       Using sprockets-rails 2.2.2
       Using rails 4.1.8
       Using animate-rails 1.0.7
       Using aws-sdk-v1 1.59.1
       Using aws-sdk 1.59.1
       Using cancancan 1.9.2
       Using chronic 0.10.2
       Using climate_control 0.0.3
       Using cocaine 0.5.5
       Using coffee-script-source 1.8.0
       Using execjs 2.2.2
       Using coffee-script 2.3.0
       Using coffee-rails 4.0.1
       Using orm_adapter 0.5.0
       Using responders 1.1.2
       Using warden 1.2.3
       Using devise 3.4.1
       Using figaro 1.0.0
       Using font-awesome-rails 4.2.0.0
       Using foundation-datetimepicker-rails 0.1.3
       Using sass 3.2.19
       Using foundation-rails 5.4.5.0
       Using friendly_id 5.0.4
       Using google-webfonts-rails 0.0.4
       Using jbuilder 2.2.6
       Using jquery-rails 3.1.2
       Using kaminari 0.16.1
       Using libv8 3.16.14.7
       Using mail_form 1.5.0
       Using newrelic_rpm 3.9.8.273
       Using paperclip 4.2.1
       Using pg_search 0.7.8
       Using rdoc 4.2.0
       Using ref 1.0.5
       Using sass-rails 4.0.5
       Using sdoc 0.4.1
       Using therubyracer 0.12.1
       Using uglifier 2.6.0
       Using whenever 0.9.4
       Bundle complete! 25 Gemfile dependencies, 65 gems now installed.
       Gems in the groups development and test were not installed.
       Bundled gems are installed into ./vendor/bundle.

-----> Migrating database
       $ RAILS_ENV="production" bundle exec rake db:migrate
       rake aborted!
       Gem::LoadError: Specified 'postgresql' for database adapter, but the gem is not loaded. Add `gem 'pg'` to your Gemfile (and ensure its version is at the minimum required by ActiveRecord).
       /home/deployer/tech/tmp/build-142229948411279/vendor/bundle/ruby/2.1.0/gems/activerecord-4.1.8/lib/active_record/connection_adapters/connection_specification.rb:190:in `rescue in spec'
       /home/deployer/tech/tmp/build-142229948411279/vendor/bundle/ruby/2.1.0/gems/activerecord-4.1.8/lib/active_record/connection_adapters/connection_specification.rb:187:in `spec'
       /home/deployer/tech/tmp/build-142229948411279/vendor/bundle/ruby/2.1.0/gems/activerecord-4.1.8/lib/active_record/connection_handling.rb:50:in `establish_connection'
       /home/deployer/tech/tmp/build-142229948411279/vendor/bundle/ruby/2.1.0/gems/activerecord-4.1.8/lib/active_record/railtie.rb:129:in `block (2 levels) in <class:Railtie>'
       /home/deployer/tech/tmp/build-142229948411279/vendor/bundle/ruby/2.1.0/gems/activesupport-4.1.8/lib/active_support/lazy_load_hooks.rb:38:in `instance_eval'
       /home/deployer/tech/tmp/build-142229948411279/vendor/bundle/ruby/2.1.0/gems/activesupport-4.1.8/lib/active_support/lazy_load_hooks.rb:38:in `execute_hook'
       /home/deployer/tech/tmp/build-142229948411279/vendor/bundle/ruby/2.1.0/gems/activesupport-4.1.8/lib/active_support/lazy_load_hooks.rb:28:in `block in on_load'
       /home/deployer/tech/tmp/build-142229948411279/vendor/bundle/ruby/2.1.0/gems/activesupport-4.1.8/lib/active_support/lazy_load_hooks.rb:27:in `each'
       /home/deployer/tech/tmp/build-142229948411279/vendor/bundle/ruby/2.1.0/gems/activesupport-4.1.8/lib/active_support/lazy_load_hooks.rb:27:in `on_load'
       /home/deployer/tech/tmp/build-142229948411279/vendor/bundle/ruby/2.1.0/gems/activerecord-4.1.8/lib/active_record/railtie.rb:118:in `block in <class:Railtie>'
       /home/deployer/tech/tmp/build-142229948411279/vendor/bundle/ruby/2.1.0/gems/railties-4.1.8/lib/rails/initializable.rb:30:in `instance_exec'
       /home/deployer/tech/tmp/build-142229948411279/vendor/bundle/ruby/2.1.0/gems/railties-4.1.8/lib/rails/initializable.rb:30:in `run'
       /home/deployer/tech/tmp/build-142229948411279/vendor/bundle/ruby/2.1.0/gems/railties-4.1.8/lib/rails/initializable.rb:55:in `block in run_initializers'
       /home/deployer/tech/tmp/build-142229948411279/vendor/bundle/ruby/2.1.0/gems/railties-4.1.8/lib/rails/initializable.rb:54:in `run_initializers'
       /home/deployer/tech/tmp/build-142229948411279/vendor/bundle/ruby/2.1.0/gems/railties-4.1.8/lib/rails/application.rb:300:in `initialize!'
       /home/deployer/tech/tmp/build-142229948411279/config/environment.rb:5:in `<top (required)>'
       /home/deployer/tech/tmp/build-142229948411279/vendor/bundle/ruby/2.1.0/gems/activesupport-4.1.8/lib/active_support/dependencies.rb:247:in `require'
       /home/deployer/tech/tmp/build-142229948411279/vendor/bundle/ruby/2.1.0/gems/activesupport-4.1.8/lib/active_support/dependencies.rb:247:in `block in require'
       /home/deployer/tech/tmp/build-142229948411279/vendor/bundle/ruby/2.1.0/gems/activesupport-4.1.8/lib/active_support/dependencies.rb:232:in `load_dependency'
       /home/deployer/tech/tmp/build-142229948411279/vendor/bundle/ruby/2.1.0/gems/activesupport-4.1.8/lib/active_support/dependencies.rb:247:in `require'
       /home/deployer/tech/tmp/build-142229948411279/vendor/bundle/ruby/2.1.0/gems/railties-4.1.8/lib/rails/application.rb:276:in `require_environment!'
       /home/deployer/tech/tmp/build-142229948411279/vendor/bundle/ruby/2.1.0/gems/railties-4.1.8/lib/rails/application.rb:389:in `block in run_tasks_blocks'
       Gem::LoadError: pg is not part of the bundle. Add it to Gemfile.
       /home/deployer/tech/tmp/build-142229948411279/vendor/bundle/ruby/2.1.0/gems/activerecord-4.1.8/lib/active_record/connection_adapters/postgresql_adapter.rb:13:in `<top (required)>'
       /home/deployer/tech/tmp/build-142229948411279/vendor/bundle/ruby/2.1.0/gems/activesupport-4.1.8/lib/active_support/dependencies.rb:247:in `require'
       /home/deployer/tech/tmp/build-142229948411279/vendor/bundle/ruby/2.1.0/gems/activesupport-4.1.8/lib/active_support/dependencies.rb:247:in `block in require'
       /home/deployer/tech/tmp/build-142229948411279/vendor/bundle/ruby/2.1.0/gems/activesupport-4.1.8/lib/active_support/dependencies.rb:232:in `load_dependency'
       /home/deployer/tech/tmp/build-142229948411279/vendor/bundle/ruby/2.1.0/gems/activesupport-4.1.8/lib/active_support/dependencies.rb:247:in `require'
       /home/deployer/tech/tmp/build-142229948411279/vendor/bundle/ruby/2.1.0/gems/activerecord-4.1.8/lib/active_record/connection_adapters/connection_specification.rb:188:in `spec'
       /home/deployer/tech/tmp/build-142229948411279/vendor/bundle/ruby/2.1.0/gems/activerecord-4.1.8/lib/active_record/connection_handling.rb:50:in `establish_connection'
       /home/deployer/tech/tmp/build-142229948411279/vendor/bundle/ruby/2.1.0/gems/activerecord-4.1.8/lib/active_record/railtie.rb:129:in `block (2 levels) in <class:Railtie>'
       /home/deployer/tech/tmp/build-142229948411279/vendor/bundle/ruby/2.1.0/gems/activesupport-4.1.8/lib/active_support/lazy_load_hooks.rb:38:in `instance_eval'
       /home/deployer/tech/tmp/build-142229948411279/vendor/bundle/ruby/2.1.0/gems/activesupport-4.1.8/lib/active_support/lazy_load_hooks.rb:38:in `execute_hook'
       /home/deployer/tech/tmp/build-142229948411279/vendor/bundle/ruby/2.1.0/gems/activesupport-4.1.8/lib/active_support/lazy_load_hooks.rb:28:in `block in on_load'
       /home/deployer/tech/tmp/build-142229948411279/vendor/bundle/ruby/2.1.0/gems/activesupport-4.1.8/lib/active_support/lazy_load_hooks.rb:27:in `each'
       /home/deployer/tech/tmp/build-142229948411279/vendor/bundle/ruby/2.1.0/gems/activesupport-4.1.8/lib/active_support/lazy_load_hooks.rb:27:in `on_load'
       /home/deployer/tech/tmp/build-142229948411279/vendor/bundle/ruby/2.1.0/gems/activerecord-4.1.8/lib/active_record/railtie.rb:118:in `block in <class:Railtie>'
       /home/deployer/tech/tmp/build-142229948411279/vendor/bundle/ruby/2.1.0/gems/railties-4.1.8/lib/rails/initializable.rb:30:in `instance_exec'
       /home/deployer/tech/tmp/build-142229948411279/vendor/bundle/ruby/2.1.0/gems/railties-4.1.8/lib/rails/initializable.rb:30:in `run'
       /home/deployer/tech/tmp/build-142229948411279/vendor/bundle/ruby/2.1.0/gems/railties-4.1.8/lib/rails/initializable.rb:55:in `block in run_initializers'
       /home/deployer/tech/tmp/build-142229948411279/vendor/bundle/ruby/2.1.0/gems/railties-4.1.8/lib/rails/initializable.rb:54:in `run_initializers'
       /home/deployer/tech/tmp/build-142229948411279/vendor/bundle/ruby/2.1.0/gems/railties-4.1.8/lib/rails/application.rb:300:in `initialize!'
       /home/deployer/tech/tmp/build-142229948411279/config/environment.rb:5:in `<top (required)>'
       /home/deployer/tech/tmp/build-142229948411279/vendor/bundle/ruby/2.1.0/gems/activesupport-4.1.8/lib/active_support/dependencies.rb:247:in `require'
       /home/deployer/tech/tmp/build-142229948411279/vendor/bundle/ruby/2.1.0/gems/activesupport-4.1.8/lib/active_support/dependencies.rb:247:in `block in require'
       /home/deployer/tech/tmp/build-142229948411279/vendor/bundle/ruby/2.1.0/gems/activesupport-4.1.8/lib/active_support/dependencies.rb:232:in `load_dependency'
       /home/deployer/tech/tmp/build-142229948411279/vendor/bundle/ruby/2.1.0/gems/activesupport-4.1.8/lib/active_support/dependencies.rb:247:in `require'
       /home/deployer/tech/tmp/build-142229948411279/vendor/bundle/ruby/2.1.0/gems/railties-4.1.8/lib/rails/application.rb:276:in `require_environment!'
       /home/deployer/tech/tmp/build-142229948411279/vendor/bundle/ruby/2.1.0/gems/railties-4.1.8/lib/rails/application.rb:389:in `block in run_tasks_blocks'
       Tasks: TOP => db:migrate => environment
       (See full trace by running task with --trace)
 !     ERROR: Deploy failed.

-----> Cleaning up build
       $ rm -rf "$build_path"
       Unlinking current
       $ rm -f "deploy.lock"
       OK

 !     Command failed.
       Failed with status 19
yns
  • 5
  • 2

1 Answers1

0

I'm sure set :rails_env, 'production' sets environment for rake and rails commands only, so try bundle_prefix.

In worst case move gem 'pg' to common section of Gemfile.

sashaegorov
  • 1,821
  • 20
  • 26
  • SashaEgorov thanks but that's not working.I think the problem might be with the ENV – yns Jan 25 '15 at 18:55
  • @JeanPoly Hmmmm. It seems to be bit more tricky, than I thought. Can you diagnose problem more deeply? For example, following steps may be reasonable: 1) check your Rails app use exact Ruby interpreter which is supposed (it is better to check when you work with rbenv, RVM managers) 2) Next is to check this line code `require 'pg'` in IRB session (this helps to determine can't Ruby load this gem or not) 3) Enable full backtrace when running rake task, may be it contains something helpful. – sashaegorov Jan 26 '15 at 03:19
  • @JeanPoly 4) Check bundler's log after deployment attempt, to be sure it ran successfully and `pg` was installed. – sashaegorov Jan 26 '15 at 03:25
  • when i run the require 'pg' it returns true. During the bundle install the pg gem is not installed.Also I checked the bundlers gems directory and it's not listed. I updated the error log in my question. – yns Jan 26 '15 at 12:05
  • @JeanPoly Sorry, how about `$ mina deploy --verbose`? How does it tell? – sashaegorov Jan 26 '15 at 17:39
  • I can't see anything thats wrong. I posted it in the question so you can have a look.Thanks – yns Jan 26 '15 at 19:25
  • @JeanPoly before I'll give up. As I see `pg` is absent in mina's log. So, according info: this http://bundler.io/man/bundle-install.1.html#DEPLOYMENT-MODE please check if `pg` gem exists in `Gemfile.lock` (!). Yes, Gemfile and Gemfile.lock files may be out of sync! That is true. If it doesn't have `pg`, do the following: 1) Remove outdated Gemfile.lock 2) Run `bundle install` locally on your Development machine 3) After that check `pg` gem in Gemfile.lock, and finally run `mina`. As I found `mina deploy --verbose` has `invoke 'bundle:install'` which run `bundle install ... --deployment`. – sashaegorov Jan 27 '15 at 15:12
  • @JeanPoly mina's log also shows that your Gemfile doesn't have some gems *actually installed* by bundler. So backup Gemfile.lock first and investigate... That stuff is pretty strange. – sashaegorov Jan 27 '15 at 15:14