-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
47 lines (41 loc) · 1.75 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
.PHONY: db-migrate-make db-migrate-up db-migrate-down help
define HELP_MESSAGE
Usage:
make db-migrate-make migration_filename=<filename>
make db-migrate-up mysql_username=<mysql_username> mysql_password=<mysql_password>
make db-migrate-down mysql_username=<mysql_username> mysql_password=<mysql_password>
Example:
make db-migrate-make migration_filename=create_table_accounts
make db-migrate-up mysql_username=test mysql_password=test_password
make db-migrate-down mysql_username=test mysql_password=test_password
endef
export HELP_MESSAGE
help:
@echo "$$HELP_MESSAGE"
@echo ""
@echo "Available targets:"
@egrep -E '^[a-zA-Z0-9_.-]+:' $(MAKEFILE_LIST) | grep -vE 'help:|Example:|Usage:|.PHONY:' | awk 'BEGIN {FS = ":*?## "}; {printf " %-20s %s\n", $$1, $$2}'
migration_filename :=
mysql_username :=
mysql_password :=
db-migrate-make:
@if [ -z "$(migration_filename)" ]; then \
echo "Error: migration_filename is required."; \
echo "$$HELP_MESSAGE"; \
exit 1; \
fi
migrate create -ext sql -dir internal/db/migrations -seq $(migration_filename)
db-migrate-up:
@if [ -z "$(mysql_username)" ] || [ -z "$(mysql_password)" ]; then \
echo "Error: mysql_username and mysql_password are required."; \
echo "$$HELP_MESSAGE"; \
exit 1; \
fi
migrate -path internal/db/migrations -database "mysql://$(mysql_username):$(mysql_password)@tcp(localhost:3324)/wave_deploy_db" -verbose up
db-migrate-down:
@if [ -z "$(mysql_username)" ] || [ -z "$(mysql_password)" ]; then \
echo "Error: mysql_username and mysql_password are required."; \
echo "$$HELP_MESSAGE"; \
exit 1; \
fi
migrate -path internal/db/migrations -database "mysql://$(mysql_username):$(mysql_password)@tcp(localhost:3324)/wave_deploy_db" -verbose down