This repository has been archived by the owner on Aug 9, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Makefile
194 lines (161 loc) · 5.72 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
# Minimal script to install the SQL creation scripts ready for postinst script.
VERSION=1.14.0
REVISION = $(shell test -d .git && git describe --always || echo $(VERSION))
TEST_DATABASE = regress_linz_bde_schema
datadir=${DESTDIR}/usr/share/linz-bde-schema
bindir=${DESTDIR}/usr/bin
#
# Uncoment these line to support testing via pg_regress
#
SQLSCRIPTS = \
sql/01-bde_roles.sql \
sql/02-bde_schema.sql \
sql/03-bde_functions.sql \
sql/04-bde_schema_index.sql \
sql/05-bde_version.sql \
sql/99-patches.sql \
sql/versioning/01-version_tables.sql
SCRIPTS_built = \
scripts/linz-bde-schema-load \
scripts/linz-bde-schema-publish
TEST_SCRIPTS = \
test/base.pg
EXTRA_CLEAN = \
sql/05-bde_version.sql \
sql/03-bde_functions.sql \
$(SCRIPTS_built)
.dummy:
# Need install to depend on something for debuild
all: $(SQLSCRIPTS) $(SCRIPTS_built)
%.sql: %.sql.in Makefile
sed -e 's/@@VERSION@@/$(VERSION)/;s|@@REVISION@@|$(REVISION)|' $< > $@
scripts/linz-bde-schema-load: scripts/linz-bde-schema-load.bash
sed -e 's/@@VERSION@@/$(VERSION)/;s|@@REVISION@@|$(REVISION)|' $< > $@
chmod +x $@
scripts/linz-bde-schema-publish: scripts/linz-bde-schema-publish.bash
sed -e 's/@@VERSION@@/$(VERSION)/;s|@@REVISION@@|$(REVISION)|' $< > $@
chmod +x $@
install: $(SQLSCRIPTS) $(SCRIPTS_built)
mkdir -p ${datadir}/sql
cp sql/*.sql ${datadir}/sql
mkdir -p ${datadir}/sql/versioning
cp sql/versioning/*.sql ${datadir}/sql/versioning
mkdir -p ${bindir}
cp $(SCRIPTS_built) ${bindir}
installcheck: check-loader
# Check an already prepared database
# It is expected that the prepared database
# is set via PGDATABASE
#
check-prepared:
V=`psql -XtAc 'select bde.bde_version()'` && \
echo $$V && test "$$V" = "$(VERSION)"
mkdir -p test-prepared/ && \
sed '/\\i sql/d' test/base.pg | \
sed '/-- Switch to unprivileged role/,/^END /d' | \
sed '/-- Cleanup/,/^END /d' \
> test-prepared/base.pg && \
pg_prove test-prepared/
check-publisher:
V=`linz-bde-schema-publish --version` && \
echo $$V && test `echo "$$V" | awk '{print $$1}'` = "$(VERSION)"
test/test-publication.bash
check-loader:
V=`linz-bde-schema-load --version` && \
echo $$V && test `echo "$$V" | awk '{print $$1}'` = "$(VERSION)"
dropdb --if-exists $(TEST_DATABASE)
createdb $(TEST_DATABASE)
linz-bde-schema-load $(TEST_DATABASE)
linz-bde-schema-load $(TEST_DATABASE)
export PGDATABASE=$(TEST_DATABASE); \
$(MAKE) check-prepared
dropdb $(TEST_DATABASE)
createdb $(TEST_DATABASE)
linz-bde-schema-load --noextension $(TEST_DATABASE)
linz-bde-schema-load --noextension $(TEST_DATABASE)
export PGDATABASE=$(TEST_DATABASE); \
$(MAKE) check-prepared
dropdb $(TEST_DATABASE)
createdb $(TEST_DATABASE)
linz-bde-schema-load --revision $(TEST_DATABASE)
linz-bde-schema-load --revision $(TEST_DATABASE)
export PGDATABASE=$(TEST_DATABASE); \
$(MAKE) check-prepared
dropdb $(TEST_DATABASE)
check-loader-stdout:
dropdb --if-exists $(TEST_DATABASE)
createdb $(TEST_DATABASE)
linz-bde-schema-load - | \
psql --set ON_ERROR_STOP=1 -Xo /dev/null $(TEST_DATABASE)
linz-bde-schema-load - | \
psql --set ON_ERROR_STOP=1 -Xo /dev/null $(TEST_DATABASE)
export PGDATABASE=$(TEST_DATABASE); \
$(MAKE) check-prepared
dropdb $(TEST_DATABASE)
createdb $(TEST_DATABASE)
linz-bde-schema-load --noextension - | \
psql --set ON_ERROR_STOP=1 -Xo /dev/null $(TEST_DATABASE)
linz-bde-schema-load --noextension - | \
psql --set ON_ERROR_STOP=1 -Xo /dev/null $(TEST_DATABASE)
export PGDATABASE=$(TEST_DATABASE); \
$(MAKE) check-prepared
dropdb $(TEST_DATABASE)
createdb $(TEST_DATABASE)
linz-bde-schema-load --revision - | \
psql --set ON_ERROR_STOP=1 -Xo /dev/null $(TEST_DATABASE)
linz-bde-schema-load --revision - | \
psql --set ON_ERROR_STOP=1 -Xo /dev/null $(TEST_DATABASE)
export PGDATABASE=$(TEST_DATABASE); \
$(MAKE) check-prepared
dropdb $(TEST_DATABASE)
uninstall:
rm -rf ${datadir}
check test: $(SQLSCRIPTS) $(TEST_SCRIPTS)
export PGDATABASE=$(TEST_DATABASE); \
dropdb --if-exists $$PGDATABASE; \
createdb $$PGDATABASE; \
pg_prove test/;
# Test with versioning after patches
export PGDATABASE=$(TEST_DATABASE); \
dropdb --if-exists $$PGDATABASE && \
createdb $$PGDATABASE && \
mkdir -p test-versioned/ && \
sed 's/^--VERSIONED-- //' test/base.pg > test-versioned/base.pg && \
table_version-loader $$PGDATABASE && \
pg_prove test-versioned/
# Test with versioning after patches and table_version
# installed NOT as an extension
export PGDATABASE=$(TEST_DATABASE); \
dropdb --if-exists $$PGDATABASE && \
createdb $$PGDATABASE && \
mkdir -p test-versioned/ && \
sed 's/^--VERSIONED-- //' test/base.pg > test-versioned/base.pg && \
table_version-loader --no-extension $$PGDATABASE && \
pg_prove test-versioned/
# Test with versioning before patches (the sed line swaps
# order of 99-patches.sql and version_tables.sql files)
export PGDATABASE=$(TEST_DATABASE); \
dropdb --if-exists $$PGDATABASE && \
createdb $$PGDATABASE && \
mkdir -p test-versioned/ && \
sed 's/^--VERSIONED-- //' test/base.pg | \
sed -n '/99-patches/ { h; :a; n; /version_tables.sql/ { p; x } }; p' \
> test-versioned/base.pg && \
table_version-loader $$PGDATABASE && \
pg_prove test-versioned/
# Test with versioning before patches and table_version
# installed NOT as an extension
export PGDATABASE=$(TEST_DATABASE); \
dropdb --if-exists $$PGDATABASE && \
createdb $$PGDATABASE && \
mkdir -p test-versioned/ && \
sed 's/^--VERSIONED-- //' test/base.pg | \
sed -n '/99-patches/ { h; :a; n; /version_tables.sql/ { p; x } }; p' \
> test-versioned/base.pg && \
table_version-loader --no-extension $$PGDATABASE && \
pg_prove test-versioned/
clean:
rm -f regression.diffs
rm -f regression.out
rm -rf results
rm -f $(EXTRA_CLEAN)