forked from risk-place-angola/backend-risk-place
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
35 lines (27 loc) · 1.46 KB
/
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
GO_BUILD = go build
GOFLAGS = CGO_ENABLED=0
DATABASE_HOST ?= localhost
DATABASE_PORT ?= $(shell grep "DB_PORT" .env | cut -d '=' -f2)
DATABASE_NAME ?= $(shell grep "DB_NAME" .env | cut -d '=' -f2)
DATABASE_USERNAME ?= $(shell grep "DB_USERNAME" .env | cut -d '=' -f2)
DATABASE_PASSWORD ?= $(shell grep "DB_PASSWORD" .env | cut -d '=' -f2)
DATABSE_DSN ?= ${DATABASE_USERNAME}:${DATABASE_PASSWORD}@${DATABASE_HOST}:${DATABASE_PORT}/${DATABASE_NAME}
# Version of migrations - this is optionally used on goto command
V?=
# Number of migrations - this is optionally used on up and down commands
N?=
.PHONY: migrate_setup migrate_up migrate_down migrate_goto migrate_drop_db
migrate_setup:
@if [ -z "$$(which migrate)" ]; then echo "Installing golang-migrate..."; go install -tags 'postgres' github.com/golang-migrate/migrate/v4/cmd/migrate@latest; fi
migrate_up: migrate_setup
@ migrate -database 'postgres://${DATABSE_DSN}?sslmode=disable' -path $$(pwd)/migrations up $(N)
migrate_down: migrate_setup
@ migrate -database 'postgres://${DATABSE_DSN}?sslmode=disable' -path $$(pwd)/migrations down $(N)
migrate_goto: migrate_setup
@ migrate -database 'postgres://${DATABSE_DSN}?sslmode=disable' -path $$(pwd)/migrations goto $(V)
migrate_drop_db: migrate_setup
@ migrate -database 'postgres://${DATABSE_DSN}?sslmode=disable' -path $$(pwd)/migrations drop
## build: Build app binary
.PHONY: build
build:
$(GOFLAGS) $(GO_BUILD) -a -v -ldflags="-w -s" -o bin/app main.go