Project

General

Profile

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
mk_analytical_table()
31
{
32
    local table="$1"
33
    local public_table="\"$public\".$table"
34
    cat <<EOF
35
$(mk_table "$@")
36
EOF
37
}
38

    
39
((set -x; "$selfDir/psql_verbose_vegbien") <<EOF
40
GRANT USAGE ON SCHEMA analytical_db TO bien_read;
41
GRANT USAGE ON SCHEMA analytical_db TO public_;
42

    
43
$(mk_table geoscrub_input)
44

    
45
$(mk_table threatened_taxonlabel)
46

    
47
$(mk_analytical_table taxon_trait)
48
$(mk_analytical_table analytical_stem)
49
$(mk_analytical_table provider_count)
50
GRANT SELECT ON TABLE analytical_db.provider_count TO public_;
51
EOF
52
) || exit
53

    
54
remake=1 "$selfDir"/../run export_ </dev/null
55
#"$selfDir/export_analytical_db"
(43-43/86)