-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
86 lines (60 loc) · 2.83 KB
/
Makefile
File metadata and controls
86 lines (60 loc) · 2.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# Makefile
# Variables
BACKEND_DIR=fastapi_backend
FRONTEND_DIR=nextjs-frontend
DOCKER_COMPOSE=docker-compose
DB_SERVICE := db # your Postgres service name in docker-compose.yml
DB_USER := postgres # the DB super-user
DB_NAME := mydatabase # the name of your database
# Help
.PHONY: help
help:
@echo "Available commands:"
@awk '/^[a-zA-Z_-]+:/{split($$1, target, ":"); print " " target[1] "\t" substr($$0, index($$0,$$2))}' $(MAKEFILE_LIST)
# Backend commands
.PHONY: start-backend test-backend
start-backend: ## Start the backend server with FastAPI and hot reload
cd $(BACKEND_DIR) && ./start.sh
test-backend: ## Run backend tests using pytest
cd $(BACKEND_DIR) && uv run pytest
# Frontend commands
.PHONY: start-frontend test-frontend
start-frontend: ## Start the frontend server with pnpm and hot reload
cd $(FRONTEND_DIR) && ./start.sh
test-frontend: ## Run frontend tests using npm
cd $(FRONTEND_DIR) && pnpm run test
# Docker commands
.PHONY: docker-backend-shell docker-frontend-shell docker-build docker-build-backend \
docker-build-frontend docker-start-backend docker-start-frontend docker-up-test-db \
docker-migrate-db docker-db-schema docker-test-backend docker-test-frontend
docker-backend-shell: ## Access the backend container shell
$(DOCKER_COMPOSE) run --rm backend sh
docker-frontend-shell: ## Access the frontend container shell
$(DOCKER_COMPOSE) run --rm frontend sh
docker-build: ## Build all the services
$(DOCKER_COMPOSE) build --no-cache
docker-build-backend: ## Build the backend container with no cache
$(DOCKER_COMPOSE) build backend --no-cache
docker-build-frontend: ## Build the frontend container with no cache
$(DOCKER_COMPOSE) build frontend --no-cache
docker-start-backend: ## Start the backend container
$(DOCKER_COMPOSE) up backend
docker-start-frontend: ## Start the frontend container
$(DOCKER_COMPOSE) up frontend
docker-up-test-db: ## Start the test database container
$(DOCKER_COMPOSE) up db_test
docker-migrate-db: ## Run database migrations using Alembic
$(DOCKER_COMPOSE) run --rm backend alembic upgrade head
docker-db-schema: ## Generate a new migration schema. Usage: make docker-db-schema migration_name="add users"
$(DOCKER_COMPOSE) run --rm backend alembic revision --autogenerate -m "$(migration_name)"
docker-test-backend: ## Run tests for the backend
$(DOCKER_COMPOSE) run --rm backend pytest
docker-test-frontend: ## Run tests for the frontend
$(DOCKER_COMPOSE) run --rm frontend pnpm run test
.PHONY: drop-all-db
drop-all-db: ## Completely wipe all tables (public schema) and start fresh
@echo "🚨 Dropping public schema in service '$(DB_SERVICE)' (DB: $(DB_NAME))..."
@echo 'DROP SCHEMA public CASCADE; CREATE SCHEMA public;' \
| $(DOCKER_COMPOSE) exec -T $(DB_SERVICE) \
psql -U $(DB_USER) -d $(DB_NAME)
@echo "✅ All tables dropped. Public schema recreated."