-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmakefile
More file actions
75 lines (52 loc) · 1.85 KB
/
Copy pathmakefile
File metadata and controls
75 lines (52 loc) · 1.85 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
# Variables
APP_NAME := shortly
BUILD_DIR := ./bin
GOOSE_DRIVER := postgres
GOOSE_DBSTRING := postgresql://postgres:mypassword@localhost:5432/postgres?sslmode=disable
GOOSE_MIGRATION_DIR := sql/schema/
.PHONY: install
install: ## Create a install dev dependencies
@echo "Installing goose..."
@go install github.com/pressly/goose/v3/cmd/goose@latest
@echo "Installing sqlc..."
@go install github.com/sqlc-dev/sqlc/cmd/sqlc@latest
@echo "Installing air..."
@go install github.com/air-verse/air@latest
.PHONY: new-migration
new-migration: ## Create a new migration
@read -p "Enter migration name: " name; \
goose -dir $(GOOSE_MIGRATION_DIR) $(GOOSE_DRIVER) "$(GOOSE_DBSTRING)" create "$$name" sql
.PHONY: migrate-up
migrate-up: ## Apply all up migrations
@goose -dir $(GOOSE_MIGRATION_DIR) $(GOOSE_DRIVER) "$(GOOSE_DBSTRING)" up
.PHONY: migrate-down
migrate-down: ## Rollback the last migration
@goose -dir $(GOOSE_MIGRATION_DIR) $(GOOSE_DRIVER) "$(GOOSE_DBSTRING)" down
.PHONY: migrate-fix
migrate-fix: ## Rollback the last migration
@goose -dir $(GOOSE_MIGRATION_DIR) $(GOOSE_DRIVER) "$(GOOSE_DBSTRING)" fix
.PHONY: run-dev
run-dev:## run air - Live reload
@air
.PHONY: sqlc
sqlc:## Generate fully type-safe idiomatic code from SQL(folder:sql/queries)
@sqlc generate
.PHONY: gen-docs
gen-docs:## Generate and format swagger docs
@swag init && swag fmt
.PHONY: build
build:## Build executable
@echo "Building the project..."
@mkdir -p $(BUILD_DIR)
@go build -o $(BUILD_DIR)/$(APP_NAME) .
.PHONY: run
run:## Run executable
@echo "Running the project..."
@$(BUILD_DIR)/$(APP_NAME)
.PHONY: clean
clean:## Clean project
@echo "Cleaning up..."
@rm -rf $(BUILD_DIR) tmp *.exe
.PHONY: help
help: ## Show available commands
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-15s\033[0m %s\n", $$1, $$2}'