DOCKER_REGISTRY ?= static.ranneft.ru:25000
IMAGE_TAG ?= latest
export DOCKER_REGISTRY IMAGE_TAG

.PHONY: up down logs restart clean backend-test frontend-dev docker-build docker-push migrate migrate-bootstrap

# Apply incremental SQL migrations (skips 000001_* — Docker initdb runs that on first DB init).
ifeq ($(OS),Windows_NT)
migrate:
	powershell -NoProfile -ExecutionPolicy Bypass -File scripts/migrate.ps1

migrate-bootstrap:
	powershell -NoProfile -ExecutionPolicy Bypass -File scripts/migrate.ps1 -Bootstrap
else
migrate:
	sh scripts/migrate.sh

migrate-bootstrap:
	MIGRATE_INCLUDE_BOOTSTRAP=1 sh scripts/migrate.sh
endif

up:
	docker compose up -d --build

down:
	docker compose down

logs:
	docker compose logs -f

restart: down up

backend-test:
	cd backend && go test -race ./...

frontend-dev:
	cd frontend && npm install && npm run dev

clean:
	docker compose down -v
	docker compose build --no-cache

# Build custom images with registry tags (backend + frontend only; postgres/redis stay public pulls)
docker-build:
	docker compose build backend frontend

# Push custom images to $(DOCKER_REGISTRY) (login first: docker login $(DOCKER_REGISTRY))
docker-push: docker-build
	docker compose push backend frontend
