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
49ifneq (,$(wildcard ./.env))
include .env
export
endif
MIGRATIONS_DIR=internal/db/migrations
DB_DSN=postgres://$(DB_USERNAME):$(DB_PASSWORD)@$(DB_HOST):$(DB_PORT)/$(DB_NAME)?sslmode=$(DB_SSLMODE)
.PHONY: build run migrate-create migrate-up migrate-down test lint
build:
@go build -o ./target/main ./main.go
run: build
@./target/main \
-app-port=$(APP_PORT) \
-frontend-url=$(FRONTEND_URL) \
-db-host=$(DB_HOST) \
-db-port=$(DB_PORT) \
-db-name=$(DB_NAME) \
-db-username=$(DB_USERNAME) \
-db-password=$(DB_PASSWORD) \
-db-sslmode=$(DB_SSLMODE)
migrate-create:
@if [ -z "$(NAME)" ]; then \
echo "Error: NAME is required. Usage: make migrate-create NAME=your_migration_name"; \
exit 1; \
fi
@echo "Creating migration: $(NAME)"
@goose -dir $(MIGRATIONS_DIR) create $(NAME) sql
migrate-up:
@echo "Running migrations..."
@goose -dir $(MIGRATIONS_DIR) postgres "$(DB_DSN)" up
migrate-down:
@echo "Running migrations..."
@goose -dir $(MIGRATIONS_DIR) postgres "$(DB_DSN)" down
test:
@go test ./...
lint:
@golangci-lint run
lint-fix:
@golangci-lint run --fix