1 |
6461
|
aaronmk
|
#!/bin/bash
|
2 |
4395
|
aaronmk
|
# Creates analytical DB
|
3 |
7864
|
aaronmk
|
# Usage: self [log=]
|
4 |
4395
|
aaronmk
|
|
5 |
|
|
selfDir="$(dirname -- "$0")"
|
6 |
|
|
|
7 |
6459
|
aaronmk
|
. "$selfDir/vegbien_dest"
|
8 |
|
|
|
9 |
7864
|
aaronmk
|
if test -n "${log=1}"; then # $log defaults to 1
|
10 |
|
|
exec >>"$selfDir/../inputs/analytical_db/logs/make_analytical_db.log.sql" 2>&1
|
11 |
|
|
fi
|
12 |
6047
|
aaronmk
|
|
13 |
6054
|
aaronmk
|
(set -x; date)
|
14 |
6048
|
aaronmk
|
|
15 |
7620
|
aaronmk
|
sleep 5 # wait for tnrs.make to acquire the lock if being run right after import
|
16 |
7618
|
aaronmk
|
"$selfDir/waitself" "$selfDir/../inputs/.TNRS/tnrs/tnrs.make"
|
17 |
|
|
|
18 |
9924
|
aaronmk
|
mk_table()
|
19 |
6460
|
aaronmk
|
{
|
20 |
|
|
local table="$1"
|
21 |
9924
|
aaronmk
|
local public_table="\"$public\".$table"
|
22 |
6460
|
aaronmk
|
cat <<EOF
|
23 |
|
|
-- Create $table
|
24 |
6466
|
aaronmk
|
TRUNCATE $public_table;
|
25 |
|
|
INSERT INTO $public_table SELECT * FROM ${public_table}_view;
|
26 |
7061
|
aaronmk
|
ANALYZE $public_table;
|
27 |
9924
|
aaronmk
|
EOF
|
28 |
|
|
}
|
29 |
6460
|
aaronmk
|
|
30 |
7345
|
aaronmk
|
((set -x; "$selfDir/psql_verbose_vegbien") <<EOF
|
31 |
14095
|
aaronmk
|
SELECT iucn_red_list_view_modify();
|
32 |
|
|
|
33 |
9925
|
aaronmk
|
$(mk_table geoscrub_input)
|
34 |
6053
|
aaronmk
|
|
35 |
14093
|
aaronmk
|
$(mk_table taxon_trait)
|
36 |
|
|
$(mk_table analytical_stem)
|
37 |
|
|
$(mk_table provider_count)
|
38 |
6042
|
aaronmk
|
EOF
|
39 |
7345
|
aaronmk
|
) || exit
|
40 |
6981
|
aaronmk
|
|
41 |
10865
|
aaronmk
|
remake=1 "$selfDir"/../run export_ </dev/null
|
42 |
8320
|
aaronmk
|
#"$selfDir/export_analytical_db"
|