# MQTT Management Platform — Release 1 developer commands
# All commands assume a POSIX shell; on Windows use WSL/Git Bash or run the
# docker compose commands directly in PowerShell/cmd.

COMPOSE ?= docker compose
B ?= mqtt-backend

.PHONY: up down logs ps bootstrap migrate revision backend-shell test fmt lint

# --- Lifecycle -------------------------------------------------------------
up:            ## Start the whole stack in the background
	$(COMPOSE) up -d --build

down:          ## Stop the stack (volumes are preserved)
	$(COMPOSE) down

ps:            ## Show service status
	$(COMPOSE) ps

logs:          ## Tail all logs
	$(COMPOSE) logs -f

# --- Database --------------------------------------------------------------
migrate:       ## Apply Alembic migrations inside the running backend
	$(COMPOSE) exec $(B) alembic upgrade head

revision:      ## Create an empty Alembic revision (autogenerate)
	$(COMPOSE) exec $(B) alembic revision --autogenerate -m "$(m)"

backend-shell: ## Shell into the backend container
	$(COMPOSE) exec $(B) sh

# --- Tests -----------------------------------------------------------------
test:          ## Run backend test suite inside the container
	$(COMPOSE) run --rm $(B) pytest -q

# --- Quality ---------------------------------------------------------------
fmt:           ## Format backend sources
	$(COMPOSE) run --rm $(B) ruff format app tests

lint:          ## Lint backend sources
	$(COMPOSE) run --rm $(B) ruff check app tests