Project

General

Profile

1 225 aaronmk
export PGOPTIONS = --client-min-messages=WARNING
2
3
psqlOpts = --set ON_ERROR_STOP=1 --quiet
4 227 aaronmk
asAdmin = sudo -u postgres
5
psqlAdmin = $(asAdmin) psql $(psqlOpts)
6 225 aaronmk
psqlDbUser = ./util/psql_vegbien $(psqlOpts)
7
8 149 aaronmk
9 228 aaronmk
all: FORCE install
10
11 225 aaronmk
.SUFFIXES:
12
13 202 aaronmk
FORCE:
14 225 aaronmk
.PHONY: FORCE
15 202 aaronmk
16
17 228 aaronmk
install: FORCE user db
18 202 aaronmk
19 228 aaronmk
uninstall: FORCE rm_db rm_user
20 202 aaronmk
21 228 aaronmk
reinstall: FORCE uninstall install
22 225 aaronmk
23 228 aaronmk
reinstall_db: FORCE rm_db db
24 202 aaronmk
25 228 aaronmk
empty_db: FORCE
26 225 aaronmk
	$(psqlDbUser) <../mappings/schemas/vegbien_empty.sql
27 202 aaronmk
28
user: FORCE
29 228 aaronmk
	$(MAKE) _$@
30
31
ifeq ($(MAKECMDGOALS),_user)
32 230 aaronmk
include util/vegbien_dest
33 228 aaronmk
endif
34
35
_user: FORCE
36 229 aaronmk
	@echo "At sudo password prompt, enter *your* password"
37 227 aaronmk
	@sudo -v
38 228 aaronmk
	@echo "At prompt \"Enter password for new role:\", enter $(out_password)"
39
	-$(_user_cmd)
40 202 aaronmk
# ignore errors about existing user
41 228 aaronmk
_user_cmd = $(asAdmin) createuser --no-superuser --no-createdb --no-createrole \
42
--pwprompt "$(out_user)"
43 202 aaronmk
44
rm_user: FORCE
45 225 aaronmk
	echo "DROP USER bien;"|$(psqlAdmin)
46 202 aaronmk
47
db: FORCE
48 225 aaronmk
	$(psqlAdmin) <../mappings/schemas/vegbien.sql
49 202 aaronmk
50
rm_db: FORCE
51 225 aaronmk
	echo "DROP DATABASE vegbien;"|$(psqlAdmin)
52 202 aaronmk
53
54 176 aaronmk
test: test-map
55 149 aaronmk
56 176 aaronmk
test-%: FORCE
57
	./test/$(*F)