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 |
9681
|
aaronmk
|
self_make 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 |
9854
|
aaronmk
|
.rel subdir.run
|
19 |
|
|
.rel ../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 |
9935
|
aaronmk
|
install_log_rel=logs/install.log.sql
|
28 |
|
|
|
29 |
9934
|
aaronmk
|
table_make_install()
|
30 |
|
|
{
|
31 |
9935
|
aaronmk
|
echo_func; local install_log="${install_log-$top_dir/$install_log_rel}"
|
32 |
9934
|
aaronmk
|
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 |
9936
|
aaronmk
|
datasrc_make_install()
|
40 |
|
|
{
|
41 |
|
|
echo_func
|
42 |
|
|
subdir=. install_log="$top_dir/../$install_log_rel" table_make_install "$@"
|
43 |
|
|
}
|
44 |
|
|
|
45 |
9074
|
aaronmk
|
map_table()
|
46 |
8161
|
aaronmk
|
{
|
47 |
9838
|
aaronmk
|
echo_func; set_make_vars
|
48 |
9386
|
aaronmk
|
table_make map.csv
|
49 |
8214
|
aaronmk
|
psql <<EOF
|
50 |
8191
|
aaronmk
|
SELECT util.reset_map_table('pg_temp.map');
|
51 |
8161
|
aaronmk
|
\copy pg_temp.map FROM 'map.csv' CSV HEADER;
|
52 |
8191
|
aaronmk
|
SELECT util.set_col_names('"$table"', 'pg_temp.map'::regclass);
|
53 |
8161
|
aaronmk
|
EOF
|
54 |
|
|
}
|
55 |
8198
|
aaronmk
|
|
56 |
9838
|
aaronmk
|
mk_derived()
|
57 |
|
|
{ echo_func; set_make_vars; "$root_dir"/schemas/VegCore/mk_derived; }
|
58 |
8245
|
aaronmk
|
|
59 |
9074
|
aaronmk
|
remake_VegBIEN_mappings()
|
60 |
8245
|
aaronmk
|
{
|
61 |
9838
|
aaronmk
|
echo_func; set_make_vars
|
62 |
9047
|
aaronmk
|
public_schema_exists || return 0
|
63 |
9946
|
aaronmk
|
if remaking; then in_top_dir rm header.csv map.csv; fi # remake them
|
64 |
9386
|
aaronmk
|
yes|table_make test
|
65 |
8245
|
aaronmk
|
}
|
66 |
8273
|
aaronmk
|
|
67 |
9074
|
aaronmk
|
postprocess() # overridable
|
68 |
8273
|
aaronmk
|
{
|
69 |
9838
|
aaronmk
|
echo_func; set_make_vars
|
70 |
8273
|
aaronmk
|
local file="$top_dir"/postprocess.sql
|
71 |
|
|
if test -e "$file"; then psql "$@"; fi
|
72 |
|
|
}
|
73 |
|
|
|
74 |
9836
|
aaronmk
|
load_data()
|
75 |
9392
|
aaronmk
|
{
|
76 |
9838
|
aaronmk
|
echo_func; set_make_vars
|
77 |
9937
|
aaronmk
|
datasrc_make_install schema
|
78 |
9934
|
aaronmk
|
table_make_install ${_remake:+re}install # just the table
|
79 |
9392
|
aaronmk
|
}
|
80 |
|
|
|
81 |
9074
|
aaronmk
|
import()
|
82 |
8273
|
aaronmk
|
{
|
83 |
9838
|
aaronmk
|
echo_func; set_make_vars
|
84 |
9841
|
aaronmk
|
self_make load_data
|
85 |
8282
|
aaronmk
|
map_table
|
86 |
|
|
postprocess
|
87 |
9947
|
aaronmk
|
remake_VegBIEN_mappings
|
88 |
8282
|
aaronmk
|
mk_derived
|
89 |
8273
|
aaronmk
|
}
|
90 |
8705
|
aaronmk
|
|
91 |
|
|
fi
|