Skip to content

Commit

Permalink
materialize access view
Browse files Browse the repository at this point in the history
  • Loading branch information
smnorris committed Jan 4, 2024
1 parent 4699d0f commit 81445c0
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
8 changes: 5 additions & 3 deletions db/views/01_streams_access_vw.sql
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
-- view of stream data plus downstream barrier info

drop view if exists bcfishpass.streams_access_vw cascade;
drop materialized view if exists bcfishpass.streams_access_vw cascade;

create view bcfishpass.streams_access_vw as
create materialized view bcfishpass.streams_access_vw as
select
s.segmented_stream_id,
b.barriers_anthropogenic_dnstr,
Expand Down Expand Up @@ -63,4 +63,6 @@ left outer join bcfishpass.wsg_species_presence wsg_salmon on s.watershed_group_
left outer join bcfishpass.wsg_species_presence wsg_ct_dv_rb on s.watershed_group_code = wsg_ct_dv_rb.watershed_group_code and (wsg_ct_dv_rb.ct is true or wsg_ct_dv_rb.dv is true or wsg_ct_dv_rb.rb is true)
left outer join bcfishpass.wsg_species_presence wsg_st on s.watershed_group_code = wsg_st.watershed_group_code and wsg_st.st is true
left outer join bcfishpass.wsg_species_presence wsg_wct on s.watershed_group_code = wsg_wct.watershed_group_code and wsg_wct.wct is true
left outer join bcfishpass.crossings x on r.remediations_barriers_dnstr[1] = x.aggregated_crossings_id and x.pscis_status = 'REMEDIATED' and x.pscis_status = 'PASSABLE';
left outer join bcfishpass.crossings x on r.remediations_barriers_dnstr[1] = x.aggregated_crossings_id and x.pscis_status = 'REMEDIATED' and x.pscis_status = 'PASSABLE';

create unique index on bcfishpass.streams_access_vw (segmented_stream_id);
3 changes: 3 additions & 0 deletions model/01_access/model_access.sh
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,9 @@ $PARALLEL $PSQL -f sql/load_streams_upstr_observations.sql -v wsg={1} ::: $WSGS
$PSQL -c "truncate bcfishpass.streams_dnstr_species"
$PARALLEL $PSQL -f sql/load_streams_dnstr_species.sql -v wsg={1} ::: $WSGS

# refresh materialized view
$PSQL -c "refresh materialized view bcfishpass.streams_access_vw"

# generate crossings access report
$PSQL -c "truncate bcfishpass.crossings_upstream_access"
parallel --halt now,fail=1 --jobs 2 --no-run-if-empty $PSQL -f sql/load_crossings_upstream_access_01.sql -v wsg={1} ::: $WSGS
Expand Down

0 comments on commit 81445c0

Please sign in to comment.