-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
169 lines (142 loc) · 5.29 KB
/
Makefile
File metadata and controls
169 lines (142 loc) · 5.29 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
# Makefile for Django Portfolio Blog with NYC Taxi API
# Usage: make <target>
.PHONY: help build up down restart logs shell migrate makemigrations createsuperuser collectstatic test clean load-sample load-taxi-data
# Default target
help:
@echo "Available commands:"
@echo " build - Build Docker containers"
@echo " up - Start the application"
@echo " down - Stop the application"
@echo " restart - Restart the application"
@echo " logs - View application logs"
@echo " shell - Open Django shell"
@echo " bash - Open bash shell in web container"
@echo " migrate - Run database migrations"
@echo " makemigrations - Create new migrations"
@echo " createsuperuser - Create Django superuser"
@echo " collectstatic - Collect static files"
@echo " test - Run tests"
@echo " clean - Clean up containers and volumes"
@echo " api-test-duckdb - Test DuckDB-based endpoints"
@echo " db-check - Check database connection"
@echo " db-stats - Show database size and statistics"
@echo " db-clean - Clean database to free space"
@echo " db-cleanup - Advanced database cleanup (interactive)"
@echo " db-vacuum - Vacuum database to reclaim space"
# Docker commands
build:
docker-compose build
up:
docker-compose up -d
@echo "Application started at http://localhost:8000"
@echo "API endpoints available at http://localhost:8000/api/"
down:
docker-compose down
restart: down up
logs:
docker-compose logs -f
# Django management commands
shell:
docker-compose run --rm web python manage.py shell
bash:
docker-compose run --rm web bash
migrate:
docker-compose run --rm web python manage.py migrate
makemigrations:
docker-compose run --rm web python manage.py makemigrations
createsuperuser:
docker-compose run --rm web python manage.py createsuperuser
collectstatic:
docker-compose run --rm web python manage.py collectstatic --noinput
test:
docker-compose run --rm web python manage.py test
# API testing
api-test-duckdb:
@echo "Testing DuckDB-based API endpoints..."
@echo "These query parquet files directly - no database storage needed!"
@echo ""
@echo "Testing with 2023 data (month 1):"
@curl -s "http://localhost:8000/api/taxi-data/summary/?year=2023&month=1" | head -c 300
@echo ""
@echo "Testing trip stats:"
@curl -s "http://localhost:8000/api/taxi-data/stats/?year=2023&month=1" | head -c 300
@echo ""
@echo "Testing sample trips:"
@curl -s "http://localhost:8000/api/taxi-data/trips/?year=2023&month=1&limit=5" | head -c 500
# Database commands
db-check:
@echo "Checking database connection..."
docker-compose run --rm web python manage.py check --database default
db-stats:
@echo "Getting database statistics..."
docker-compose run --rm web python manage.py db_stats
db-clean:
@echo "Cleaning up database to free space..."
@echo "This will remove all taxi data but keep the database structure"
@read -p "Are you sure? (y/N): " confirm; \
if [ "$$confirm" = "y" ] || [ "$$confirm" = "Y" ]; then \
docker-compose run --rm web python manage.py shell -c "from taxi_api.models import Trip, Zone; Trip.objects.all().delete(); print('Taxi data cleared')"; \
echo "Database cleaned - taxi data removed"; \
else \
echo "Cancelled"; \
fi
db-vacuum:
@echo "Running database vacuum to reclaim space..."
@echo "This will optimize the database and reclaim deleted space"
docker-compose run --rm web python manage.py shell -c "from django.db import connection; cursor = connection.cursor(); cursor.execute('VACUUM FULL;'); print('Database vacuum completed')"
db-cleanup:
@echo "Advanced database cleanup options:"
@echo " --keep-records N - Keep N most recent records"
@echo " --older-than-days N - Delete records older than N days"
@echo " --vacuum - Run VACUUM after cleanup"
@echo " --dry-run - Show what would be deleted"
@echo ""
@echo "Examples:"
@echo " make db-cleanup ARGS='--keep-records 5000 --vacuum'"
@echo " make db-cleanup ARGS='--older-than-days 30 --dry-run'"
@echo " make db-cleanup ARGS='--vacuum'"
@echo ""
@read -p "Enter arguments (or press Enter for --dry-run): " args; \
if [ -z "$$args" ]; then \
args="--dry-run"; \
fi; \
docker-compose run --rm web python manage.py cleanup_data $$args
db-reset:
@echo "WARNING: This will delete all data!"
@read -p "Are you sure? (y/N): " confirm; \
if [ "$$confirm" = "y" ] || [ "$$confirm" = "Y" ]; then \
docker-compose down; \
docker volume rm new_profile_postgres_data 2>/dev/null || true; \
docker-compose up -d postgres; \
sleep 5; \
docker-compose run --rm web python manage.py migrate; \
echo "Database reset complete"; \
else \
echo "Cancelled"; \
fi
# Development commands
dev-setup: build migrate
@echo "Development environment setup complete!"
@echo "Run 'make up' to start the application"
# Cleanup commands
clean:
docker-compose down -v
docker system prune -f
docker volume prune -f
clean-all: clean
docker-compose down --rmi all -v
docker system prune -a -f
# Status check
status:
@echo "Container status:"
@docker-compose ps
@echo ""
@echo "Recent logs:"
@docker-compose logs --tail=10
# Quick development cycle
quick-restart:
docker-compose restart web
@echo "Web container restarted"
# View Django logs specifically
django-logs:
docker-compose logs -f web