-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
33 lines (25 loc) · 894 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
DB_NAME = $(shell cat .env | grep DB_NAME | cut -d = -f 2)
DB_USER = $(shell cat .env | grep DB_USER | cut -d = -f 2)
DB_PASSWORD = $(shell cat .env | grep DB_PASS | cut -d = -f 2)
DB_PORT = $(shell cat .env | grep DB_PORT | cut -d = -f 2)
DSN = mysql://$(DB_USER):$(DB_PASSWORD)@tcp(127.0.0.1:$(DB_PORT))/$(DB_NAME)?parseTime=true
.PHONY: create_migration
check_env:
echo $(DB_NAME), $(DB_USER), $(DB_PASSWORD)
check_dsn:
echo $(DSN)
create_migration:
ifndef NAME
@echo "Usage: make NAME=migration_name create_migration"
else
migrate create -ext sql -dir mysql/migrations -seq $(NAME)
endif
.PHONY: migrate_up
migrate_up:
migrate -path mysql/migrations -database "$(DSN)" up
.PHONY: migrate_down
migrate_down:
migrate -path mysql/migrations -database "$(DSN)" down 1
# setup golang-migrate
setup:
go install -tags 'mysql' github.com/golang-migrate/migrate/v4/cmd/migrate@latest