58 |
58 |
$(MAKE) $*
|
59 |
59 |
# re-run make so that cache of existing files is reset
|
60 |
60 |
|
61 |
|
##### Subdir forwarding
|
62 |
|
|
63 |
|
define subdirTargets
|
64 |
|
$(subdir): _always
|
65 |
|
+$$(subMake)
|
66 |
|
|
67 |
|
$(subdir)%: _always
|
68 |
|
+$$(subMake)
|
69 |
|
.PRECIOUS: $(subdir)% # let subdir's Makefile decide whether to delete on error
|
70 |
|
endef
|
71 |
|
$(foreach subdir,$(wildcard */),$(eval $(subdirTargets)))
|
72 |
|
|
73 |
|
Makefile: ;
|
74 |
|
|
75 |
|
%: $(addsuffix %,$(dir $(shell echo */Makefile))) _always ;
|
76 |
|
|
77 |
61 |
##### Installation
|
78 |
62 |
|
79 |
63 |
install: _always core mysql inputs/install test
|
... | ... | |
167 |
151 |
|
168 |
152 |
##### VegBIEN DB
|
169 |
153 |
|
170 |
|
db: schemas/vegbien.sql _always
|
|
154 |
#### DB and bien user
|
|
155 |
|
|
156 |
confirmRmDb = $(call confirm,WARNING:\
|
|
157 |
This will delete your VegBIEN DB if it exists! Continue?)
|
|
158 |
rmPublicSchema := 'DROP SCHEMA IF EXISTS public CASCADE;'
|
|
159 |
|
|
160 |
db: mk_db schemas/install _always ;
|
|
161 |
|
|
162 |
mk_db: _always
|
|
163 |
@$(confirmRmDb)
|
171 |
164 |
-echo "CREATE USER bien PASSWORD '$(bienPassword)';"|$(psqlAsAdmin)
|
172 |
165 |
-echo "CREATE DATABASE vegbien WITH OWNER bien TEMPLATE template0 \
|
173 |
166 |
ENCODING 'UTF8' LC_COLLATE 'en_US.UTF-8' LC_CTYPE 'en_US.UTF-8';"|$(psqlAsAdmin)
|
174 |
|
<$< bin/db_dump_localize|$(psqlAsBien)
|
|
167 |
echo $(rmPublicSchema)|env $(psqlAsAdmin) vegbien
|
175 |
168 |
# ignore errors if user or database exists
|
|
169 |
# drop public schema *as admin* because it starts out owned by postgres
|
176 |
170 |
|
177 |
|
confirmRmDb = $(call confirm,WARNING: This will delete your VegBIEN DB!\
|
178 |
|
Continue?)
|
179 |
|
|
180 |
171 |
rm_db: _always
|
181 |
172 |
@$(confirmRmDb)
|
182 |
173 |
echo "DROP DATABASE IF EXISTS vegbien;"|$(psqlAsAdmin)
|
... | ... | |
184 |
175 |
|
185 |
176 |
reinstall_db: _always rm_db db ;
|
186 |
177 |
|
|
178 |
#### public schema
|
|
179 |
|
|
180 |
schemas/install: schemas/vegbien.sql _always
|
|
181 |
-echo "CREATE SCHEMA public;"|$(psqlAsBien)
|
|
182 |
<$< bin/db_dump_localize|$(psqlAsBien)
|
|
183 |
# ignore errors if schema exists
|
|
184 |
# public schema will be owned by bien
|
|
185 |
|
|
186 |
schemas/uninstall: _always
|
|
187 |
@$(confirmRmDb)
|
|
188 |
echo $(rmPublicSchema)|$(psqlAsBien)
|
|
189 |
|
187 |
190 |
empty_db: _always schemas/vegbien_empty.sql
|
188 |
191 |
@$(confirmRmDb)
|
189 |
192 |
$(psqlAsBien) <schemas/vegbien_empty.sql
|
... | ... | |
260 |
263 |
|
261 |
264 |
test-all: _always remake test missing_mappings
|
262 |
265 |
@$(done)
|
|
266 |
|
|
267 |
##### Subdir forwarding
|
|
268 |
|
|
269 |
# Must come last so overridden targets are not forwarded
|
|
270 |
|
|
271 |
define subdirTargets
|
|
272 |
$(subdir): _always
|
|
273 |
+$$(subMake)
|
|
274 |
|
|
275 |
$(subdir)%: _always
|
|
276 |
+$$(subMake)
|
|
277 |
.PRECIOUS: $(subdir)% # let subdir's Makefile decide whether to delete on error
|
|
278 |
|
|
279 |
$(subdir)reinstall: _always $(subdir)uninstall $(subdir)install ;
|
|
280 |
endef
|
|
281 |
$(foreach subdir,$(wildcard */),$(eval $(subdirTargets)))
|
|
282 |
|
|
283 |
Makefile: ;
|
|
284 |
|
|
285 |
%: $(addsuffix %,$(dir $(shell echo */Makefile))) _always ;
|
main Makefile: VegBIEN DB: Install public schema in a separate step, so that it can be dropped without dropping the entire DB (which also contains staging tables that shouldn't be dropped when there is a schema change). Added schemas/install, schemas/uninstall, implicit schemas/reinstall to manage the public schema separately from the rest of the DB. Moved Subdir forwarding to the bottom so overridden targets are not forwarded. README.TXT: Since `make reinstall_db` would drop the entire DB, tell user to run new `make schemas/reinstall` instead to reinstall (main) DB from schema.