1
|
#!/bin/bash
|
2
|
# Creates analytical DB
|
3
|
|
4
|
selfDir="$(dirname -- "$0")"
|
5
|
|
6
|
prefix=
|
7
|
. "$selfDir/vegbien_dest"
|
8
|
|
9
|
exec 2>>"$selfDir/../inputs/analytical_db/logs/make_analytical_db.log.sql" >&2
|
10
|
|
11
|
(set -x; date)
|
12
|
|
13
|
mk_analytical_table ()
|
14
|
{
|
15
|
local table="$1"
|
16
|
cat <<EOF
|
17
|
-- Create $table
|
18
|
TRUNCATE $table;
|
19
|
INSERT INTO $table SELECT * FROM ${table}_view;
|
20
|
|
21
|
-- Create analytical_db.$table view pointing to table in $public
|
22
|
DROP VIEW IF EXISTS analytical_db.$table;
|
23
|
CREATE VIEW analytical_db.$table AS
|
24
|
SELECT * FROM "$public".$table;
|
25
|
GRANT SELECT ON TABLE analytical_db.$table TO bien_read;
|
26
|
EOF
|
27
|
}
|
28
|
|
29
|
(set -x; "$selfDir/psql_verbose_vegbien") <<EOF
|
30
|
TRUNCATE geoscrub_input;
|
31
|
INSERT INTO geoscrub_input SELECT * FROM geoscrub_input_view;
|
32
|
|
33
|
SELECT make_family_higher_plant_group();
|
34
|
TRUNCATE threatened_taxonlabel;
|
35
|
INSERT INTO threatened_taxonlabel SELECT * FROM threatened_taxonlabel_view;
|
36
|
|
37
|
$(mk_analytical_table analytical_stem)
|
38
|
$(mk_analytical_table analytical_aggregate)
|
39
|
EOF
|