Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 5 additions & 7 deletions dev-db/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,18 @@ help:

up:
@echo "Starting development database..."
docker-compose up -d
docker compose up -d
@echo "Waiting for database to be ready..."
@$(MAKE) wait
@echo "Database ready at localhost:5439"
@$(MAKE) wait
@$(MAKE) seed

down:
docker-compose down
docker compose down

logs:
docker-compose logs -f database
docker compose logs -f database

reset:
@echo "Resetting database (this removes all data)..."
Expand All @@ -33,15 +33,13 @@ reset:

apply-schema:
@echo "Applying database schema updates..."
docker-compose exec -T database psql -U username -d postgres -f /docker-entrypoint-initdb.d/01-init.sql
docker compose exec -T database psql -U username -d postgres -f /docker-entrypoint-initdb.d/01-init.sql

seed:
@python seed_sample_data.py

clean:
docker-compose down -v --remove-orphans
@echo "Removing local database files..."
@rm -rf .pgdata
docker compose down -v --remove-orphans

# Cross-platform wait command
wait:
Expand Down
2 changes: 2 additions & 0 deletions dev-db/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ The seeding script loads two parquet datasets into the development database:
- `space2stats_sample_cs.parquet` → inserted into the `space2stats` table. It contains administrative boundaries, demographic breakdowns, nighttime lights, built area statistics, GHS indicators, and flood exposure metrics.
- `space2stats_sample_ts.parquet` → inserted into the `climate` table. It provides Standardized Precipitation Index (SPI) climate time series aggregated by H3 hexagon.

Both parquet files must live in `init-scripts/data/` with the exact filenames above (the seed script reads from that directory).

The latest copies of these parquet files are stored in `s3://wbg-geography01/Space2Stats/sample_data/local_db/`.

## Troubleshooting
Expand Down
20 changes: 11 additions & 9 deletions dev-db/docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
services:
database:
db:
container_name: dev-db
platform: linux/amd64
build:
context: .
dockerfile: Dockerfile
environment:
- POSTGRES_USER=username
- POSTGRES_PASSWORD=password
- POSTGRES_DB=postgres
POSTGRES_USER: username
POSTGRES_PASSWORD: password
POSTGRES_DB: postgres
ports:
- 5439:5432
command: >
Expand All @@ -29,9 +30,8 @@ services:
-c min_wal_size=1GB
-c max_wal_size=4GB
volumes:
- ./.pgdata:/var/lib/postgresql/data
- dev_db_data:/var/lib/postgresql/data
- ./init-scripts:/docker-entrypoint-initdb.d
- ./space2stats_sample_cs.parquet:/docker-entrypoint-initdb.d/data/space2stats_sample_cs.parquet

healthcheck:
test: ["CMD-SHELL", "pg_isready -U username -d postgres"]
Expand All @@ -43,15 +43,17 @@ services:
pgadmin:
image: dpage/pgadmin4:latest
environment:
- PGADMIN_DEFAULT_EMAIL=admin@space2stats.com
- PGADMIN_DEFAULT_PASSWORD=admin
PGADMIN_DEFAULT_EMAIL: admin@space2stats.com
PGADMIN_DEFAULT_PASSWORD: admin
ports:
- 8080:80
depends_on:
database:
db:
condition: service_healthy
volumes:
- pgadmin_data:/var/lib/pgadmin
- ./pgadmin-servers.json:/pgadmin4/servers.json:ro

volumes:
pgadmin_data:
dev_db_data:
14 changes: 14 additions & 0 deletions dev-db/pgadmin-servers.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"Servers": {
"1": {
"Name": "Space2Stats Dev",
"Group": "Development",
"Host": "db",
"Port": 5432,
"MaintenanceDB": "postgres",
"Username": "username",
"SSLMode": "prefer",
"Comment": "Auto-registered by docker-compose"
}
}
}
5 changes: 3 additions & 2 deletions dev-db/seed_sample_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,12 +134,13 @@ def insert_data_to_db(
def main() -> None:
"""Load the Space2Stats sample datasets into the development database."""
script_dir = Path(__file__).parent
data_dir = script_dir / "init-scripts" / "data"

main_table = get_table_name("PGTABLENAME", DEFAULT_MAIN_TABLE)
ts_table = get_table_name("TIMESERIES_TABLE_NAME", DEFAULT_TS_TABLE)

cs_file = script_dir / "space2stats_sample_cs.parquet"
ts_file = script_dir / "space2stats_sample_ts.parquet"
cs_file = data_dir / "space2stats_sample_cs.parquet"
ts_file = data_dir / "space2stats_sample_ts.parquet"

print(f"Preparing to seed cross-sectional data into '{main_table}'.")
cs_df = load_parquet_data(cs_file)
Expand Down
Loading