'development' database is not configured - ruby-on-rails

I am getting this error while doing rake db:migrate of newly cloned app.
'development' database is not configured. Available: ["production"]
So after reading the error, I am doing RAILS_ENV=production rake db:migrate
But this isn't working either.
My database.yml has
production:
adapter: postgresql
encoding: unicode
database: test
pool: 5
username: admin
password: admin
port: 5433
Please suggest.

Add
development:
adapter: postgresql
encoding: unicode
database: test
pool: 5
username: admin
password: admin
port: 5433
host: localhost
to database.yml file.
Also, if you test your application, you'll need test environment as well.

Your database.yml file shows you have only production environment configured for DB operations. You need to add configuration for development environment as well.
Open your database.yml file and add a configuration for development environment.
Something like the following should suffice (contents in square brackets are to be replaced with your actual values):
development:
adapter:[your adapter]
encoding: [your encoding]
database: [your database for development]
pool: [your pool]
username: [your database server username]
password: [your database server password]
port: [the port you're connecting on]
Remember to indent your yaml code appropriately.

Related

Load database records to localhost

How can I make the database records that I have on my heroku app to be available also on my machine?
database.yml
development:
adapter: sqlite3
encoding: unicode
database: databasename
pool: 5
username: my_mac_username
password: #no password filled
test:
adapter: sqlite3
encoding: unicode
database: testdatabasename
pool: 5
username: my_mac_username
password: #no password filled
production:
adapter: postgresql
encoding: unicode
database: productiondatabasename
pool: 5
username: my_mac_username
password: #no password filled
I run
heroku pg:pull DATABASE_URL productiondatabasename --app my_heroku_app_name
and bunch of lines is being displayed in my terminal. But that's it. Nothing more happens. I still do not have the records available on localhost.
What am I missing here?
What I was doing wrong was the configuration of database.yml.
If using sqlite3, drop your db first, then change the development adapter to postgresql (make sure that you have installed it properly!). Then recreate the database.
After running
heroku pg:pull DATABASE_URL developmentdatabasename --app my_heroku_app_name
everything should be OK!

ENV variables are not set for test environment

I have a test database set like this in database.yml:
test:
adapter: postgresql
encoding: unicode
database: database_test
host: localhost
pool: 5
username: <%= ENV['PG_USERNAME']%>
password: <%= ENV['PG_PASSWORD']%>
I use spring gem for running tests (although this is not important as the issue occurs without using it as well)
The issue is that every time I run a bundle exec rspec spec/ I get an error no password supplied (PG::ConnectionBad):
/.bundle/ruby/2.3.0/gems/activerecord-4.2.0/lib/active_record/connection_adapters/postgresql_adapter.rb:651:in `initialize': fe_sendauth: no password supplied (PG::ConnectionBad)
And I need to change it manually to:
test:
adapter: postgresql
encoding: unicode
database: database_test
host: localhost
pool: 5
username: postgres
password: postgres
In order for it to work.
I have set variables in ~/.bashrc:
export PG_USERNAME="postgres"
export PG_PASSWORD="postgres"
The strange is that in development mode it all working fine when I use the same structure as in test:
development:
adapter: postgresql
encoding: unicode
database: database_dev
host: localhost
pool: 5
username: <%= ENV['PG_USERNAME']%>
password: <%= ENV['PG_PASSWORD']%>
What is the problem with my test environment and how to fix it in order for it to automatically use ENV['PG_USERNAME'] like in development mode?
I proposed a quickfix in the comments, but I'd suggest to use the excellent dotenv gem for configuration loading depending on your configuration. It would incidentally solve your current problem.

Working on a rails app locally with a remote Postgres connection?

Is there a way to configure the database.yml file to connect to Heroku's Postgres remotely?
I'm having trouble understanding how Heroku, Rails and PG gem work together.
It looks like during deployment, Heroku re-writes the database.yml file - is it possible to see the contents of this updated .yml file and use it locally?
Below are the steps to access Heroku db from local development:
Login to your heroku account.
Navigate to this URL https://postgres.heroku.com/databases/ OR you can get heroku db url by running this command in the terminal: heroku pg:credentials:url
Select your application database.
You will able to see your heroku pg credentials:
Host xxxxxxxxx.77777.amazonaws.com
Database 42feddfddeee
Username 44444444444
Port xxxx
Password 777sfsadferwefsdferwefsdf
collect above details and put in your databse.yml file development evn:
adapter: postgresql
host: < host > # HOST
port: < port > # Port
database: < database name > # Database Name
username: < user_name > # User Name
password: '< password >' # Password
Restart you application,
Best of luck..!!
I am not a postgres user but this should work.
You can alter your database.yml to include host and port
production:
adapter: postgresql
encoding: unicode
database: di_production
pool: 5
username: user
password:
host: heroku.host.name
port: <postgres listen port>
And of course, you should allow connection on the server side, both at the firewall level and database level.
A simple hack to see contents of #{Rails.root}/config/database.yml is to write code to load this yml into an object, then print it out on the UI
DB_CONFIG = YAML.load(File.read("#{Rails.root}/config/database.yml", __FILE__))
puts DB_CONFIG["production"].inspect # or what ever method you want to print it
I am a bit of a newbie and may have misunderstood your question - but. Developed a ROR application using postgress database. Then uploaded to Heroku. I ran DB/Migrate/schema.rb to set up the remote Postgresql database.
From memory heroku run rake db:init (but I could be wrong). Whenver I update the database in develpment to get update in Heroku I have to promote code and run heroku run rake db:migrate
From my config/dtabase.yml
development:
adapter: postgresql
encoding: unicode
database: di_development
pool: 5
username: davidlee
password:
test:
adapter: postgresql
encoding: unicode
database: di_test
pool: 5
username: davidlee
password:
production:
adapter: postgresql
encoding: unicode
database: di_production
pool: 5
username: user
password:
and it works. I can't remember doing anything else.
Pierre

Cannot seem to use development database

I updated my database.yml file to look like so:
test:
adapter: postgresql
encoding: unicode
database: startpoint_test
hostname: localhost
pool: 5
username: postgres
password: password
development:
adapter: postgresql
encoding: unicode
database: startpoint_dev
pool: 5
username: postgres
password: password
And now it seems when I run my application, and sign up a new user the development database does not get a new user inserted into it ...
The tests all pass for signing up a new user
Have you tried using
rake db:create:all
and then
rake db:test:prepare

Issue with Postgresql `initialize` ... Socket .s.PGSQL.5432

There have been a few post on this issue, unfortunately none of the solutions have worked for me.
My suspicion is that my postgresql is either not running or not configured correctly.
Here is where I am at, I have a development project I have joined, they are using postgresql. Here are the step I have take to get here:
Cloned Repo
Changed name of config/ database.yml.sample -> database.yml
Changed name of config/ s3.yml.sample -> s3.yml
Ran bundle install
Ran Rake db:migrate
resulting in this error:
rake aborted!
could not connect to server: No such file or directory
Is the server running locally and accepting
connections on Unix domain socket "/var/pgsql_socket/.s.PGSQL.5432"?
Here is what my files currently look like:
Database.yml
development:
adapter: postgresql
encoding: unicode
database: rentsnapper_development
pool: 5
username: user
password:
test: &test
adapter: postgresql
encoding: unicode
database: rentsnapper_test
pool: 5
username: user
password:
cucumber:
<<: *test
And My s3.yml
defaults: &defaults
access_key_id:
secret_access_key:
development:
<<: *defaults
photos_bucket: rentsnapper-photos-development
Solutions Tried:
https://stackoverflow.com/a/14887090/2066855
No File listed
https://stackoverflow.com/a/14225289/2066855
No Change, when I run rake db:migrate I get the same error
https://stackoverflow.com/a/15788389/2066855
Nothing happened
Also as a side question that may or may not be relevant linux is telling me that "ruby-1.9.3-p385 is not installed", I'm running ruby-1.9.3-p362, I suspect this is unrelated. Is this something I need to update or can I get by with my current version.
Thank you in advanced...
SOLVED: I had to fix my database.yml file. Added "host: localhost" took out user & password lines.
development:
adapter: postgresql
encoding: unicode
database: rentsnapper_development
pool: 5
host: localhost
test: &test
adapter: postgresql
encoding: unicode
database: rentsnapper_test
pool: 5
host: localhost
cucumber:
<<: *test

Resources