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 8273 aaronmk
: "${schema="$(cd "$top_dir"/..; basename "$PWD")"}"
23 8696 aaronmk
mk_esc_name schema
24 8273 aaronmk
: "${table="$( cd "$top_dir"   ; basename "$PWD")"}"
25 8696 aaronmk
mk_esc_name table
26 8195 aaronmk
export schema table
27 8161 aaronmk
28 9074 aaronmk
input_make()
29 8242 aaronmk
{
30 8881 aaronmk
	echo_func
31 9075 aaronmk
	command make --directory="$top_dir"/.. "${@/#/$table/}"
32 8242 aaronmk
}
33
34 9074 aaronmk
map_table()
35 8161 aaronmk
{
36 8881 aaronmk
	echo_func
37 8273 aaronmk
	input_make map.csv
38 8214 aaronmk
	psql <<EOF
39 8191 aaronmk
SELECT util.reset_map_table('pg_temp.map');
40 8161 aaronmk
\copy pg_temp.map FROM 'map.csv' CSV HEADER;
41 8191 aaronmk
SELECT util.set_col_names('"$table"', 'pg_temp.map'::regclass);
42 8161 aaronmk
EOF
43
}
44 8198 aaronmk
45 9074 aaronmk
mk_derived()
46 8282 aaronmk
{
47 8881 aaronmk
	echo_func
48 8282 aaronmk
	"$root_dir"/schemas/VegCore/mk_derived
49
}
50 8245 aaronmk
51 9074 aaronmk
remake_VegBIEN_mappings()
52 8245 aaronmk
{
53 8881 aaronmk
	echo_func
54 9047 aaronmk
	public_schema_exists || return 0
55 8277 aaronmk
	echo_run rm header.csv map.csv # remake them
56 8273 aaronmk
	yes|input_make test
57 8245 aaronmk
}
58 8273 aaronmk
59 9074 aaronmk
postprocess() # overridable
60 8273 aaronmk
{
61 8881 aaronmk
	echo_func
62 8273 aaronmk
	local file="$top_dir"/postprocess.sql
63
	if test -e "$file"; then psql "$@"; fi
64
}
65
66 9074 aaronmk
import()
67 8273 aaronmk
{
68 8881 aaronmk
	echo_func
69 8282 aaronmk
	map_table
70
	postprocess
71
	mk_derived
72 8273 aaronmk
}
73 8705 aaronmk
74
fi