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