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