Skip to content

Setting up Postgres

E. Lynette Rayle edited this page Dec 18, 2019 · 8 revisions

back to Introduction


Installing Postgres

Installation of postgres is outside the scope of this tutorial. For mac, you might want to check out Install Postgres with Homebrew.

TODO: Perhaps someone can add a link for windows and other platforms.

Create the database and user

Start postgres command line with...

psql postgres

NOTE: To quit, type \q in the command line.

create role _USER_NAME_ with login encrypted password '_PASSWORD_' createdb;
create database valkyrie_pg_demo_development with owner _USER_NAME_ encoding 'utf8';
alter user _USER_NAME_ with SUPERUSER;

NOTE: Substitute a user name and password for _USER_NAME_ and _PASSWORD_, respectively.

Setup .env file (optional)

To avoid having user name and password in Github, it is recommended that you use the env library gem.

Edit .gitignore and confirm/add the following. Note, it is generally commented out by default.

# Used by dotenv library to load environment variables.
.env

Edit Gemfile and add...

gem 'dotenv-deployment'
gem 'dotenv-rails'

Run bundle install...

bundle install

Create/Edit .env file at the root of the app and add the following making the same substitutions for _USER_NAME_ and _PASSWORD_ as made above.

DATABASE_USERNAME=_USER_NAME_
DATABASE_PASSWORD=_PASSWORD_

Configure database connection information

Edit config/database.yml, uncomment and set the following under development to use the env variables...

database: valkyrie_pg_demo_development
username: <%= ENV['DATABASE_USERNAME'] %>
password: <%= ENV['DATABASE_PASSWORD'] %>
host: localhost
port: 5432

NOTE: There are various ways to setup a database to work with Rails. You do not have to use the settings presented here, but they are sufficient for the tutorial.

Install and run Valkyrie migrations

At the root of the valkyrie_pd_demo app, run the following...

bin/rails valkyrie_engine:install:migrations
bin/rails db:migrate

Previous | Next