Ruby PostgreSQL - ruby-on-rails

So for background, I just got a new computer and put Xubuntu 13.04 on it, then proceeded to put on RVM, Ruby, and Rails. I've slowly been adding libs as I run into problems, but can't find the solution to this one.
When running rake db:migrate, I get the following output:
rake db:migraterake aborted!
PG::ConnectionBad: fe_sendauth: no password supplied
/home/erik/.rvm/gems/ruby-2.0.0-p451/gems/activerecord-4.0.1/lib/active_record/connection_adapters/postgresql_adapter.rb:831:in `initialize'
/home/erik/.rvm/gems/ruby-2.0.0-p451/gems/activerecord-4.0.1/lib/active_record/connection_adapters/postgresql_adapter.rb:831:in `new'
/home/erik/.rvm/gems/ruby-2.0.0-p451/gems/activerecord-4.0.1/lib/active_record/connection_adapters/postgresql_adapter.rb:831:in `connect'
/home/erik/.rvm/gems/ruby-2.0.0-p451/gems/activerecord-4.0.1/lib/active_record/connection_adapters/postgresql_adapter.rb:548:in `initialize'
/home/erik/.rvm/gems/ruby-2.0.0-p451/gems/activerecord-4.0.1/lib/active_record/connection_adapters/postgresql_adapter.rb:41:in `new'
/home/erik/.rvm/gems/ruby-2.0.0-p451/gems/activerecord-4.0.1/lib/active_record/connection_adapters/postgresql_adapter.rb:41:in `postgresql_connection'
/home/erik/.rvm/gems/ruby-2.0.0-p451/gems/activerecord-4.0.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:440:in `new_connection'
/home/erik/.rvm/gems/ruby-2.0.0-p451/gems/activerecord-4.0.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:450:in `checkout_new_connection'
/home/erik/.rvm/gems/ruby-2.0.0-p451/gems/activerecord-4.0.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:421:in `acquire_connection'
/home/erik/.rvm/gems/ruby-2.0.0-p451/gems/activerecord-4.0.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:356:in `block in checkout'
/home/erik/.rvm/gems/ruby-2.0.0-p451/gems/activerecord-4.0.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:355:in `checkout'
/home/erik/.rvm/gems/ruby-2.0.0-p451/gems/activerecord-4.0.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:265:in `block in connection'
/home/erik/.rvm/gems/ruby-2.0.0-p451/gems/activerecord-4.0.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:264:in `connection'
/home/erik/.rvm/gems/ruby-2.0.0-p451/gems/activerecord-4.0.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:546:in `retrieve_connection'
/home/erik/.rvm/gems/ruby-2.0.0-p451/gems/activerecord-4.0.1/lib/active_record/connection_handling.rb:79:in `retrieve_connection'
/home/erik/.rvm/gems/ruby-2.0.0-p451/gems/activerecord-4.0.1/lib/active_record/connection_handling.rb:53:in `connection'
/home/erik/.rvm/gems/ruby-2.0.0-p451/gems/activerecord-4.0.1/lib/active_record/migration.rb:863:in `initialize'
/home/erik/.rvm/gems/ruby-2.0.0-p451/gems/activerecord-4.0.1/lib/active_record/migration.rb:764:in `new'
/home/erik/.rvm/gems/ruby-2.0.0-p451/gems/activerecord-4.0.1/lib/active_record/migration.rb:764:in `up'
/home/erik/.rvm/gems/ruby-2.0.0-p451/gems/activerecord-4.0.1/lib/active_record/migration.rb:742:in `migrate'
/home/erik/.rvm/gems/ruby-2.0.0-p451/gems/activerecord-4.0.1/lib/active_record/railties/databases.rake:42:in `block (2 levels) in <top (required)>'
/home/erik/.rvm/gems/ruby-2.0.0-p451/bin/ruby_executable_hooks:15:in `eval'
/home/erik/.rvm/gems/ruby-2.0.0-p451/bin/ruby_executable_hooks:15:in `<main>'
Tasks: TOP => db:migrate
(See full trace by running task with --trace)
I think I've made the common edits to the pg_hba.conf:
# Database administrative login by Unix domain socket
local all postgres trust
# TYPE DATABASE USER ADDRESS METHOD
# "local" is for Unix domain socket connections only
local all all trust
# IPv4 local connections:
host all all 127.0.0.1/32 trust
# IPv6 local connections:
host all all ::1/128 trust
# Allow replication connections from localhost, by a user with the
# replication privilege.
#local replication postgres peer
#host replication postgres 127.0.0.1/32 md5
#host replication postgres ::1/128 md5
and database.yml:
development:
adapter: postgresql
encoding: unicode
database: stevenagy
host: localhost
pool: 5
timeout: 5000
username: localhost
password:
test:
adapter: postgresql
encoding: unicode
database: stevenagy
host: localhost
pool: 5
timeout: 5000
username: localhost
password:
production:
development:
adapter: postgresql
encoding: unicode
database: stevenagy
host: localhost
pool: 5
timeout: 5000
username: localhost
password:
Any advice? Thanks!

There's no password directive in your database.yml entries, but your pg_hba.conf requires md5 password authentication. Specify a password for your connections, use an authentication method in pg_hba.conf that doesn't require a password, or put the passwords in the ~/.pgpass file if you don't want them in revision control.

Related

Rails and postgresql - no password supplied

I cannot figure out why I am constantly getting this error when running rake db:migrate:status after switching over to Postgresql and Rails 5.2.1
[root:7e2d33988106:~/myapp]# rake db:migrate:status 12:04AM/06.27
rake aborted!
PG::ConnectionBad: fe_sendauth: no password supplied
/usr/local/rvm/gems/ruby-2.5.1/gems/pg-1.1.4/lib/pg.rb:56:in `initialize'
/usr/local/rvm/gems/ruby-2.5.1/gems/pg-1.1.4/lib/pg.rb:56:in `new'
/usr/local/rvm/gems/ruby-2.5.1/gems/pg-1.1.4/lib/pg.rb:56:in `connect'
/usr/local/rvm/gems/ruby-2.5.1/gems/activerecord-5.2.3/lib/active_record/connection_adapters/postgresql_adapter.rb:692:in `connect'
/usr/local/rvm/gems/ruby-2.5.1/gems/activerecord-5.2.3/lib/active_record/connection_adapters/postgresql_adapter.rb:223:in `initialize'
/usr/local/rvm/gems/ruby-2.5.1/gems/activerecord-5.2.3/lib/active_record/connection_adapters/postgresql_adapter.rb:48:in `new'
/usr/local/rvm/gems/ruby-2.5.1/gems/activerecord-5.2.3/lib/active_record/connection_adapters/postgresql_adapter.rb:48:in `postgresql_connection'
/usr/local/rvm/gems/ruby-2.5.1/gems/activerecord-5.2.3/lib/active_record/connection_adapters/abstract/connection_pool.rb:811:in `new_connection'
/usr/local/rvm/gems/ruby-2.5.1/gems/activerecord-5.2.3/lib/active_record/connection_adapters/abstract/connection_pool.rb:855:in `checkout_new_connection'
/usr/local/rvm/gems/ruby-2.5.1/gems/activerecord-5.2.3/lib/active_record/connection_adapters/abstract/connection_pool.rb:834:in `try_to_checkout_new_connection'
/usr/local/rvm/gems/ruby-2.5.1/gems/activerecord-5.2.3/lib/active_record/connection_adapters/abstract/connection_pool.rb:795:in `acquire_connection'
/usr/local/rvm/gems/ruby-2.5.1/gems/activerecord-5.2.3/lib/active_record/connection_adapters/abstract/connection_pool.rb:523:in `checkout'
/usr/local/rvm/gems/ruby-2.5.1/gems/activerecord-5.2.3/lib/active_record/connection_adapters/abstract/connection_pool.rb:382:in `connection'
/usr/local/rvm/gems/ruby-2.5.1/gems/activerecord-5.2.3/lib/active_record/connection_adapters/abstract/connection_pool.rb:1014:in `retrieve_connection'
/usr/local/rvm/gems/ruby-2.5.1/gems/activerecord-5.2.3/lib/active_record/connection_handling.rb:118:in `retrieve_connection'
/usr/local/rvm/gems/ruby-2.5.1/gems/activerecord-5.2.3/lib/active_record/connection_handling.rb:90:in `connection'
/usr/local/rvm/gems/ruby-2.5.1/gems/activerecord-5.2.3/lib/active_record/schema_migration.rb:22:in `table_exists?'
/usr/local/rvm/gems/ruby-2.5.1/gems/activerecord-5.2.3/lib/active_record/railties/databases.rake:124:in `block (3 levels) in <top (required)>'
/usr/local/rvm/gems/ruby-2.5.1/gems/rake-12.3.2/exe/rake:27:in `<top (required)>'
/usr/local/rvm/gems/ruby-2.5.1/bin/ruby_executable_hooks:24:in `eval'
/usr/local/rvm/gems/ruby-2.5.1/bin/ruby_executable_hooks:24:in `<main>'
Tasks: TOP => db:migrate:status
(See full trace by running task with --trace)
What I've done so far
I have edited the pg_hba.conf file to show the following:
local all postgres md5
local all all md5
host all all 127.0.0.1/32 md5
host all all ::1/128 md5
local replication all peer
host replication all 127.0.0.1/32 md5
host replication all ::1/128 md5
and restarted the service. No luck. Same error. The first error I got prior to this was invalid password for postgresql, so i had to change one of the "peer" options to "md5"
If I look into my config/database.yml file, this is what it looks like:
# SQLite version 3.x
# gem install sqlite3
#
# Ensure the SQLite 3 gem is defined in your Gemfile
# gem 'sqlite3'
#
default: &default
adapter: postgresql
pool: 5
timeout: 5000
encoding: unicode
username: postgres
database: <%= Rails.application.credentials.dig(:database, Rails.env.to_sym, :database_name) %>
# username: <%= Rails.application.credentials.dig(:database, Rails.env.to_sym, :database_user_name) %>
# password: <%= Rails.application.credentials.dig(:database, Rails.env.to_sym, :database_password) %>
development:
<<: *default
test:
<<: *default
staging:
<<: *default
production:
<<: *default
and when I edit the credentials with rake (using EDITOR=vim rails credentials:edit), this is what this file looks like:
# aws:
# access_key_id: 123
# secret_access_key: 345
# Used as the base secret for all MessageVerifiers in Rails, including the one protecting cookies.
secret_key_base: <my long key redacted for stackoverflow>
database:
development:
database_name: development
database_user_name: postgres
database_password: <redacted for stackoverflow>
test:
database_name: test
database_user_name: postgres
database_password: <redacted for stackoverflow>
production:
database_name: production
database_user_name: postgres
database_password: <redacted for stackoverflow>
I feel like I've been going hours deep down the rabbit hole and cannot figure out how to get this Rails application working with Postgresql.
I have taken a look at this post here: PG::ConnectionBad fe_sendauth: no password supplied and have tried its suggestion with no luck, and even here How to resolve the error 'fe_sendauth: no password supplied' in Rails using PostgreSQL? with no luck either. I don't have host: '' or host: 'localhost' anywhere in the config/database.yml file (I've tried adding it and still didn't work), so I'm not quite sure this has anything to do with anything here for me.
Any other suggestions?
Add your username and password in production: in database.yml

Rake db:migrate rails with error undefined method `session_store_host`

I have several databases across various geolocations. Each has its own representation in my database.yml file.
When running RAILS_ENV=europe rake db:migrate I am getting the following error
undefined method `session_store_host' for #<Rails::Application::Configuration:0x000000038fdda8>
Stack:
/usr/local/rvm/gems/ruby-1.9.3-p327/gems/railties-3.2.17/lib/rails/railtie/configuration.rb:85:in `method_missing'
/var/www/vhosts/adm.dyqa.io/html/releases/20190324134144/config/initializers/session_store.rb:9:in `<top (required)>'
/usr/local/rvm/gems/ruby-1.9.3-p327/gems/activesupport-3.2.17/lib/active_support/dependencies.rb:245:in `load'
/usr/local/rvm/gems/ruby-1.9.3-p327/gems/activesupport-3.2.17/lib/active_support/dependencies.rb:245:in `block in load'
/usr/local/rvm/gems/ruby-1.9.3-p327/gems/activesupport-3.2.17/lib/active_support/dependencies.rb:236:in `load_dependency'
/usr/local/rvm/gems/ruby-1.9.3-p327/gems/activesupport-3.2.17/lib/active_support/dependencies.rb:245:in `load'
My database file:
europe:
adapter: mysql2
encoding: utf8
reconnect: true
database: production
pool: 10
username: USERNAME
password: PASSWORD
host: database.mycompany.europe
port: 1234
danger:
adapter: mysql2
encoding: utf8
reconnect: true
database: production
pool: 10
username: USERNAME
password: PASSWORD
host: database.mycompany.usa
port: 1234
Turns out I was missing the config file europe.rb
After creating that, the migration ran successfully.

Undefined Method 'Match' for Nil Class with Oracle Enhanced Adapter Connection

I am using the activerecord-oracle_enhanced-adapter to connect to an Oracle 11g Database so that I may more easily reference the data living in Oracle in my Rails 4 Application. I have been following the instructions in the GitHub repo so far and it appears as if I am in fact able to connect to the database that I want to, but whenever I go to query any data in the Oracle Database I get the following error:
NoMethodError: undefined method `match' for nil:NilClass
from /Users/47900/.rvm/gems/ruby-2.0.0-p481/gems/activerecord-oracle_enhanced-adapter-1.6.3/lib/active_record/connection_adapters/oracle_enhanced/oci_connection.rb:322:in `new_connection'
from /Users/47900/.rvm/gems/ruby-2.0.0-p481/gems/activerecord-oracle_enhanced-adapter-1.6.3/lib/active_record/connection_adapters/oracle_enhanced/oci_connection.rb:389:in `initialize'
from /Users/47900/.rvm/gems/ruby-2.0.0-p481/gems/activerecord-oracle_enhanced-adapter-1.6.3/lib/active_record/connection_adapters/oracle_enhanced/oci_connection.rb:26:in `new'
from /Users/47900/.rvm/gems/ruby-2.0.0-p481/gems/activerecord-oracle_enhanced-adapter-1.6.3/lib/active_record/connection_adapters/oracle_enhanced/oci_connection.rb:26:in `initialize'
from /Users/47900/.rvm/gems/ruby-2.0.0-p481/gems/activerecord-oracle_enhanced-adapter-1.6.3/lib/active_record/connection_adapters/oracle_enhanced/connection.rb:9:in `new'
from /Users/47900/.rvm/gems/ruby-2.0.0-p481/gems/activerecord-oracle_enhanced-adapter-1.6.3/lib/active_record/connection_adapters/oracle_enhanced/connection.rb:9:in `create'
from /Users/47900/.rvm/gems/ruby-2.0.0-p481/gems/activerecord-oracle_enhanced-adapter-1.6.3/lib/active_record/connection_adapters/oracle_enhanced_adapter.rb:156:in `oracle_enhanced_connection'
from /Users/47900/.rvm/gems/ruby-2.0.0-p481/gems/activerecord-4.2.2/lib/active_record/connection_adapters/abstract/connection_pool.rb:438:in `new_connection'
from /Users/47900/.rvm/gems/ruby-2.0.0-p481/gems/activerecord-4.2.2/lib/active_record/connection_adapters/abstract/connection_pool.rb:448:in `checkout_new_connection'
from /Users/47900/.rvm/gems/ruby-2.0.0-p481/gems/activerecord-4.2.2/lib/active_record/connection_adapters/abstract/connection_pool.rb:422:in `acquire_connection'
from /Users/47900/.rvm/gems/ruby-2.0.0-p481/gems/activerecord-4.2.2/lib/active_record/connection_adapters/abstract/connection_pool.rb:349:in `block in checkout'
from /Users/47900/.rvm/rubies/ruby-2.0.0-p481/lib/ruby/2.0.0/monitor.rb:211:in `mon_synchronize'
from /Users/47900/.rvm/gems/ruby-2.0.0-p481/gems/activerecord-4.2.2/lib/active_record/connection_adapters/abstract/connection_pool.rb:348:in `checkout'
from /Users/47900/.rvm/gems/ruby-2.0.0-p481/gems/activerecord-4.2.2/lib/active_record/connection_adapters/abstract/connection_pool.rb:263:in `block in connection'
from /Users/47900/.rvm/rubies/ruby-2.0.0-p481/lib/ruby/2.0.0/monitor.rb:211:in `mon_synchronize'
from /Users/47900/.rvm/gems/ruby-2.0.0-p481/gems/activerecord-4.2.2/lib/active_record/connection_adapters/abstract/connection_pool.rb:262:in `connection'
I have tried googling the issue (and checking the docs / issues), but haven't found anything useful. I am also able to access this database through sqlplus, so my Oracle Instant Client is in fact working. Here is my database.yml and model that I have configured and am using to try to query the Oracle DB:
#database.yml (obviously data is faked)
development:
adapter: oracle_enhanced
host: //127.0.0.1:1527/DATABASE_NAME
username: ENV['USERNAME']
password: ENV['PASSWORD']
#oracle.rb
class Oracle < ActiveRecord::Base
self.table_name = "SCHEMA.TABLE"
self.primary_key = "obj_id"
end
#The queries I have tried through Rails Console
>> Oracle
>> ActiveRecord::Base.connection.execute("SELECT * FROM TABLE WHERE obj_id > 1000000;")
I'll keep updating with more information as I acquire it, thank you very much in advance!
In the database.yml config file you are missing "database". Use database.yml file described in https://github.com/rsim/oracle-enhanced#database-connection
Checkout this code https://github.com/rsim/oracle-enhanced/blob/master/lib/active_record/connection_adapters/oracle_enhanced/oci_connection.rb line: 302 and 322
database.yml
development:
adapter: oracle_enhanced
host: 127.0.0.1
port: 1527
database: <DATABASE_NAME>
username: ENV['USERNAME']
password: ENV['PASSWORD']

PostgreSQL user with Ruby on Rails

I am trying to deploy my app on heroku . For that I changed from sqlite3 to pg because heroku doesn't support sqlite3. I changed things in database.yml:
# SQLite version 3.x
# gem install sqlite3
#
# Ensure the SQLite 3 gem is defined in your Gemfile
# gem 'sqlite3'
#
default: &default
adapter: postgresql
pool: 5
timeout: 5000
development:
<<: *default
database: db/development.pg
# Warning: The database defined as "test" will be erased and
# re-generated from your development database when you run "rake".
# Do not set this db to the same as development or production.
test:
<<: *default
database: db/test.pg
production:
<<: *default
database: db/my_database_production.pg
I also did add the gem and install it (gem install pg) . When I try to run bundler exec rake db:create it gives me the following error:
rake aborted!
ActiveRecord::NoDatabaseError: FATAL: role "flo" does not exist
Run `$ bin/rake db:create db:migrate` to create your database
/home/flo/Ruby/sample_app/vendor/bundle/ruby/1.9.1/gems/activerecord-4.1.6/lib/active_record/connection_adapters/postgresql_adapter.rb:898:in `rescue in connect'
/home/flo/Ruby/sample_app/vendor/bundle/ruby/1.9.1/gems/activerecord-4.1.6/lib/active_record/connection_adapters/postgresql_adapter.rb:888:in `connect'
/home/flo/Ruby/sample_app/vendor/bundle/ruby/1.9.1/gems/activerecord-4.1.6/lib/active_record/connection_adapters/postgresql_adapter.rb:568:in `initialize'
/home/flo/Ruby/sample_app/vendor/bundle/ruby/1.9.1/gems/activerecord-4.1.6/lib/active_record/connection_adapters/postgresql_adapter.rb:41:in `new'
/home/flo/Ruby/sample_app/vendor/bundle/ruby/1.9.1/gems/activerecord-4.1.6/lib/active_record/connection_adapters/postgresql_adapter.rb:41:in `postgresql_connection'
/home/flo/Ruby/sample_app/vendor/bundle/ruby/1.9.1/gems/activerecord-4.1.6/lib/active_record/connection_adapters/abstract/connection_pool.rb:435:in `new_connection'
/home/flo/Ruby/sample_app/vendor/bundle/ruby/1.9.1/gems/activerecord-4.1.6/lib/active_record/connection_adapters/abstract/connection_pool.rb:445:in `checkout_new_connection'
/home/flo/Ruby/sample_app/vendor/bundle/ruby/1.9.1/gems/activerecord-4.1.6/lib/active_record/connection_adapters/abstract/connection_pool.rb:416:in `acquire_connection'
/home/flo/Ruby/sample_app/vendor/bundle/ruby/1.9.1/gems/activerecord-4.1.6/lib/active_record/connection_adapters/abstract/connection_pool.rb:351:in `block in checkout'
/home/flo/Ruby/sample_app/vendor/bundle/ruby/1.9.1/gems/activerecord-4.1.6/lib/active_record/connection_adapters/abstract/connection_pool.rb:350:in `checkout'
/home/flo/Ruby/sample_app/vendor/bundle/ruby/1.9.1/gems/activerecord-4.1.6/lib/active_record/connection_adapters/abstract/connection_pool.rb:265:in `block in connection'
/home/flo/Ruby/sample_app/vendor/bundle/ruby/1.9.1/gems/activerecord-4.1.6/lib/active_record/connection_adapters/abstract/connection_pool.rb:264:in `connection'
/home/flo/Ruby/sample_app/vendor/bundle/ruby/1.9.1/gems/activerecord-4.1.6/lib/active_record/connection_adapters/abstract/connection_pool.rb:541:in `retrieve_connection'
/home/flo/Ruby/sample_app/vendor/bundle/ruby/1.9.1/gems/activerecord-4.1.6/lib/active_record/connection_handling.rb:113:in `retrieve_connection'
/home/flo/Ruby/sample_app/vendor/bundle/ruby/1.9.1/gems/activerecord-4.1.6/lib/active_record/connection_handling.rb:87:in `connection'
/home/flo/Ruby/sample_app/vendor/bundle/ruby/1.9.1/gems/activerecord-4.1.6/lib/active_record/migration.rb:909:in `initialize'
/home/flo/Ruby/sample_app/vendor/bundle/ruby/1.9.1/gems/activerecord-4.1.6/lib/active_record/migration.rb:807:in `new'
/home/flo/Ruby/sample_app/vendor/bundle/ruby/1.9.1/gems/activerecord-4.1.6/lib/active_record/migration.rb:807:in `up'
/home/flo/Ruby/sample_app/vendor/bundle/ruby/1.9.1/gems/activerecord-4.1.6/lib/active_record/migration.rb:785:in `migrate'
/home/flo/Ruby/sample_app/vendor/bundle/ruby/1.9.1/gems/activerecord-4.1.6/lib/active_record/railties/databases.rake:34:in `block (2 levels) in <top (required)>'
Tasks: TOP => db:migrate
(See full trace by running task with --trace)
I am trying to write su - postgres in my terminal but from that command I get :
No passwd entry for user 'postgres'
What should I do ?
You need to add the user 'flo' to your local postgres instance (I usually just add them as a super user so I don't have permissions issues). Run this in your terminal:
createuser -P -s -e flo
You will be prompted to set a password as well. Lets use 'flo' for now. You will then need to add this to your databases.yml file:
development:
<<: *default
database: db/development.pg
username: flo
password: flo
Do that and then try running rake db:create again. Check this out for additional help.

Resetting Test Database via rake test is complaining: "database configuration does not specify adapter"

I am attempting to use this bit of useful code from this question:
namespace :db do
namespace :test do
task :reset do
ActiveRecord::Base.establish_connection('test')
Rake::Task['db:drop'].invoke
Rake::Task['db:create'].invoke
Rake::Task['db:migrate'].invoke
ActiveRecord::Base.establish_connection(ENV['RAILS_ENV']) #Make sure you don't have side-effects!
end
end
end
Unfortunately I am getting this error:
** Invoke db:test:reset (first_time)
** Execute db:test:reset
rake aborted!
database configuration does not specify adapter
/home/nick/.rvm/gems/ruby-1.9.3-p194/gems/activerecord- 3.2.5/lib/active_record/connection_adapters/abstract/connection_specification.rb:45:in `resolve_hash_connection'
/home/nick/.rvm/gems/ruby-1.9.3-p194/gems/activerecord-3.2.5/lib/active_record/connection_adapters/abstract/connection_specification.rb:39:in `resolve_string_connection'
/home/nick/.rvm/gems/ruby-1.9.3-p194/gems/activerecord-3.2.5/lib/active_record/connection_adapters/abstract/connection_specification.rb:25:in `spec'
/home/nick/.rvm/gems/ruby-1.9.3-p194/gems/activerecord-3.2.5/lib/active_record/connection_adapters/abstract/connection_specification.rb:127:in `establish_connection'
/home/nick/Projects/yumbin/lib/tasks/test_environment.rake:4:in `block (3 levels) in <top (required)>'
/home/nick/.rvm/gems/ruby-1.9.3-p194#global/gems/rake-0.9.2.2/lib/rake/task.rb:205:in `call'
/home/nick/.rvm/gems/ruby-1.9.3-p194#global/gems/rake-0.9.2.2/lib/rake/task.rb:205:in `block in execute'
/home/nick/.rvm/gems/ruby-1.9.3-p194#global/gems/rake-0.9.2.2/lib/rake/task.rb:200:in `each'
/home/nick/.rvm/gems/ruby-1.9.3-p194#global/gems/rake-0.9.2.2/lib/rake/task.rb:200:in `execute'
/home/nick/.rvm/gems/ruby-1.9.3-p194#global/gems/rake-0.9.2.2/lib/rake/task.rb:158:in `block in invoke_with_call_chain'
/home/nick/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/monitor.rb:211:in `mon_synchronize'
/home/nick/.rvm/gems/ruby-1.9.3-p194#global/gems/rake-0.9.2.2/lib/rake/task.rb:151:in `invoke_with_call_chain'
/home/nick/.rvm/gems/ruby-1.9.3-p194#global/gems/rake-0.9.2.2/lib/rake/task.rb:144:in `invoke'
/home/nick/.rvm/gems/ruby-1.9.3-p194#global/gems/rake-0.9.2.2/lib/rake/application.rb:116:in `invoke_task'
/home/nick/.rvm/gems/ruby-1.9.3-p194#global/gems/rake-0.9.2.2/lib/rake/application.rb:94:in `block (2 levels) in top_level'
/home/nick/.rvm/gems/ruby-1.9.3-p194#global/gems/rake-0.9.2.2/lib/rake/application.rb:94:in `each'
/home/nick/.rvm/gems/ruby-1.9.3-p194#global/gems/rake-0.9.2.2/lib/rake/application.rb:94:in `block in top_level'
/home/nick/.rvm/gems/ruby-1.9.3-p194#global/gems/rake-0.9.2.2/lib/rake/application.rb:133:in `standard_exception_handling'
/home/nick/.rvm/gems/ruby-1.9.3-p194#global/gems/rake-0.9.2.2/lib/rake/application.rb:88:in `top_level'
/home/nick/.rvm/gems/ruby-1.9.3-p194#global/gems/rake-0.9.2.2/lib/rake/application.rb:66:in `block in run'
/home/nick/.rvm/gems/ruby-1.9.3-p194#global/gems/rake-0.9.2.2/lib/rake/application.rb:133:in `standard_exception_handling'
/home/nick/.rvm/gems/ruby-1.9.3-p194#global/gems/rake-0.9.2.2/lib/rake/application.rb:63:in `run'
/home/nick/.rvm/gems/ruby-1.9.3-p194#global/gems/rake-0.9.2.2/bin/rake:33:in `<top (required)>'
./bundler_stubs/rake:16:in `load'
./bundler_stubs/rake:16:in `<main>'
Tasks: TOP => db:test:reset
As you can see I am using Ruby 1.9.3 via RVM. I am using Rails 3.2.5, Rake version 0.9.2.2 and Postgresql 9.1, and the pg gem (0.13.2). Additionally, I have no database errors in my environments. Thhe app is deployed and running on Heroku, runs locally in development, and I can run my full test suite without issue. In a Rails console running the line:
ActiveRecord::Base.establish_connection('test')
succeeds. I checked the database.yml in vi for invisible characters but could not find any. Only '$' at the end of each line. I'm starting to think that the answer is incredibly simple and in front of my nose but I just can't see it.
UPDATE: Adding my database.yml file:
# SQLite version 3.x
# gem install sqlite3
#
# Ensure the SQLite 3 gem is defined in your Gemfile
# gem 'sqlite3'
development:
adapter: postgresql
encoding: unicode
database: myapp-dev
pool: 5
username: ******
password: *******
# Warning: The database defined as "test" will be erased and
# re-generated from your development database when you run "rake".
# Do not set this db to the same as development or production.
test:
adapter: postgresql
encoding: unicode
database: myapp-test
pool: 5
username: *****
password: ******
production:
adapter: postgresql
encoding: unicode
database: myapp
pool: 5
username: ******
password: *******
You need a test entry in your database.yml file, and I think you're probably lacking one. Make sure you have an entry that looks like this in database.yml:
test:
adapter: sqlite3
database: db/test.sqlite3
pool: 5
timeout: 5000
Using whatever adapter and database your development database is using.

Resources