Project

General

Profile

1 8291 aaronmk
#!/bin/bash -e
2 8273 aaronmk
3
if false; then #### run script template:
4 8291 aaronmk
#!/bin/bash -e
5 8273 aaronmk
. "$(dirname "${BASH_SOURCE[0]}")"/path/to/table.run
6 8161 aaronmk
7 9039 aaronmk
func_override import__table_run
8 9074 aaronmk
import()
9 8273 aaronmk
{
10 8881 aaronmk
	echo_func
11 8273 aaronmk
	before_import_cmds
12 9039 aaronmk
	import__table_run "$@"
13 8273 aaronmk
	after_import_cmds
14
}
15
fi ####
16 8213 aaronmk
17 8296 aaronmk
. "$(dirname "${BASH_SOURCE[0]}")"/import.run
18 9013 aaronmk
. "$(dirname "${BASH_SOURCE[0]}")"/../sh/local.sh
19 8273 aaronmk
20 8705 aaronmk
if self_not_included; then
21
22 9394 aaronmk
: "${schema="$(log+ 2 cd "$top_dir"/..; basename "$PWD")"}"
23
: "${table="$( log+ 2 cd "$top_dir"   ; basename "$PWD")"}"
24 8195 aaronmk
export schema table
25 8161 aaronmk
26 9386 aaronmk
table_make() # usage: [silent=1] table_make target...
27 9355 aaronmk
# requires Makefile in datasrc dir with `include ../input.Makefile`
28 9386 aaronmk
# target names are relative to the table subdir itself, not the datasrc dir
29 9355 aaronmk
{
30
	echo_func; kw_params silent
31 9388 aaronmk
	make --directory="$(canon_rel_path "$top_dir"/..)" ${silent:+--silent }\
32
"${@/#/$table/}"
33 9387 aaronmk
	# "${@/#/$table/}": replaces empty str at beginning of str (/#) with $table/
34 9355 aaronmk
}
35 8242 aaronmk
36 9074 aaronmk
map_table()
37 8161 aaronmk
{
38 8881 aaronmk
	echo_func
39 9386 aaronmk
	table_make map.csv
40 8214 aaronmk
	psql <<EOF
41 8191 aaronmk
SELECT util.reset_map_table('pg_temp.map');
42 8161 aaronmk
\copy pg_temp.map FROM 'map.csv' CSV HEADER;
43 8191 aaronmk
SELECT util.set_col_names('"$table"', 'pg_temp.map'::regclass);
44 8161 aaronmk
EOF
45
}
46 8198 aaronmk
47 9350 aaronmk
mk_derived() { echo_func; "$root_dir"/schemas/VegCore/mk_derived; }
48 8245 aaronmk
49 9074 aaronmk
remake_VegBIEN_mappings()
50 8245 aaronmk
{
51 8881 aaronmk
	echo_func
52 9047 aaronmk
	public_schema_exists || return 0
53 9169 aaronmk
	rm header.csv map.csv # remake them
54 9386 aaronmk
	yes|table_make test
55 8245 aaronmk
}
56 8273 aaronmk
57 9074 aaronmk
postprocess() # overridable
58 8273 aaronmk
{
59 8881 aaronmk
	echo_func
60 8273 aaronmk
	local file="$top_dir"/postprocess.sql
61
	if test -e "$file"; then psql "$@"; fi
62
}
63
64 9392 aaronmk
load_data()
65
{
66
	echo_func
67 9408 aaronmk
	verbosity_min=3 table_make ${remake:+re}install # just the table
68
		# install logs require verbose output
69 9392 aaronmk
}
70
71 9074 aaronmk
import()
72 8273 aaronmk
{
73 8881 aaronmk
	echo_func
74 9392 aaronmk
	load_data
75 8282 aaronmk
	map_table
76
	postprocess
77
	mk_derived
78 8273 aaronmk
}
79 8705 aaronmk
80
fi