Skip to content

Instantly share code, notes, and snippets.

@eliotsykes
Last active August 29, 2015 14:07
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save eliotsykes/3e74172c43c2e8787dd9 to your computer and use it in GitHub Desktop.
Save eliotsykes/3e74172c43c2e8787dd9 to your computer and use it in GitHub Desktop.
How to setup rails-dev-box & PostgreSQL

SSH to the vagrant OS command line.

Terminal $> vagrant ssh

Login to postgres database as vagrant user with the psql client:

vagrant@rails-dev-box: psql -U vagrant postgres

Decide on a username and password you want to use for your database.

Now we'll create this user with psql (in this example we'll be using "coderelf" as our username). Replace coderelf and ‘password’ with your own choices then run this statement:

postgres=# CREATE USER coderelf WITH CREATEDB PASSWORD 'password';

Give the new user permissions on all databases. Replace coderelf with your chosen username:

postgres=# GRANT ALL PRIVILEGES ON ALL TABLES IN SCHEMA public TO coderelf;

Exit psql by typing:

;\q

Update database.yml with your newly created username and password:

development:
  …
  username: coderelf
  password: password


test:
  …
  username: coderelf
  password: password 

Finally create the new databases by running:

rake db:create

If this was successful, there won’t be any output. Double-check it was successful by running rake db:create again (yes, again). You should see 2 lines printed out similar to:

database_name_development already exists
database_name_test already exists

Optional, only do this if you see an error like:

PG InvalidParameterValue ERROR new encoding UTF8 is incompatible with the encoding of the template database SQL_ASCII
HINT Use the same encoding as in the template database or use template0 as template

then specify the template option in database.yml for both development and test databases as follows:

development:
  …
  template: template0

test:
  …
  template: template0
@eliotsykes
Copy link
Author

If anyone has a way to do this using puppet with rails-dev-box, please share.

@eliotsykes
Copy link
Author

For an environment setup with this + rails-dev-box + middleman + rails see https://github.com/dannyvassallo/rails-middleman-vagrant

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment