Skip to content

Instantly share code, notes, and snippets.

@nielsrolf
Last active March 8, 2019 20:17
Show Gist options
  • Save nielsrolf/761bfae35f38761a002f23a100dbba6a to your computer and use it in GitHub Desktop.
Save nielsrolf/761bfae35f38761a002f23a100dbba6a to your computer and use it in GitHub Desktop.
Install postgres and postGIS on os x and set it up for a (django) app
# DB Setup
# Install postgres
brew install postgres
# Make it start automatically
pg_ctl -D /usr/local/var/postgres start && brew services start postgresql
# start PSQL Shell as admin to create the db user
psql postgres
CREATE ROLE app_db_user WITH LOGIN PASSWORD 'app_db_password';
ALTER ROLE app_db_user CREATEDB;
ALTER ROLE app_db_user SUPERUSER; // Otherwise the test database cannot be created
\q
# start PSQL Shell as db user and create the database
psql postgres -U app_db_user
CREATE DATABASE app_db;
\q
# Install and add PostGIS if necessary
brew install postgis
# connect to the db as admin to add postGIS as extension to the db
psql app_db
CREATE EXTENSION postgis;
# Install the posgres extension and set all settings in your django settings.py
pip install django psycopg2
# open settings.py in your editor and replace the database part by:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'NAME': 'app_db',
'USER': 'app_db_user',
'PASSWORD': 'app_db_password',
'HOST': 'localhost',
'PORT': '5432',
}
}
# Later when you deploy the project, you will read these from environment variables
# Apply your migrations if you are using django.
# Note: In the main settings.py, db user and password have to be set
# and the venv/condaenv/... must be active
python manage.py migrate
python manage.py createsuperuser
# Seed your db with a script that you start from the django shell
python manage.py shell
from your.seed.module import seed_db
seed_db()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment