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!
Related
I'm learning ruby. I've created some application and played with it.
i wanted to change the database to postgres. I modified gemfile with
gem 'pg'
[pg already installed in usr/bin/pg]
then update database.yml with
postgresql where sqllite is used.
pg connection bad:
FATAL: role "user" does not exist
i've created some postgres user already. what should i have to change to work with postgres?
development:
adapter: postgresql
database: db/development.postgresql
pool: 5
timeout: 5000
user:
adapter: postgresql
database: db/test.postgresql
pool: 5
timeout: 5000
production:
adapter: postgresql
database: db/production.postgresql
pool: 5
timeout: 5000
If you don't specify a username to connect to PostgreSQL as, libpq will connect using the login username of the current running user.
libpq is what the Pg gem used by Rails uses to connect to PostgreSQL.
So, in your database.yml, specify the PostgreSQL user to connect to the database as with a user: entry. Make sure this corresponds to a user that exists in PostgreSQL, and that pg_hba.conf permits this user to connect.
To learn more, see the client authentication chapter of the PostgreSQL docs.
I know its a two year old question, but I just ran into the same problem, and i fixed it by changing the syntax of config.yml, then I rake db:migrate
default: &default
adapter: postgresql
encoding: unicode
pool: 5
development:
<<: *default
database: yourappnamehere_development
test:
<<: *default
database: yourappnamehere_testdevelopment:
production:
<<: *default
database: YOURAPPNAME_production
username: YOURUSERNAME
password: <%= ENV['YOURAPPNAME_DATABASE_PASSWORD'] %>
Just followed the "Migrating to PostgreSQL" Railscast, migrating my local sqlite3 database to postgres:
here is my database.yml file:
development:
adapter: postgresql
encoding: unicode
database: app_development
pool: 5
host: localhost
username: martinbraun
password:
test:
adapter: postgresql
encoding: unicode
database: app_test
pool: 5
username: mbraun
password:
production:
adapter: postgresql
encoding: utf8
database: app_production
pool: 5
username: mbraun
password:
My postgres server is running on postgressapp on port 5432. It tells me that it's running and I get connection to my database app_development.
However, "which psql" tells me:
/usr/bin/psql
and when I start my app, all the records are not loading, I simply see my application layout and all html stuff which is not related to any records. No error is showing up.
I have verified that my database contains data via rails console, so the migration from sqlite3 to postgres was def successful. I am just wondering why my records are not showing and what I do wrong here?
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
I am in the process of migrating my SQL to Postgresql because I want to develop in the same environment as my production.
I installed Postgres and was able to set my database yml file such that rake db:create:all worked with no problems.
However before I pushed, I realized that the username and password of the postgresql database is only available on my computer. I.e. I created the login role on my computer. When my friend who is also developing on the application, pulls the code, he won't have the username and password created by me on my computer.
Is he supposed to also create the same login role? Or is there a way to leave username / password blank so that everyone who develops can access the application? More importantly, what is the best practice for a situation like this?
I am developing on windows and he is on mac.
My database.yml: username and password left out.
development:
adapter: postgresql
encoding: unicode
database: volatility_development
pool: 5
timeout: 5000
host: localhost
test:
adapter: postgresql
encoding: unicode
database: volatility_test
pool: 5
timeout: 5000
host: localhost
production:
adapter: postgresql
encoding: unicode
database: volatility_production
pool: 5
timeout: 5000
one possibility would be to use a combination of erb and environment variables, for example:
development:
username: <%= ENV['USERNAME'] %>
password: <%= ENV['PASSWORD'] %>
adapter: postgresql
encoding: unicode
database: volatility_development
pool: 5
timeout: 5000
host: localhost
then you could do either of the following:
start your server like so: USERNAME=bob PASSWORD=secret rails s
add the following to your .bashrc
export USERNAME=bob
export PASSWORD=secret
I'm created project. Works in development mode! Excellent!
DEVELOPMENT:
Typing : ruby lib/scripts/test_sync.rb
And my script works!
PRODUCTION:
Typing : ruby lib/scripts/test_sync.rb
Get Access denied for user 'root'#'localhost' (using password: YES)
Dont know, I did everything. grant previligies, changed password and so on... Coul someone help me, please?
UPD*
# SQLite version 3.x
# gem install sqlite3-ruby (not necessary on OS X Leopard)
development:
adapter: mysql
host: localhost
database: survey_development
username: root
password:
encoding: utf8
# 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: mysql
host: localhost
database: survey_development
username: root
password:
encoding: utf8
production:
adapter: mysql
host: survey
database: survey_production
username: survey
password:
encoding: utf8
mossad:
adapter: mysql
host: baza
database: baza_production
username: baza_survey
password:
encoding: utf8
Try adding RAILS_ENV=production
Your login/password pair is incorrect for MySql database in database.yml.
EDIT
You should remove your password row if it does not exist:
production:
adapter: mysql
host: survey
database: survey_production
username: survey
encoding: utf8