-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
200 lines (161 loc) · 5.73 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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
#
# Creates some databases, fill them with data, and then run syncdbdocs apps on
# them to check if works as expected
#
RANDVAR ?= default
NETWORK_NAME ?= sdd_network_$(RANDVAR)
SYNCDBDOCS_IMAGE ?= syncdbdocs
PG_CONTAINER ?= sdd_pg_$(RANDVAR)
MYSQL_CONTAINER ?= sdd_mysql_$(RANDVAR)
MSSQL_CONTAINER ?= sdd_mssql_$(RANDVAR)
PG_IMAGE_VERSION ?= latest
MYSQL_IMAGE_VERSION ?= latest
MSSQL_IMAGE_VERSION ?= 2019-latest
DB_NAME = dbtest
DB_USER = root
DB_PASS = pass
PG_PORT = 5432
MYSQL_PORT = 3306
MSSQL_PORT = 1433
MSSQL_USER = sa
MSSQL_PASS = _asdfASDF123
SQLITE_FILE = testdb.db
.PHONY: all test clean
all: | up build test clean
clean: | down
up: | net-up db-up migrate
down: | db-down net-down
net-up:
docker network create $(NETWORK_NAME) || true
net-down:
docker network rm $(NETWORK_NAME) || true
db-up: | pg-up mysql-up mssql-up
pg-up:
docker run -d --rm \
--name $(PG_CONTAINER) \
--network $(NETWORK_NAME) \
-e POSTGRES_DB=$(DB_NAME) \
-e POSTGRES_USER=$(DB_USER) \
-e POSTGRES_PASSWORD=$(DB_PASS) \
postgres:$(PG_IMAGE_VERSION)
mysql-up:
docker run -d --rm \
--name $(MYSQL_CONTAINER) \
--network $(NETWORK_NAME) \
-e MYSQL_DATABASE=$(DB_NAME) \
-e MYSQL_ROOT_PASSWORD=$(DB_PASS) \
mysql:$(MYSQL_IMAGE_VERSION)
mssql-up:
docker run -d --rm \
--name $(MSSQL_CONTAINER) \
--network $(NETWORK_NAME) \
-e ACCEPT_EULA=Y \
-e SA_PASSWORD=$(MSSQL_PASS) \
mcr.microsoft.com/mssql/server:$(MSSQL_IMAGE_VERSION)
migrate: | migrate-pg migrate-mysql migrate-mssql migrate-sqlite
migrate-pg:
docker run --rm \
--network $(NETWORK_NAME) \
-v $(PWD)/test/postgres:/flyway/sql \
flyway/flyway:7.11 \
-url=jdbc:postgresql://$(PG_CONTAINER):$(PG_PORT)/$(DB_NAME) \
-user=$(DB_USER) \
-password=$(DB_PASS) \
-connectRetries=5 \
migrate
migrate-mysql:
docker run --rm \
--network $(NETWORK_NAME) \
-v $(PWD)/test/mysql:/flyway/sql \
flyway/flyway:7.11 \
-url=jdbc:mysql://$(MYSQL_CONTAINER):$(MYSQL_PORT)/$(DB_NAME) \
-user=$(DB_USER) \
-password=$(DB_PASS) \
-connectRetries=5 \
migrate
migrate-mssql:
docker run --rm \
--network $(NETWORK_NAME) \
-v $(PWD)/test/mssql:/flyway/sql \
flyway/flyway:7.11 \
-mixed=true \
"-url=jdbc:sqlserver://$(MSSQL_CONTAINER):$(MSSQL_PORT);databaseName=master" \
-user=$(MSSQL_USER) \
-password=$(MSSQL_PASS) \
-connectRetries=5 \
migrate
migrate-sqlite:
rm -f $(PWD)/test/sqlite/$(SQLITE_FILE)
touch $(PWD)/test/sqlite/$(SQLITE_FILE)
docker run --rm \
-v $(PWD)/test/sqlite:/db:rw \
debian:stable \
bash -c " \
apt update \
&& apt install sqlite3 -y \
&& sqlite3 /db/$(SQLITE_FILE) < /db/V1__dbimport.sql \
"
db-down:
docker stop $(PG_CONTAINER) || true
docker stop $(MYSQL_CONTAINER) || true
docker stop $(MSSQL_CONTAINER) || true
build:
docker build . --tag $(SYNCDBDOCS_IMAGE)
PG_RUN_SYNCDBDOCS = docker run --rm \
--network $(NETWORK_NAME) \
-e DB_PASSWORD=$(DB_PASS) \
-v $(PWD)/test/postgres:/tmp/testpg/:ro \
$(SYNCDBDOCS_IMAGE) \
-h $(PG_CONTAINER) \
-p $(PG_PORT) \
-u $(DB_USER) \
-d $(DB_NAME)
test-pg:
$(PG_RUN_SYNCDBDOCS) -format=md > /tmp/dbtest.result
diff $(PWD)/test/postgres/dbtest-from-scratch.expected.md /tmp/dbtest.result || (echo "PG Test001.md failed" && false)
$(PG_RUN_SYNCDBDOCS) -format=text > /tmp/dbtest.result
diff $(PWD)/test/postgres/dbtest-from-scratch.expected.txt /tmp/dbtest.result || (echo "PG Test001.txt failed" && false)
$(PG_RUN_SYNCDBDOCS) -db-comments-first -clean -i /tmp/testpg/dbtest.input > /tmp/dbtest.result
diff $(PWD)/test/postgres/dbtest-preserve-order-clean.expected.txt /tmp/dbtest.result || (echo "PG Test002 failed" && false)
$(PG_RUN_SYNCDBDOCS) -clean -i /tmp/testpg/dbtest.input > /tmp/dbtest.result
diff $(PWD)/test/postgres/dbtest-preserve-file-comments-clean.expected.txt /tmp/dbtest.result || (echo "PG Test003 failed" && false)
$(PG_RUN_SYNCDBDOCS) -i /tmp/testpg/dbtest.input > /tmp/dbtest.result
diff $(PWD)/test/postgres/dbtest-preserve-order-and-fields.expected.txt /tmp/dbtest.result || (echo "PG Test004 failed" && false)
# retying with same file should leave things intact
$(PG_RUN_SYNCDBDOCS) -i /tmp/testpg/dbtest-preserve-order-and-fields.expected.txt > /tmp/dbtest.result
diff $(PWD)/test/postgres/dbtest-preserve-order-and-fields.expected.txt /tmp/dbtest.result || (echo "PG Test005 failed" && false)
MYSQL_RUN_SYNCDBDOCS = docker run --rm \
--network $(NETWORK_NAME) \
-e DB_PASSWORD=$(DB_PASS) \
-v $(PWD)/test/mysql:/tmp/testmysql/:ro \
$(SYNCDBDOCS_IMAGE) \
-h $(MYSQL_CONTAINER) \
-p $(MYSQL_PORT) \
-u $(DB_USER) \
-d $(DB_NAME)
test-mysql:
$(MYSQL_RUN_SYNCDBDOCS) -format=md > /tmp/dbtest.result
diff $(PWD)/test/mysql/dbtest-from-scratch.expected.md /tmp/dbtest.result || (echo "MYSQL Test001.md failed" && false)
$(MYSQL_RUN_SYNCDBDOCS) -format=text > /tmp/dbtest.result
diff $(PWD)/test/mysql/dbtest-from-scratch.expected.txt /tmp/dbtest.result || (echo "MYSQL Test001.txt failed" && false)
MSSQL_RUN_SYNCDBDOCS = docker run --rm \
--network $(NETWORK_NAME) \
-e DB_PASSWORD=$(MSSQL_PASS) \
-v $(PWD)/test/mysql:/tmp/testmysql/:ro \
$(SYNCDBDOCS_IMAGE) \
-h $(MSSQL_CONTAINER) \
-p $(MSSQL_PORT) \
-u $(MSSQL_USER) \
-d $(DB_NAME)
test-mssql:
$(MSSQL_RUN_SYNCDBDOCS) -format=text > /tmp/dbtest.result
diff $(PWD)/test/mssql/dbtest-from-scratch.expected.txt /tmp/dbtest.result || (echo "MSSQL Test001.txt failed" && false)
SQLITE_RUN_SYNCDBDOCS = docker run --rm \
--network $(NETWORK_NAME) \
-v $(PWD)/test/sqlite:/tmp/testsqlite/:ro \
$(SYNCDBDOCS_IMAGE) \
-h /tmp/testsqlite/$(SQLITE_FILE) \
-d $(DB_NAME)
test-sqlite:
$(SQLITE_RUN_SYNCDBDOCS) -format=text > /tmp/dbtest.result
diff $(PWD)/test/sqlite/dbtest-from-scratch.expected.txt /tmp/dbtest.result || (echo "SQLITE Test001.txt failed" && false)