-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
40 lines (31 loc) · 812 Bytes
/
Makefile
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
# Variables
APP_NAME := api
BUILD_DIR := ./cmd/$(APP_NAME)
BUILD_OUTPUT := $(BUILD_DIR)/$(APP_NAME)
MIGRATE := migrate
DB_URL := $(GREENLIGHT_DB_DSN)
# Targets
.PHONY: all build run migrate-up migrate-down clean
# Default target
all: build run
# Build the application
build:
go build -o $(BUILD_OUTPUT) $(BUILD_DIR)
# Run the application
run: build
$(BUILD_OUTPUT)
debug:
dlv debug $(BUILD_DIR)
# Apply database migrations (up)
migrate-up:
$(MIGRATE) -path ./migrations -database "$(DB_URL)" up
# Rollback the latest database migration (down)
migrate-down:
$(MIGRATE) -path ./migrations -database "$(DB_URL)" down
migrate-create:
@echo "Enter migration name: " && \
read name && \
$(MIGRATE) create -seq -ext=.sql -dir=migrations $$name
# Clean up build artifacts
clean:
rm -f $(BUILD_OUTPUT)