I have a rails application that uses a single DO image.
I can start any of rake db:*successfully, but when I start rails console, I cannot connect to db.
How can i fix this? The application is working fine. So I think this is a problem rails console.
Console output:
deployer:/home/rails$ RAILS_ENV=production bundle exec rake db:migrate
ActiveRecord::SchemaMigration Load (3.2ms) SELECT "schema_migrations".* FROM "schema_migrations"
deployer:/home/rails$ echo $APP_DATABASE_PASSWORD
[redacted database password]
deployer:/home/rails$ RAILS_ENV=production bundle exec rails console
Running via Spring preloader in process 25038
Loading production environment (Rails 4.2.6)
2.3.0 :001 > User.connection
PG::ConnectionBad: fe_sendauth: no password supplied
database.yml
default: &default
adapter: postgresql
encoding: unicode
pool: 5
host: localhost
username: rails
password: <%= ENV['APP_DATABASE_PASSWORD'] %>
production:
<<: *default
database: production
username: rails
password: <%= ENV['APP_DATABASE_PASSWORD'] %>
EDIT
Looking around, I found that it ActiveRecord::Base.configurationshas password: nil. Why then does the server process read the password, but the console does not work?
I added ActiveRecord::Base.configurationsto the initializer. Upon initialization, a password is present.
The console ActiveRecord::Base.configurationsreturns all information as expected, except for the password. I even reloaded the default vars with. /etc/defaults/unicorn
EDIT 2
ActiveRecord::Base.configurations on RAILS_ENV=production bundle exec rails console
{"default"=>
{"adapter"=>"postgresql",
"encoding"=>"unicode",
"pool"=>5,
"host"=>"localhost",
"username"=>"rails",
"password"=>nil},
"development"=>
{"adapter"=>"postgresql",
"encoding"=>"unicode",
"pool"=>5,
"host"=>"localhost",
"username"=>"rails",
"password"=>nil,
"database"=>"development"},
"test"=>
{"adapter"=>"postgresql",
"encoding"=>"unicode",
"pool"=>5,
"host"=>"localhost",
"username"=>"rails",
"password"=>nil,
"database"=>"test"},
"production"=>
{"adapter"=>"postgresql",
"encoding"=>"unicode",
"pool"=>5,
"host"=>"localhost",
"username"=>"rails",
"password"=>nil,
"database"=>"production"}}
ActiveRecord::Base.configurations on APP_DATABASE_PASSWORD=password RAILS_ENV=production bundle exec rails console
{"default"=>
{"adapter"=>"postgresql",
"encoding"=>"unicode",
"pool"=>5,
"host"=>"localhost",
"username"=>"rails",
"password"=>nil},
"development"=>
{"adapter"=>"postgresql",
"encoding"=>"unicode",
"pool"=>5,
"host"=>"localhost",
"username"=>"rails",
"password"=>nil,
"database"=>"development"},
"test"=>
{"adapter"=>"postgresql",
"encoding"=>"unicode",
"pool"=>5,
"host"=>"localhost",
"username"=>"rails",
"password"=>nil,
"database"=>"test"},
"production"=>
{"adapter"=>"postgresql",
"encoding"=>"unicode",
"pool"=>5,
"host"=>"localhost",
"username"=>"rails",
"password"=>nil,
"database"=>"production"}}
ActiveRecord::Base.configurations on RAILS_ENV=production bundle exec rails server
{"default"=>
{"adapter"=>"postgresql",
"encoding"=>"unicode",
"pool"=>5,
"host"=>"localhost",
"username"=>"rails",
"password"=>[password]},
"development"=>
{"adapter"=>"postgresql",
"encoding"=>"unicode",
"pool"=>5,
"host"=>"localhost",
"username"=>"rails",
"password"=>[password],
"database"=>"development"},
"test"=>
{"adapter"=>"postgresql",
"encoding"=>"unicode",
"pool"=>5,
"host"=>"localhost",
"username"=>"rails",
"password"=>[password],
"database"=>"test"},
"production"=>
{"adapter"=>"postgresql",
"encoding"=>"unicode",
"pool"=>5,
"host"=>"localhost",
"username"=>"rails",
"password"=>[password],
"database"=>"production"}}