Home

/

Library

/

tech/db-setup.md

Database Setup (Local + Server)

Database Setup (Local + Server)

Prereqs

  • Postgres is installed and running.
  • CORNICE_DB_PWD is set (see .env.dev).

Create Role + Database

Set the password from .env.dev:

export CORNICE_DB_PWD='dk38K7d72___FJSK93kd*&&*'

Create role and database:

psql -U postgres -d postgres -c "create role cornice_user with login password '${CORNICE_DB_PWD}';"
psql -U postgres -d postgres -c "create database cornice_dev owner cornice_user;"

Apply Migrations (Order Matters)

psql -U cornice_user -d cornice_dev -f migrations/001_create_global_markets.sql
psql -U cornice_user -d cornice_dev -f migrations/002_create_markets.sql
psql -U cornice_user -d cornice_dev -f migrations/003_create_market_links.sql
psql -U cornice_user -d cornice_dev -f migrations/004_create_snapshots.sql

Connection String

postgresql://cornice_user:${CORNICE_DB_PWD}@localhost:5432/cornice_dev

Notes

  • On Ubuntu, you may need sudo -u postgres psql ... for role creation.
  • If role/database already exist, drop them first or skip creation.