1
|
#!/bin/bash
|
2
|
# Creates analytical DB
|
3
|
# Usage: self [log=]
|
4
|
|
5
|
selfDir="$(dirname -- "$0")"
|
6
|
|
7
|
. "$selfDir/vegbien_dest"
|
8
|
|
9
|
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
|
|
13
|
(set -x; date)
|
14
|
|
15
|
sleep 5 # wait for tnrs.make to acquire the lock if being run right after import
|
16
|
"$selfDir/waitself" "$selfDir/../inputs/.TNRS/tnrs/tnrs.make"
|
17
|
|
18
|
mk_table()
|
19
|
{
|
20
|
local table="$1"
|
21
|
local public_table="\"$public\".$table"
|
22
|
cat <<EOF
|
23
|
-- Create $table
|
24
|
TRUNCATE $public_table;
|
25
|
INSERT INTO $public_table SELECT * FROM ${public_table}_view;
|
26
|
ANALYZE $public_table;
|
27
|
EOF
|
28
|
}
|
29
|
|
30
|
((set -x; "$selfDir/psql_verbose_vegbien") <<EOF
|
31
|
SELECT iucn_red_list_view_modify();
|
32
|
|
33
|
$(mk_table geoscrub_input)
|
34
|
|
35
|
$(mk_table taxon_trait)
|
36
|
$(mk_table analytical_stem)
|
37
|
$(mk_table provider_count)
|
38
|
EOF
|
39
|
) || exit
|
40
|
|
41
|
remake=1 "$selfDir"/../run export_ </dev/null
|
42
|
#"$selfDir/export_analytical_db"
|