.PHONY: down build up logs shell lock migrate migration import-dictionary

build:
	docker compose build --no-cache

up:
	docker compose up -d

down:
	docker compose down

logs:
	docker compose logs -f api

shell:
	docker compose exec api bash

# Run pending migrations against the running db container
migrate:
	docker compose build api --no-cache && docker compose up -d && docker compose exec api alembic upgrade head

migrate-no-build:
	docker compose exec api alembic upgrade head

# Generate a new migration: make migration NAME="add foo table"
migration:
	docker compose exec api alembic revision --autogenerate -m "$(NAME)"

# Generate a pinned requirements.txt from pyproject.toml (requires uv installed locally)
lock:
	cd api && uv pip compile pyproject.toml -o requirements.txt

rebuild: down build up

# Import a kaikki dictionary JSONL into Postgres.
# Requires the DB to be running with its port exposed on localhost (docker compose up).
# DATABASE_URL defaults to the docker-compose dev credentials.
# Usage: make import-dictionary lang=fr
import-dictionary:
	cd api && uv run ./scripts/import_dictionary.py --lang $(lang)
