Project

General

Profile

« Previous | Next » 

Revision 1745

root Makefile: rm_db: Confirm deletion with user. Merged postgres_user, rm_postgres_user into db, rm_db so that deletion confirmation applies to user deletion as well (which would indirectly cause the DB to be deleted).

View differences:

Makefile
19 19

  
20 20
# User interaction
21 21

  
22
confirm = $(shell read -p $(emph)"$(1) (y/n)"$(endEmph) REPLY; \
23
test "$REPLY" = y && echo t)
22
done = echo; echo $(emph)"Finished $@"$(endEmph); echo
24 23

  
25
getPassword = $(shell read -s -p $(emph)"Enter your $(1) password:"$(endEmph) \
26
REPLY; echo >&2; echo -n "$REPLY")
27

  
28 24
wait := read -p $(emph)'Press ENTER to continue:'$(endEmph) REPLY
29 25

  
30
done = echo; echo $(emph)"Finished $@"$(endEmph); echo
26
confirm = $(shell read -p $(emph)"$(1) (y/n)"$(endEmph) REPLY; \
27
test "$$REPLY" = y && echo t)
31 28

  
32 29
# File editing
33 30
sudoAppend = echo $$'$(2)'|sudo tee -a $(1) >/dev/null
......
162 159
psqlAsBien := bin/psql_vegbien $(psqlOpts)
163 160
bienPassword := $(shell cat config/bien_password)
164 161

  
165
postgres_user: _always
166
	-echo "CREATE USER bien PASSWORD '$(bienPassword)';"|$(psqlAsAdmin)
167
# ignore errors if user exists
168

  
169
rm_postgres_user: _always
170
	echo "DROP USER IF EXISTS bien;"|$(psqlAsAdmin)
171

  
172 162
##### VegBIEN DB
173 163

  
174
db: _always schemas/vegbien.sql
175
	-$($@_create_cmd)
176
	$(psqlAsBien) <schemas/vegbien.sql
177
# ignore errors if database exists
178
db_create_cmd = echo "CREATE DATABASE vegbien OWNER bien ENCODING 'UTF8' \
164
db: schemas/vegbien.sql _always
165
	-echo "CREATE USER bien PASSWORD '$(bienPassword)';"|$(psqlAsAdmin)
166
	-echo "CREATE DATABASE vegbien OWNER bien ENCODING 'UTF8' \
179 167
TEMPLATE template1;"|$(psqlAsAdmin)
168
	$(psqlAsBien) <$<
169
# ignore errors if user or database exists
180 170

  
171
define rmDb
172
echo "DROP DATABASE IF EXISTS vegbien;"|$(psqlAsAdmin)
173
echo "DROP USER IF EXISTS bien;"|$(psqlAsAdmin)
174
endef
175

  
181 176
rm_db: _always
182
	echo "DROP DATABASE IF EXISTS vegbien;"|$(psqlAsAdmin)
177
	$(if $(call confirm,WARNING: This will delete your VegBIEN DB! Continue?),\
178
$(rmDb))
183 179

  
184 180
reinstall_db: _always rm_db db ;
185 181

  

Also available in: Unified diff