Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add administrative geo shapes #136

Merged
merged 4 commits into from
Jul 31, 2024
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
38 changes: 29 additions & 9 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ SHELL := /bin/bash

# -- Docker
COMPOSE = bin/compose
COMPOSE_UP = $(COMPOSE) up -d --force-recreate
COMPOSE_RUN = $(COMPOSE) run --rm --no-deps
COMPOSE_RUN_API = $(COMPOSE_RUN) api
COMPOSE_RUN_API_PIPENV = $(COMPOSE_RUN_API) pipenv run
Expand Down Expand Up @@ -81,19 +82,23 @@ logs-opendata: ## display opendata logs (follow mode)
.PHONY: logs-opendata

run: ## run the api server (and dependencies)
$(COMPOSE) up -d --wait api
$(COMPOSE_UP) --wait api
.PHONY: run

run-all: ## run the whole stack
$(COMPOSE) up -d api keycloak metabase notebook opendata
$(COMPOSE_UP) api keycloak metabase notebook opendata
.PHONY: run-all

run-metabase: ## run the metabase service
$(COMPOSE_UP) metabase
.PHONY: run-metabase

run-notebook: ## run the notebook service
$(COMPOSE) up -d notebook
$(COMPOSE_UP) notebook
.PHONY: run-notebook

run-opendata: ## run the opendata service
$(COMPOSE) up -d opendata
$(COMPOSE_UP) opendata
.PHONY: run-opendata

status: ## an alias for "docker compose ps"
Expand Down Expand Up @@ -131,9 +136,20 @@ drop-metabase-db: ## drop Metabase database
@$(COMPOSE) exec postgresql bash -c 'psql "postgresql://$${POSTGRES_USER}:$${POSTGRES_PASSWORD}@$${QUALICHARGE_DB_HOST}:$${QUALICHARGE_DB_PORT}/postgres" -c "drop database \"$${MB_DB_DBNAME}\";"' || echo "Duly noted, skipping database deletion."
.PHONY: drop-metabase-db

dump-metabase: ## dump metabase objects
bin/pg_dump -a --inserts \
-t Report_Card \
-t Report_Dashboard \
-t Report_DashboardCard \
-t Dashboard_Tab \
-t Setting \
-U qualicharge \
metabaseappdb > src/metabase/custom.sql
.PHONY: dump-metabase

migrate-api: ## run alembic database migrations for the api service
@echo "Running api service database engine…"
@$(COMPOSE) up -d --wait postgresql
@$(COMPOSE_UP) --wait postgresql
@echo "Creating api service database…"
@$(COMPOSE) exec postgresql bash -c 'psql "postgresql://$${POSTGRES_USER}:$${POSTGRES_PASSWORD}@$${QUALICHARGE_DB_HOST}:$${QUALICHARGE_DB_PORT}/postgres" -c "create database \"$${QUALICHARGE_DB_NAME}\";"' || echo "Duly noted, skipping database creation."
@$(COMPOSE) exec postgresql bash -c 'psql "postgresql://$${POSTGRES_USER}:$${POSTGRES_PASSWORD}@$${QUALICHARGE_DB_HOST}:$${QUALICHARGE_DB_PORT}/$${QUALICHARGE_DB_NAME}" -c "create extension postgis;"' || echo "Duly noted, skipping extension creation."
Expand Down Expand Up @@ -164,9 +180,9 @@ jupytext--to-ipynb: ## convert remote md files into ipynb
reset-db: ## Reset the PostgreSQL database
$(COMPOSE) stop postgresql
$(COMPOSE) down postgresql
$(COMPOSE) up -d --force-recreate postgresql
$(COMPOSE_UP) postgresql
$(MAKE) migrate-api
$(COMPOSE) up -d --force-recreate api
$(COMPOSE_UP) api
$(MAKE) create-superuser
.PHONY: reset-db

Expand All @@ -178,17 +194,21 @@ seed-api: run

seed-metabase: ## seed the Metabase server
@echo "Running metabase service …"
@$(COMPOSE) up -d --wait metabase
@$(COMPOSE_UP) --wait metabase
@echo "Create metabase initial admin user…"
bin/metabase-init
@echo "Create API data source…"
$(COMPOSE_RUN) terraform init
$(COMPOSE_RUN) terraform apply -auto-approve
cat src/metabase/custom.sql | \
bin/psql \
-U qualicharge \
-d metabaseappdb
.PHONY: seed-metabase

seed-oidc: ## seed the OIDC provider
@echo 'Starting OIDC provider…'
@$(COMPOSE) up -d keycloak
@$(COMPOSE_UP) keycloak
@$(COMPOSE_RUN) dockerize -wait http://keycloak:8080 -timeout 60s
@echo 'Seeding OIDC client…'
@$(COMPOSE) exec keycloak /usr/local/bin/kc-init
Expand Down
5 changes: 5 additions & 0 deletions bin/pg_dump
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/usr/bin/env bash

docker compose exec postgresql \
pg_dump \
"$@"
5 changes: 5 additions & 0 deletions bin/psql
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/usr/bin/env bash

docker compose exec -T postgresql \
psql \
"$@"
1 change: 1 addition & 0 deletions src/api/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ and this project adheres to

- Allow to configure `API_STATIQUE_PAGE_MAX_SIZE` and `API_STATIQUE_PAGE_SIZE`
independently from `API_STATIQUE_BULK_CREATE_MAX_SIZE`
- Store french administrative levels and geographic boundaries (shapes)

### Changed

Expand Down
3 changes: 3 additions & 0 deletions src/api/Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,12 @@ annotated-types = "==0.7.0"
email-validator = "==2.2.0"
fastapi = "==0.111.1"
geoalchemy2 = {extras = ["shapely"], version = "==0.15.2"}
geopandas = "==1.0.1"
httpx = {extras = ["cli"], version = "==0.27.0"}
pandas = "==2.2.2"
passlib = {extras = ["bcrypt"], version = "==1.7.4"}
psycopg = {extras = ["pool", "binary"], version = "==3.2.1"}
pyarrow = "==17.0.0"
pydantic-extra-types = {extras = ["all"], version = "==2.9.0"}
pydantic-settings = "==2.3.4"
pyjwt = "==2.8.0"
Expand Down
158 changes: 156 additions & 2 deletions src/api/Pipfile.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions src/api/qualicharge/migrations/env.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
Station,
Status,
)
from qualicharge.schemas.geo import Region, Department, EPCI, City # noqa: F401

# this is the Alembic Config object, which provides
# access to the values within the .ini file in use.
Expand Down
Loading