Project

General

Profile

1 6461 aaronmk
#!/bin/bash
2 4395 aaronmk
# Creates analytical DB
3
4
selfDir="$(dirname -- "$0")"
5
6 6459 aaronmk
. "$selfDir/vegbien_dest"
7
8 6055 aaronmk
exec 2>>"$selfDir/../inputs/analytical_db/logs/make_analytical_db.log.sql" >&2
9 6047 aaronmk
10 6054 aaronmk
(set -x; date)
11 6048 aaronmk
12 6460 aaronmk
mk_analytical_table ()
13
{
14
    local table="$1"
15 6465 aaronmk
    local public_table="\"$public\".$table" analyt_table="analytical_db.$table"
16 6460 aaronmk
    cat <<EOF
17
-- Create $table
18 6466 aaronmk
TRUNCATE $public_table;
19
INSERT INTO $public_table SELECT * FROM ${public_table}_view;
20 6460 aaronmk
21 6465 aaronmk
-- Create $analyt_table view pointing to table in $public
22
DROP VIEW IF EXISTS $analyt_table;
23
CREATE VIEW $analyt_table AS
24
SELECT * FROM $public_table;
25
GRANT SELECT ON TABLE $analyt_table TO bien_read;
26 7042 aaronmk
GRANT SELECT ON TABLE $analyt_table TO public_;
27
    -- actual access depends on underlying table's permissions
28 6460 aaronmk
EOF
29
}
30
31 6462 aaronmk
(set -x; "$selfDir/psql_verbose_vegbien") <<EOF
32 7031 aaronmk
GRANT USAGE ON SCHEMA analytical_db TO bien_read;
33
GRANT USAGE ON SCHEMA analytical_db TO public_;
34
35 6053 aaronmk
TRUNCATE geoscrub_input;
36
INSERT INTO geoscrub_input SELECT * FROM geoscrub_input_view;
37
38 6042 aaronmk
SELECT make_family_higher_plant_group();
39 6085 aaronmk
TRUNCATE threatened_taxonlabel;
40
INSERT INTO threatened_taxonlabel SELECT * FROM threatened_taxonlabel_view;
41 6042 aaronmk
42 6895 aaronmk
$(mk_analytical_table taxon_trait)
43 6460 aaronmk
$(mk_analytical_table analytical_stem)
44 6868 aaronmk
$(mk_analytical_table provider_count)
45 6460 aaronmk
$(mk_analytical_table analytical_aggregate)
46 6042 aaronmk
EOF
47 6981 aaronmk
48
"$selfDir/export_analytical_db"