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 |
9074
|
aaronmk
|
map_table()
|
28 |
8161
|
aaronmk
|
{
|
29 |
9838
|
aaronmk
|
echo_func; set_make_vars
|
30 |
9386
|
aaronmk
|
table_make map.csv
|
31 |
8214
|
aaronmk
|
psql <<EOF
|
32 |
8191
|
aaronmk
|
SELECT util.reset_map_table('pg_temp.map');
|
33 |
8161
|
aaronmk
|
\copy pg_temp.map FROM 'map.csv' CSV HEADER;
|
34 |
8191
|
aaronmk
|
SELECT util.set_col_names('"$table"', 'pg_temp.map'::regclass);
|
35 |
8161
|
aaronmk
|
EOF
|
36 |
|
|
}
|
37 |
8198
|
aaronmk
|
|
38 |
9838
|
aaronmk
|
mk_derived()
|
39 |
|
|
{ echo_func; set_make_vars; "$root_dir"/schemas/VegCore/mk_derived; }
|
40 |
8245
|
aaronmk
|
|
41 |
9074
|
aaronmk
|
remake_VegBIEN_mappings()
|
42 |
8245
|
aaronmk
|
{
|
43 |
9838
|
aaronmk
|
echo_func; set_make_vars
|
44 |
9047
|
aaronmk
|
public_schema_exists || return 0
|
45 |
9169
|
aaronmk
|
rm header.csv map.csv # remake them
|
46 |
9386
|
aaronmk
|
yes|table_make test
|
47 |
8245
|
aaronmk
|
}
|
48 |
8273
|
aaronmk
|
|
49 |
9074
|
aaronmk
|
postprocess() # overridable
|
50 |
8273
|
aaronmk
|
{
|
51 |
9838
|
aaronmk
|
echo_func; set_make_vars
|
52 |
8273
|
aaronmk
|
local file="$top_dir"/postprocess.sql
|
53 |
|
|
if test -e "$file"; then psql "$@"; fi
|
54 |
|
|
}
|
55 |
|
|
|
56 |
9836
|
aaronmk
|
install_log="$top_dir"/logs/install.log.sql
|
57 |
|
|
|
58 |
|
|
load_data()
|
59 |
9392
|
aaronmk
|
{
|
60 |
9838
|
aaronmk
|
echo_func; set_make_vars
|
61 |
9847
|
aaronmk
|
local verbosity_min= # install logs require default verbosity
|
62 |
9839
|
aaronmk
|
set -- table_make ${_remake:+re}install # just the table
|
63 |
9837
|
aaronmk
|
if remaking || test ! -e "$install_log"; then "$@" # OK to clobber log
|
64 |
|
|
else benign_error=1 noclobber=1 "$@" || true
|
65 |
9836
|
aaronmk
|
fi
|
66 |
9392
|
aaronmk
|
}
|
67 |
|
|
|
68 |
9074
|
aaronmk
|
import()
|
69 |
8273
|
aaronmk
|
{
|
70 |
9838
|
aaronmk
|
echo_func; set_make_vars
|
71 |
9841
|
aaronmk
|
self_make load_data
|
72 |
8282
|
aaronmk
|
map_table
|
73 |
|
|
postprocess
|
74 |
|
|
mk_derived
|
75 |
8273
|
aaronmk
|
}
|
76 |
8705
|
aaronmk
|
|
77 |
|
|
fi
|