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
|
self_make import__table_run "$@"
|
13
|
after_import_cmds
|
14
|
}
|
15
|
fi ####
|
16
|
|
17
|
. "$(dirname "${BASH_SOURCE[0]}")"/import.run
|
18
|
.rel subdir.run
|
19
|
.rel ../sh/db_make.sh
|
20
|
|
21
|
if self_not_included; then
|
22
|
|
23
|
: "${table=$subdir}"; export table
|
24
|
|
25
|
table_make() { subdir_make "$@"; }
|
26
|
|
27
|
install_log_rel=logs/install.log.sql
|
28
|
|
29
|
table_make_install()
|
30
|
{
|
31
|
echo_func; local install_log="${install_log-$top_dir/$install_log_rel}"
|
32
|
local verbosity_min= # install logs require default verbosity
|
33
|
set -- table_make "$@"
|
34
|
if remaking || test ! -e "$install_log"; then "$@" # OK to clobber log
|
35
|
else benign_error=1 noclobber=1 "$@" || true
|
36
|
fi
|
37
|
}
|
38
|
|
39
|
datasrc_make_install()
|
40
|
{
|
41
|
echo_func
|
42
|
subdir=. install_log="$top_dir/../$install_log_rel" table_make_install "$@"
|
43
|
}
|
44
|
|
45
|
map_table()
|
46
|
{
|
47
|
echo_func; set_make_vars
|
48
|
table_make map.csv
|
49
|
psql <<EOF
|
50
|
SELECT util.reset_map_table('pg_temp.map');
|
51
|
\copy pg_temp.map FROM 'map.csv' CSV HEADER;
|
52
|
SELECT util.set_col_names('"$table"', 'pg_temp.map'::regclass);
|
53
|
EOF
|
54
|
}
|
55
|
|
56
|
mk_derived()
|
57
|
{ echo_func; set_make_vars; "$root_dir"/schemas/VegCore/mk_derived; }
|
58
|
|
59
|
remake_VegBIEN_mappings()
|
60
|
{
|
61
|
echo_func; set_make_vars
|
62
|
public_schema_exists || return 0
|
63
|
rm header.csv map.csv # remake them
|
64
|
yes|table_make test
|
65
|
}
|
66
|
|
67
|
postprocess() # overridable
|
68
|
{
|
69
|
echo_func; set_make_vars
|
70
|
local file="$top_dir"/postprocess.sql
|
71
|
if test -e "$file"; then psql "$@"; fi
|
72
|
}
|
73
|
|
74
|
load_data()
|
75
|
{
|
76
|
echo_func; set_make_vars
|
77
|
datasrc_make_install schema
|
78
|
table_make_install ${_remake:+re}install # just the table
|
79
|
}
|
80
|
|
81
|
import()
|
82
|
{
|
83
|
echo_func; set_make_vars
|
84
|
self_make load_data
|
85
|
map_table
|
86
|
postprocess
|
87
|
mk_derived
|
88
|
}
|
89
|
|
90
|
fi
|