Search code examples
ruby-on-railsruby-on-rails-4database-migrationrails-postgresqlpg

Postgres <=> Rails . How to auto-create a user from database.yml


I am using PG for my rails4 application.

Every time I git clone to a new machine or clear my project, I have to keep creating the user for postgres before I get the app working again.

This is a problem when I share my code with designers etc and they have to unnecessarily get into details of setting up the db users and making them super users etc.

Is there a way I can automate this , given that I am using the PG gem and the Rails already know about the users I need from my database.yml


Solution

  • You shouldn't be doing this. database.yml doesn't belong in version control, see How to manage Rails database.yml.

    You should be storing a template file (I use config/database.yml.example) and each person who clones your app should copy the template file to config/database.yml, and add to it their existing database user and password, for connecting to their local development instance of Postgres.

    Your designers should also have a single development user on their local machines, and it's up to them to place their credentials into config/database.yml.

    There is no way to have Rails create database users for you, because it's supposed to be your job to tell Rails existing database user it should use. All your apps, in your development environment, should be using the same user.