1

I built a rails app (with sqllite) and I want to push it to heroku. I know I have to use postgres so I have to add production use gem 'pg' in the gemfile. But I cant figure out how to change database.yml.

How should my database.yml look? How it currently looks like:

development:
  adapter: sqlite3
  database: db/development.sqlite3
  pool: 5
  timeout: 5000

test:
  adapter: sqlite3
  database: db/test.sqlite3
  pool: 5
  timeout: 5000

production:
  adapter: sqlite3
  database: db/production.sqlite3
  pool: 5
  timeout: 5000

Should I just replace development with this?

development:
  adapter: postgresql
  encoding: unicode
  database: poets_app_development
  pool: 5
  username: poets_app
  password:

Username and password!? I never set that up for sqlite so where does it come from ?

2 Answers 2

1

User and Password have nothing to do with sqlite. Those are the credentials of your Postgres server. Take a look to this article to configure Postgres in Ubuntu (Section: Setup PostgreSQL Users and Password).

You can also add the host to your database.yml:

host: <hostname or ip address. eg.: localhost>
Sign up to request clarification or add additional context in comments.

Comments

1

the database.yml file is an abstraction around common database configuration for your rails app.

The username and password could be placed in the file but it is not recommended. You might have set up postgres using a tool like homebrew. This set up is DRY and uses environment variables to protect your secrets. Best of luck!

Consider using the following configuration:

defaults: &defaults
  adapter: postgresql
  encoding: unicode
  pool: 5
  username: <%= ENV['YOUR_DB_USERNAME'] %> (username if PostgreSQL via Homebrew)
  password: <%= ENV['YOUR_DB_PWD'] %>

development:
 <<: *defaults
 database: postgres_development

test: &test
  <<: *defaults
  database: postgres_test

production:
  <<: *defaults
  database: postgres_production

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.