How to setup a Postgres database

macOS

Use Postgres.app

TODO documentation from a macOS user.

Linux

(Based on "How to set up Postgres database for local Rails project?")

  1. Install postgresql and admin tools through the package manager
sudo apt-get install postgresql libpq-dev pgadmin3
  1. Login to postgresql prompt as the postgres user
sudo su postgres -c psql
  1. Create a postgresql user for your project
create user username with password 'password';
  1. Setup your postgres user with the same name and password as your normal user and make them a postgres superuser
alter user username superuser;
  1. Create the development and test databases
create database projectname_development;
create database projectname_test;
  1. Give permissions to the user on the databases
grant all privileges on database projectname_development to username;
grant all privileges on database projectname_test to username;

To end the postgresql session type \q

Update password for the user

alter user username with password ‘new password’;

Running seeds and migrations

With our example app, we can run our migrations and seeds.

Migrations

Run latest migrations:

npm run migrate:latest

Rollback migrations:

npm run migrate:rollback

Seeds

Seed database:

npm run seed

results matching ""

    No results matching ""