-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
89 lines (67 loc) · 2.05 KB
/
Copy pathMakefile
File metadata and controls
89 lines (67 loc) · 2.05 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
# ======================
# Project and Main Files
# ======================
NAME = FastAPI-CRUD
include .env
export
SHELL := /bin/bash
.DEFAULT_GOAL = all
# ======================
# Migrations
# ======================
M ?= "init"
migrations-create:
@docker compose exec backend alembic revision --autogenerate -m "$(M)"
@echo "✅ Database migrations created successfully.";
migrations-up:
@docker compose exec backend alembic upgrade head
@echo "✅ Database migrations updated successfully.";
# ======================
# Database Tests
# ======================
wait-db:
@echo "⏳ Waiting for database..."
@until docker compose exec db pg_isready -U admin > /dev/null 2>&1; do \
sleep 1; \
done
@echo "✅ DB is ready"
test-db:
@docker compose exec backend python scripts/test_db.py
seed:
@docker compose exec backend python scripts/seed.py
TABLE = tasks
db-clean:
docker compose exec db psql -U admin -d todo_db -c \
"TRUNCATE TABLE $(TABLE) RESTART IDENTITY CASCADE;"
query-tables:
@docker compose exec db psql -U admin -d todo_db -c "\dt"
query-data:
@docker compose exec db psql -U admin -d todo_db -c \
"SELECT * FROM $(TABLE) LIMIT 5;"
# ======================
# Python Cache Cleanup
# ======================
rm-pycache:
@echo "🛠️ Removing Python cache files..."
@sudo find . -type d -name "__pycache__" -exec rm -rf {} +
@sudo find . -type f -name "*.pyc" -delete
@echo "✅ Python cache cleaned."
# ======================
# Rules
# ======================
all: up wait-db test-db migrations-up
up:
@docker compose up -d --build --wait
@echo "✅ $(NAME) is running at http://localhost:8000";
down:
@docker compose down
@echo "✅ $(NAME) has been stopped.";
clean:
@docker compose down --rmi local --remove-orphans
@echo "✅ $(NAME) has been cleaned.";
fclean:
@docker compose down --rmi local --volumes --remove-orphans
@${MAKE} --no-print-directory rm-pycache
@echo "✅ $(NAME) has been deep cleaned.";
.PHONY: migrations-create migrations-up wait-db test-db seed db-clean \
query-tables query-data rm-pycache all up down clean fclean