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 9585 aaronmk
. "$(dirname "${BASH_SOURCE[0]}")"/subdir.run
19 8273 aaronmk
20 8705 aaronmk
if self_not_included; then
21
22 9585 aaronmk
: "${table=$subdir}"; export table
23
24
table_make() { subdir_make "$@"; }
25
26 9074 aaronmk
map_table()
27 8161 aaronmk
{
28 8881 aaronmk
	echo_func
29 9386 aaronmk
	table_make map.csv
30 8214 aaronmk
	psql <<EOF
31 8191 aaronmk
SELECT util.reset_map_table('pg_temp.map');
32 8161 aaronmk
\copy pg_temp.map FROM 'map.csv' CSV HEADER;
33 8191 aaronmk
SELECT util.set_col_names('"$table"', 'pg_temp.map'::regclass);
34 8161 aaronmk
EOF
35
}
36 8198 aaronmk
37 9350 aaronmk
mk_derived() { echo_func; "$root_dir"/schemas/VegCore/mk_derived; }
38 8245 aaronmk
39 9074 aaronmk
remake_VegBIEN_mappings()
40 8245 aaronmk
{
41 8881 aaronmk
	echo_func
42 9047 aaronmk
	public_schema_exists || return 0
43 9169 aaronmk
	rm header.csv map.csv # remake them
44 9386 aaronmk
	yes|table_make test
45 8245 aaronmk
}
46 8273 aaronmk
47 9074 aaronmk
postprocess() # overridable
48 8273 aaronmk
{
49 8881 aaronmk
	echo_func
50 8273 aaronmk
	local file="$top_dir"/postprocess.sql
51
	if test -e "$file"; then psql "$@"; fi
52
}
53
54 9392 aaronmk
load_data()
55
{
56
	echo_func
57 9408 aaronmk
	verbosity_min=3 table_make ${remake:+re}install # just the table
58
		# install logs require verbose output
59 9392 aaronmk
}
60
61 9074 aaronmk
import()
62 8273 aaronmk
{
63 8881 aaronmk
	echo_func
64 9392 aaronmk
	load_data
65 8282 aaronmk
	map_table
66
	postprocess
67
	mk_derived
68 8273 aaronmk
}
69 8705 aaronmk
70
fi