-
-
Notifications
You must be signed in to change notification settings - Fork 25
/
Makefile
124 lines (97 loc) · 3.57 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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
include .env
BOLD='\033[1m'
END_BOLD='\033[0m'
DB_TARGETS=db_postgres db_mysql db_sqlite
WAIT_TARGETS=wait_for_postgres wait_for_mysql wait_for_sqlite
DIESEL_TARGETS=diesel_postgres diesel_mysql diesel_sqlite
CLEAN_TARGETS=clean_postgres clean_mysql clean_sqlite
STOP_TARGETS=stop_postgres stop_mysql stop_sqlite
.DEFAULT_GOAL=default
default: db tests ignored stop
.PHONY: db $(DB_TARGETS) \
$(WAIT_TARGETS) \
diesel $(DIESEL_TARGETS) \
clean $(CLEAN_TARGETS)
stop $(STOP_TARGETS) \
default clippy tests ignored doc .FORCE
.SILENT: $(DB_TARGETS) $(WAIT_TARGETS) $(DIESEL_TARGETS) $(CLEAN_TARGETS) $(STOP_TARGETS)
.NOTPARALLEL: default
db: $(DB_TARGETS)
db_postgres:
@echo -e $(BOLD)Setting up Postgres database...$(END_BOLD)
docker run --rm -d --name "$(POSTGRES_CONTAINER)" -p 5432:5432 \
-e POSTGRES_DB="$(POSTGRES_DB)" \
-e POSTGRES_USER="$(POSTGRES_USER)" \
-e POSTGRES_PASSWORD="$(POSTGRES_PASSWORD)" \
postgres:"$(POSTGRES_VERSION)"
$(MAKE) diesel_postgres
db_mysql:
@echo -e $(BOLD)Setting up MySQL database...$(END_BOLD)
docker run --rm -d --name "$(MYSQL_CONTAINER)" -p 3306:3306 \
-e MYSQL_DATABASE="$(MYSQL_DB)" \
-e MYSQL_ROOT_PASSWORD="$(MYSQL_PASSWORD)" \
-e TZ=UTC \
mysql:"$(MYSQL_VERSION)"
$(MAKE) diesel_mysql
db_sqlite:
@echo -e $(BOLD)Setting up SQLite database...$(END_BOLD)
sqlite3 "$(SQLITE_FILE)" "VACUUM;"
mkdir -p "$(SQLITE_TESTS_DIR)"
$(MAKE) diesel_sqlite
diesel: $(DIESEL_TARGETS)
diesel_postgres:
@echo -e $(BOLD)Running Diesel migrations on Postgres database...$(END_BOLD)
while ! diesel migration run --database-url "$(POSTGRES_URL)" --migration-dir "$(POSTGRES_MIGRATIONS)" --config-file "$(POSTGRES_CONFIG)" 2> /dev/null; \
do \
sleep 1; \
done
diesel_mysql:
@echo -e $(BOLD)Running Diesel migrations on MySQL database...$(END_BOLD)
while ! diesel migration run --database-url "$(MYSQL_URL)" --migration-dir "$(MYSQL_MIGRATIONS)" --config-file "$(MYSQL_CONFIG)" 2> /dev/null; \
do \
sleep 1; \
done
diesel_sqlite:
@echo -e $(BOLD)Running Diesel migrations on SQLite database...$(END_BOLD)
while ! diesel migration run --database-url sqlite://"$(SQLITE_FILE)" --migration-dir "$(SQLITE_MIGRATIONS)" --config-file "$(SQLITE_CONFIG)" 2> /dev/null; \
do \
sleep 1; \
done
clean: $(CLEAN_TARGETS)
clean_postgres:
@echo -e $(BOLD)Cleaning Postgres database...$(END_BOLD)
docker exec "$(POSTGRES_CONTAINER)" dropdb -U "$(POSTGRES_USER)" "$(POSTGRES_DB)"
docker exec "$(POSTGRES_CONTAINER)" psql -U "$(POSTGRES_USER)" --command="CREATE DATABASE $(POSTGRES_DB);"
$(MAKE) diesel_postgres
clean_mysql:
@echo -e $(BOLD)Cleaning MySQL database...$(END_BOLD)
docker exec "$(MYSQL_CONTAINER)" mysql \
--user="$(MYSQL_USER)" \
--password="$(MYSQL_PASSWORD)" \
--execute="DROP DATABASE $(MYSQL_DB); CREATE DATABASE $(MYSQL_DB);"
$(MAKE) diesel_mysql
clean_sqlite:
@echo -e $(BOLD)Cleaning SQLite database...$(END_BOLD)
$(MAKE) stop_sqlite
$(MAKE) db_sqlite
stop: $(STOP_TARGETS)
stop_postgres:
@echo -e $(BOLD)Stopping Postgres database...$(END_BOLD)
docker kill "$(POSTGRES_CONTAINER)"
stop_mysql:
@echo -e $(BOLD)Stopping MySQL database...$(END_BOLD)
docker kill "$(MYSQL_CONTAINER)"
stop_sqlite:
@echo -e $(BOLD)Stopping SQLite database...$(END_BOLD)
rm "$(SQLITE_FILE)"
clippy:
cargo clippy --verbose --all-targets --all-features -- -D warnings
tests:
@echo -e $(BOLD)Running tests...$(END_BOLD)
cargo test --all-features -- --color always --nocapture
ignored:
@echo -e $(BOLD)Running ignored tests...$(END_BOLD)
cargo test --all-features -- --color always --nocapture --ignored
$(MAKE) clean
doc:
cargo doc --package fang --open