-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
188 lines (149 loc) Β· 5.75 KB
/
Copy pathMakefile
File metadata and controls
188 lines (149 loc) Β· 5.75 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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
# Makefile - Complete project management
.PHONY: help setup dev stop logs test clean migrate backup restore
# Colors for output
BLUE := \033[0;34m
GREEN := \033[0;32m
YELLOW := \033[0;33m
NC := \033[0m # No Color
help: ## Show this help message
@echo "$(BLUE)Bookl Trivia Game - Available Commands$(NC)"
@echo ""
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf "$(GREEN)%-20s$(NC) %s\n", $$1, $$2}'
# Setup Commands
setup: ## Complete setup with PostgreSQL
@echo "$(BLUE)π Setting up project with PostgreSQL...$(NC)"
@chmod +x scripts/*.sh
@./scripts/postgres-setup.sh
setup-local: ## Setup for local development (no Docker)
@echo "$(BLUE)π Setting up local environment...$(NC)"
@./scripts/setup-local.sh
# Development Commands
dev: ## Start all services (PostgreSQL + Backend)
@echo "$(BLUE)π Starting services...$(NC)"
@docker-compose up -d
@echo "$(GREEN)β
Services started!$(NC)"
@echo "API: http://localhost:8000/docs"
@echo "PostgreSQL: localhost:5432"
dev-local: ## Run backend locally (requires PostgreSQL running)
@echo "$(BLUE)π Starting backend locally...$(NC)"
@cd backend && uv run uvicorn app.main:app --reload --host 0.0.0.0 --port 8000
stop: ## Stop all services
@echo "$(YELLOW)π Stopping services...$(NC)"
@docker-compose stop
down: ## Stop and remove containers (preserves data)
@echo "$(YELLOW)π Stopping and removing containers...$(NC)"
@docker-compose down
# Database Commands
db-start: ## Start only PostgreSQL
@docker-compose up -d db
@echo "$(GREEN)β
PostgreSQL started on localhost:5432$(NC)"
db-stop: ## Stop PostgreSQL
@docker-compose stop db
db-connect: ## Connect to PostgreSQL via psql
@./scripts/postgres-connect.sh
db-reset: ## Reset database (WARNING: deletes all data)
@./scripts/postgres-reset.sh
# Migration Commands
migrate: ## Run database migrations
@echo "$(BLUE)π Running migrations...$(NC)"
@docker-compose exec backend uv run alembic upgrade head
@echo "$(GREEN)β
Migrations complete!$(NC)"
migrate-create: ## Create a new migration
@read -p "Migration description: " desc; \
docker-compose exec backend uv run alembic revision --autogenerate -m "$$desc"
migrate-rollback: ## Rollback last migration
@docker-compose exec backend uv run alembic downgrade -1
migrate-history: ## Show migration history
@docker-compose exec backend uv run alembic history
migrate-current: ## Show current migration version
@docker-compose exec backend uv run alembic current
# Data Management Commands
import-data: ## Import sample data
@echo "$(BLUE)π Importing sample data...$(NC)"
@docker-compose exec backend uv run python data_import.py
@echo "$(GREEN)β
Data imported!$(NC)"
backup: ## Backup PostgreSQL database
@./scripts/postgres-backup.sh
restore: ## Restore database from backup
@./scripts/postgres-restore.sh
# Testing Commands
test: ## Run all tests
@echo "$(BLUE)π§ͺ Running tests...$(NC)"
@cd backend && uv run pytest tests/ -v --cov=app --cov-report=term-missing
test-fast: ## Run tests without coverage
@cd backend && uv run pytest tests/ -v
test-api: ## Test API endpoints manually
@./scripts/test-api.sh
test-text: ## Test text matching
@cd backend && uv run python app/text_utils.py
# Logs and Monitoring
logs: ## Show logs from all services
@docker-compose logs -f
logs-backend: ## Show backend logs only
@docker-compose logs -f backend
logs-db: ## Show PostgreSQL logs only
@docker-compose logs -f db
status: ## Show service status
@docker-compose ps
# Container Access
shell: ## Open shell in backend container
@docker-compose exec backend bash
shell-db: ## Open PostgreSQL shell
@./scripts/postgres-connect.sh
# Maintenance Commands
clean: ## Clean up containers, volumes, and cache
@echo "$(YELLOW)π§Ή Cleaning up...$(NC)"
@docker-compose down -v
@docker system prune -f
@rm -rf backend/.pytest_cache backend/__pycache__ backend/app/__pycache__
@rm -rf backend/.coverage htmlcov
@echo "$(GREEN)β
Cleanup complete!$(NC)"
rebuild: ## Rebuild containers from scratch
@echo "$(BLUE)π¨ Rebuilding containers...$(NC)"
@docker-compose down
@docker-compose build --no-cache
@docker-compose up -d
@sleep 5
@make migrate
@make import-data
@echo "$(GREEN)β
Rebuild complete!$(NC)"
# Dependency Management
deps-add: ## Add a new dependency (usage: make deps-add pkg=package-name)
@cd backend && uv add $(pkg)
deps-remove: ## Remove a dependency (usage: make deps-remove pkg=package-name)
@cd backend && uv remove $(pkg)
deps-sync: ## Sync dependencies
@cd backend && uv sync
deps-lock: ## Update lock file
@cd backend && uv lock
# pgAdmin Helper
pgadmin-info: ## Show pgAdmin connection details
@echo "$(BLUE)π pgAdmin Connection Information:$(NC)"
@echo ""
@echo "$(GREEN)Host:$(NC) localhost"
@echo "$(GREEN)Port:$(NC) 5432"
@echo "$(GREEN)Database:$(NC) bookl"
@echo "$(GREEN)Username:$(NC) bookl_user"
@echo "$(GREEN)Password:$(NC) bookl_pass"
@echo ""
@echo "$(YELLOW)To connect:$(NC)"
@echo "1. Open pgAdmin"
@echo "2. Right-click 'Servers' β Create β Server"
@echo "3. Enter the details above"
# Development Helpers
check: ## Check if everything is working
@echo "$(BLUE)π Checking system status...$(NC)"
@echo ""
@echo "$(GREEN)Docker Containers:$(NC)"
@docker-compose ps
@echo ""
@echo "$(GREEN)API Health:$(NC)"
@curl -s http://localhost:8000/health | jq . || echo "β API not responding"
@echo ""
@echo "$(GREEN)Database Connection:$(NC)"
@docker-compose exec -T db pg_isready -U bookl_user -d bookl || echo "β Database not ready"
dev-setup: setup dev migrate import-data ## Complete development setup (one command)
@echo ""
@echo "$(GREEN)β
Development environment ready!$(NC)"
@echo "$(BLUE)API Documentation:$(NC) http://localhost:8000/docs"
@echo "$(BLUE)Connect pgAdmin:$(NC) make pgadmin-info"