forked from iamSH4NTO/amar-pathagar-backend
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
95 lines (81 loc) · 4.01 KB
/
Makefile
File metadata and controls
95 lines (81 loc) · 4.01 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
############################
# Makefile for Amar Pathagar Backend
############################
# --------------------------------------------------
# Load environment variables from .env
# --------------------------------------------------
ifneq (,$(wildcard ./.env))
include .env
export
endif
# --------------------------------------------------
# Configuration
# --------------------------------------------------
COMPOSE_FILE = docker-compose.yml
COMPOSE_DEV_FILE = docker-compose.dev.yml
MIGRATIONS_DIR = migrations
.DEFAULT_GOAL := help
# --------------------------------------------------
# Help
# --------------------------------------------------
.PHONY: help
help: ## Show this help message
@echo "╔════════════════════════════════════════════════════════════╗"
@echo "║ Amar Pathagar Backend - Makefile Commands ║"
@echo "╚════════════════════════════════════════════════════════════╝"
@echo ""
@echo "Usage: make [target]"
@echo ""
@grep -hE '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | \
awk 'BEGIN {FS = ":.*?## "}; {printf " \033[36m%-20s\033[0m %s\n", $$1, $$2}'
# --------------------------------------------------
# Development
# --------------------------------------------------
.PHONY: dev
dev: ## Start development environment
docker compose -f $(COMPOSE_DEV_FILE) up -d --build
@echo "✅ Development environment started"
@echo "📝 API: http://localhost:8080"
@echo "📋 Logs: make logs"
.PHONY: logs
logs: ## Follow application logs
docker compose -f $(COMPOSE_DEV_FILE) logs -f backend
.PHONY: dev-down
dev-down: ## Stop development environment
docker compose -f $(COMPOSE_DEV_FILE) down
@echo "✅ Development environment stopped"
# --------------------------------------------------
# Production
# --------------------------------------------------
.PHONY: prod
prod: ## Start production environment
docker compose -f $(COMPOSE_FILE) up -d --build
@echo "✅ Production environment started"
.PHONY: prod-down
prod-down: ## Stop production environment
docker compose -f $(COMPOSE_FILE) down
@echo "✅ Production environment stopped"
# --------------------------------------------------
# Database Migrations
# --------------------------------------------------
.PHONY: migrate-up
migrate-up: ## Run migrations
docker compose -f $(COMPOSE_DEV_FILE) exec backend goose -dir $(MIGRATIONS_DIR) postgres "postgres://$(DB_USER):$(DB_PASSWORD)@postgres:5432/$(DB_NAME)?sslmode=disable" up
@echo "✅ Migrations applied"
.PHONY: migrate-down
migrate-down: ## Roll back last migration
docker compose -f $(COMPOSE_DEV_FILE) exec backend goose -dir $(MIGRATIONS_DIR) postgres "postgres://$(DB_USER):$(DB_PASSWORD)@postgres:5432/$(DB_NAME)?sslmode=disable" down
@echo "✅ Migration rolled back"
.PHONY: migrate-status
migrate-status: ## Show migration status
docker compose -f $(COMPOSE_DEV_FILE) exec backend goose -dir $(MIGRATIONS_DIR) postgres "postgres://$(DB_USER):$(DB_PASSWORD)@postgres:5432/$(DB_NAME)?sslmode=disable" status
.PHONY: migrate-create
migrate-create: ## Create new migration (usage: make migrate-create NAME=create_users)
@if [ -z "$(NAME)" ]; then echo "❌ Usage: make migrate-create NAME=create_users"; exit 1; fi
docker compose -f $(COMPOSE_DEV_FILE) exec backend goose -dir $(MIGRATIONS_DIR) create $(NAME) sql
@echo "✅ Migration created in $(MIGRATIONS_DIR)/"
.PHONY: migrate-reset
migrate-reset: ## Reset all migrations and re-run
docker compose -f $(COMPOSE_DEV_FILE) exec backend goose -dir $(MIGRATIONS_DIR) postgres "postgres://$(DB_USER):$(DB_PASSWORD)@postgres:5432/$(DB_NAME)?sslmode=disable" reset
docker compose -f $(COMPOSE_DEV_FILE) exec backend goose -dir $(MIGRATIONS_DIR) postgres "postgres://$(DB_USER):$(DB_PASSWORD)@postgres:5432/$(DB_NAME)?sslmode=disable" up
@echo "✅ Migrations reset and reapplied"