Project

General

Profile

« Previous | Next » 

Revision 6186

input.Makefile: $(psqlAsBien), csv2db: Turn off the automatic search_path where needed, because when the input is installed, the schemas in it may not exist yet

View differences:

inputs/input.Makefile
58 58
selfMap = $(bin)/cols 0 0
59 59
psqlOpts := --set ON_ERROR_STOP=1 --quiet
60 60
psqlAsBien := $(bin)/psql_vegbien $(psqlOpts)
61
searchPath := $(datasrc),$(shell prefix=; . $(bin)/vegbien_dest;\
62
echo "$$schemas")
63
searchPath := "$(subst $(comma),"$(comma)",$(searchPath))"
61
psqlNoSearchPath := env no_search_path=1 $(psqlAsBien)
64 62
# Usage: ($(inDatasrc); cat $(file))|$(psqlCmd)
65
inDatasrc := echo 'SET search_path TO $(searchPath);'
63
inDatasrc := echo 'SET search_path TO "$(datasrc)";'
66 64

  
67 65
# SVN
68 66
addDir = $(if $(wildcard $(1)/),svn add --depth=empty $(1),svn mkdir $(1))
......
203 201
TNRS cache!,To save it: make backups/TNRS.backup-remake))
204 202

  
205 203
schema: _always
206
	-echo 'CREATE SCHEMA "$(datasrc)";'|$(psqlAsBien)
204
	-echo 'CREATE SCHEMA "$(datasrc)";'|$(psqlNoSearchPath)
207 205
# ignore errors if schema exists
208 206

  
209 207
rm_schema: _always
210
	echo 'DROP SCHEMA IF EXISTS "$(datasrc)" CASCADE;'|$(psqlAsBien)
208
	echo 'DROP SCHEMA IF EXISTS "$(datasrc)" CASCADE;'|$(psqlNoSearchPath)
211 209

  
212 210
installLog := logs/install.log.sql
213 211

  
......
219 217

  
220 218
# Must come before %/install to override it
221 219
sql/install: $(dbExports)
222
	($(inDatasrc); cat $+|pg_dump_limit)|"time" $(psqlAsBien) \
220
	($(inDatasrc); cat $+|pg_dump_limit)|"time" $(psqlNoSearchPath) \
223 221
--set=schema='"$(datasrc)"' $(logInstallRoot)
224 222

  
225 223
# Must come before `%.sql: _MySQL/%.sql` to override it
......
239 237
	$(if $(wildcard $@),,$(bin)/my2pg <$< >$@)
240 238

  
241 239
cleanup = $(if $(wildcard $*/cleanup.sql),($(inDatasrc); cat $*/cleanup.sql)\
242
|"time" $(psqlAsBien) --echo-all --set=table='"$*"' $(logInstall*Add),\
243
(prefix=; . $(bin)/vegbien_dest; env schema=$(datasrc) table=$* $(bin)/csv2db)\
244
$(logInstall*Add))
240
|"time" $(psqlNoSearchPath) --echo-all --set=table='"$*"' $(logInstall*Add),\
241
(prefix=; . $(bin)/vegbien_dest; unset schemas; env schema=$(datasrc) table=$*\
242
$(bin)/csv2db) $(logInstall*Add))
245 243

  
246 244
define exportHeader
247 245
$(cleanup)
248
echo 'SELECT * FROM "$(datasrc)"."$*" LIMIT 0;'|$(psqlAsBien) \
246
echo 'SELECT * FROM "$(datasrc)"."$*" LIMIT 0;'|$(psqlNoSearchPath) \
249 247
--no-align --field-separator=, --pset=footer=off >$*/header.csv
250 248
endef
251 249

  
252 250
# For staging tables which are derived by joining together other staging tables.
253 251
%/install %/header.csv: %/create.sql _always
254 252
	($(inDatasrc); echo 'CREATE TABLE "$*" AS'; cat $<; echo ';')|"time" \
255
$(psqlAsBien) --echo-all --set=schema='"$(datasrc)"' --set=table='"$*"' \
253
$(psqlNoSearchPath) --echo-all --set=schema='"$(datasrc)"' --set=table='"$*"' \
256 254
$(logInstall*)
257 255
	$(exportHeader)
258 256
.PRECIOUS: %/header.csv
......
260 258
%/install: _always
261 259
	$(if $(isRef),$(exportHeader),$(if $(nonXml),$(import_install_)))
262 260
	$(if $(wildcard $*/postprocess.sql),($(inDatasrc); cat $*/postprocess.sql;)\
263
|"time" $(psqlAsBien) --echo-all --set=table='"$*"' $(logInstall*Add))
261
|"time" $(psqlNoSearchPath) --echo-all --set=table='"$*"' $(logInstall*Add))
264 262
define import_install_
265
(prefix=; . $(bin)/vegbien_dest; "time" nice -n +5\
263
(prefix=; . $(bin)/vegbien_dest; unset schemas; "time" nice -n +5\
266 264
env schema=$(datasrc) table=$* $(bin)/csv2db $(catSrcs) $(logInstall*))
267 265
$(if $(filter $(srcTable),$*),($(inDatasrc);\
268 266
echo 'ALTER TABLE "$(datasrc)"."$*" RENAME row_num TO "$*.row_num";')|"time"\
269
$(psqlAsBien) --echo-all --set=table='"$*"' $(logInstall*Add))
267
$(psqlNoSearchPath) --echo-all --set=table='"$*"' $(logInstall*Add))
270 268
endef
271 269
# table-scope src table's row_num col to allow joining it with other tables
272 270

  
273 271
%/uninstall: _always
274
	echo 'DROP TABLE IF EXISTS "$(datasrc)"."$*" CASCADE;'|$(psqlAsBien)
272
	echo 'DROP TABLE IF EXISTS "$(datasrc)"."$*" CASCADE;'|$(psqlNoSearchPath)
275 273

  
276 274
%/reinstall: _always %/uninstall %/install ;
277 275

  
......
400 398
# don't run if verify/%.out's default do-nothing action was used
401 399
# can't use $(wildcard) because it won't recheck file after verify/%.out is run
402 400

  
403
psqlExport := "time" $(psqlAsBien) --no-align --field-separator=$$'\t'\
401
psqlExport := "time" $(psqlNoSearchPath) --no-align --field-separator=$$'\t'\
404 402
--pset=footer=off --pset=null=NULL
405 403
# Note that using $(inDatasrc) will not work with datasources whose tables are
406 404
# the same name as VegBIEN tables (likely only VegBank), because the datasource

Also available in: Unified diff