3

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

1 Answer 1

2

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:

  1. start your server like so: USERNAME=bob PASSWORD=secret rails s
  2. add the following to your .bashrc

    export USERNAME=bob
    export PASSWORD=secret
    
Sign up to request clarification or add additional context in comments.

1 Comment

You can also use dotenv and store your environment variables in a .env file in your project directory.

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.