#!/bin/bash
##########################################
# WARNING:  DEMO script.  DROPS and RECREATES pgosm database 
##########################################

docker stop pgosm || true
docker rm pgosm || true


docker run --name pgosm -d \
    -v ~/pgosm-data:/app/output \
    -e POSTGRES_PASSWORD=notyoursecretpassword \
    -p 5433:5432 -d rustprooflabs/pgosm-flex


docker exec -it \
    -e POSTGRES_PASSWORD=notyoursecretpassword \
    -e POSTGRES_USER=postgres \
    -e PGOSM_DATA_SCHEMA_ONLY=true \
    -e PGOSM_DATA_SCHEMA_NAME=osm_dc \
    pgosm bash docker/run_pgosm_flex.sh \
    north-america/us \
    district-of-columbia \
    2000 \
    run-all


docker exec -it \
    -e POSTGRES_PASSWORD=notyoursecretpassword \
    -e POSTGRES_USER=postgres \
    -e PGOSM_DATA_SCHEMA_ONLY=true \
    -e PGOSM_DATA_SCHEMA_NAME=osm_co \
    pgosm bash docker/run_pgosm_flex.sh \
    north-america/us \
    colorado \
    2000 \
    run-all


docker exec -it \
    -e POSTGRES_PASSWORD=notyoursecretpassword \
    -e POSTGRES_USER=postgres \
    -e PGOSM_DATA_SCHEMA_ONLY=true \
    -e PGOSM_DATA_SCHEMA_NAME=osm_co2 \
    pgosm bash docker/run_pgosm_flex.sh \
    north-america/us \
    colorado \
    2000 \
    run-unitable


docker exec -it \
    -e POSTGRES_PASSWORD=notyoursecretpassword \
    -e POSTGRES_USER=postgres \
    -e PGOSM_DATA_SCHEMA_ONLY=true \
    -e PGOSM_DATA_SCHEMA_NAME=osm_uswest \
    pgosm bash docker/run_pgosm_flex.sh \
    north-america \
    us-west \
    2000 \
    run-road-place


# DEV Use only!  Ensure DB is empty first
psql -d postgres -c "DROP DATABASE IF EXISTS pgosm;"
psql -d postgres -c "CREATE DATABASE pgosm;"
psql -d pgosm -c "CREATE EXTENSION postgis;"


# Load output from PgOSM-Flex into the DB where you actually want it!
psql -d pgosm -f ~/pgosm-data/pgosm-flex-district-of-columbia-run-all.sql
psql -d pgosm -f ~/pgosm-data/pgosm-flex-colorado-run-all.sql
psql -d pgosm -f ~/pgosm-data/pgosm-flex-colorado-run-unitable.sql
psql -d pgosm -f ~/pgosm-data/pgosm-flex-us-west-run-road-place.sql


