-
Notifications
You must be signed in to change notification settings - Fork 1
/
Makefile
executable file
·81 lines (57 loc) · 1.74 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
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
# Variables
APP_NAME=LoyaltyPointsAPI
DB_USER ?= Njoguu
DB_PASSWORD ?= alannjoguu
DB_NAME ?= LoyaltyPointsDB
DB_ADDRESS ?= localhost
DB_PORT ?= 5433
DB_OWNER ?= Njoguu
DB_CONN = postgresql://$(DB_USER):$(DB_PASSWORD)@$(DB_HOST):$(DB_PORT)/$(DB_NAME)?sslmode=disable
CONTAINER_NAME ?= postgres_db
MIGRATION_EXT ?= "sql"
MIGRATION_DIR ?= "db/migrations"
#================================
#== DOCKER Targets
#================================
COMPOSE := @docker compose
remove:
$(COMPOSE) down
build:
$(COMPOSE) up --build -d
createdb:
docker exec -it $(CONTAINER_NAME) createdb --username=$(DB_USER) --owner=$(DB_OWNER) $(DB_NAME)
dropdb:
docker exec -it $(CONTAINER_NAME) dropdb -U $(DB_OWNER) $(DB_NAME)
start-services:
$(COMPOSE) start db
$(COMPOSE) start cache
$(COMPOSE) start api
stop-services:
$(COMPOSE) stop api
$(COMPOSE) stop cache
$(COMPOSE) stop db
restart-services: stop-services start-services
#================================
#== GOLANG ENVIRONMENT Targets
#================================
GO := @go
# install:
# ${GO} get .
tidy:
docker exec -it api ${GO} mod tidy
migratedb:
docker exec -it api ${GO} run migrate/migrate.go
#================================
#== DB MIGRATION Targets
#================================
create-migrations:
migrate create -ext $(MIGRATION_EXT) -dir $(MIGRATION_DIR) -seq $(MIGRATION_NAME)
migrateup:
migrate -path $(MIGRATION_DIR) -database "$(DB_CONN)" -verbose up
migratedown:
migrate -path $(MIGRATION_DIR) -database "$(DB_CONN)" -verbose down
migrateup1:
migrate -path $(MIGRATION_DIR) -database "$(DB_CONN)" -verbose up 1
migratedown1:
migrate -path $(MIGRATION_DIR) -database "$(DB_CONN)" -verbose down 1
.PHONY: createdb postgres dropdb migrateup migratedown create-migrations