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