#!/usr/bin/env make

SHELL = /bin/bash
UID := $(shell id -u)
GID := $(shell id -g)

export UID
export GID

frontend/node_modules:
	docker run --rm -v ${PWD}/frontend:/app -w /app -u ${UID}:${GID} node:16-bullseye npm i

backend/right_tree/staticfiles:
	docker run --rm -v ${PWD}/backend:/app -w /app -u ${UID}:${GID} right-tree python manage.py collectstatic --noinput

ingest:
	docker-compose up -d backend postgres
	docker-compose exec backend python manage.py loaddata \
		/app/right_tree/api/data/fixtures/001_eco_regions.json \
		/app/right_tree/api/data/fixtures/002_tolerance_levels.json \
		/app/right_tree/api/data/fixtures/003_soil_variants.json \
		/app/right_tree/api/data/fixtures/004_soil_order_mappings.json \
		/app/right_tree/api/data/fixtures/005_habitats.json \
		/app/right_tree/api/data/fixtures/006_zones.json \
		/app/right_tree/api/data/fixtures/007_habitat_images.json
	docker-compose exec backend python manage.py loadshapefiles
	docker-compose exec backend python manage.py createplantfixtures
	docker-compose exec backend python manage.py loaddata \
		/app/right_tree/api/data/fixtures/plants.json

createsuperuser:
	docker-compose up -d backend
	docker-compose exec backend python manage.py createsuperuser

shell:
	docker-compose up -d backend
	docker-compose exec backend python manage.py shell

psql:
	docker-compose up -d postgres
	docker-compose exec postgres psql -U righttree -d righttree

build:
	docker build --no-cache -t right-tree backend

start: frontend/node_modules backend/right_tree/staticfiles
	docker-compose up -d
	docker-compose logs -f

logs:
	docker-compose logs -f

stop:
	docker-compose down

clean: stop
	git clean -dxf

reset: clean
	docker-compose down --volumes --remove-orphans
