Project

General

Profile

1
#!/bin/bash
2
# Creates analytical DB
3

    
4
selfDir="$(dirname -- "$0")"
5

    
6
. "$selfDir/vegbien_dest"
7

    
8
exec 2>>"$selfDir/../inputs/analytical_db/logs/make_analytical_db.log.sql" >&2
9

    
10
(set -x; date)
11

    
12
"$selfDir/waitself" "$selfDir/../inputs/.TNRS/tnrs/tnrs.make"
13

    
14
mk_analytical_table ()
15
{
16
    local table="$1"
17
    local public_table="\"$public\".$table" analyt_table="analytical_db.$table"
18
    cat <<EOF
19
-- Create $table
20
TRUNCATE $public_table;
21
INSERT INTO $public_table SELECT * FROM ${public_table}_view;
22
ANALYZE $public_table;
23

    
24
-- Create $analyt_table view pointing to table in $public
25
DROP VIEW IF EXISTS $analyt_table;
26
CREATE VIEW $analyt_table AS
27
SELECT * FROM $public_table;
28
GRANT SELECT ON TABLE $analyt_table TO bien_read;
29
EOF
30
}
31

    
32
((set -x; "$selfDir/psql_verbose_vegbien") <<EOF
33
GRANT USAGE ON SCHEMA analytical_db TO bien_read;
34
GRANT USAGE ON SCHEMA analytical_db TO public_;
35

    
36
TRUNCATE geoscrub_input;
37
INSERT INTO geoscrub_input SELECT * FROM geoscrub_input_view;
38

    
39
SELECT make_family_higher_plant_group();
40
TRUNCATE threatened_taxonlabel;
41
INSERT INTO threatened_taxonlabel SELECT * FROM threatened_taxonlabel_view;
42

    
43
$(mk_analytical_table taxon_trait)
44
$(mk_analytical_table analytical_stem)
45
$(mk_analytical_table provider_count)
46
GRANT SELECT ON TABLE analytical_db.provider_count TO public_;
47
$(mk_analytical_table analytical_aggregate)
48
EOF
49
) || exit
50

    
51
"$selfDir/export_analytical_db"
(38-38/80)