Skip to content

Commit

Permalink
Update join_tracking_table_crossings_vw.sql (#596)
Browse files Browse the repository at this point in the history
* Add WCRP columns to wcrp_watersheds.csv

Column shows which wcrp the watershed belongs to

* Added migration files

db.v0.5.3 includes join_tracking_table_crossings_vw.sql and migrate.sh

* Add wcrp column to wcrp_watersheds

Added column in table creation

* Moved wcrp column creation

- Added statement to add the wcrp column to bcfishpass.wcrp_watersheds
- removed the change from db/v0.5.0/sql/tables/wcrp.sql

* run add column wcrp to wcrp_watersheds on all systems

* Update join_tracking_table_crossings_vw.sql

- Added right join so excluded structures with no feature in crossings_wcrp_vw show up in the joined table.

---------

Co-authored-by: Simon Norris <[email protected]>
  • Loading branch information
andrewp-CWF and smnorris authored Nov 8, 2024
1 parent fd7a2e2 commit 66695ec
Showing 1 changed file with 109 additions and 4 deletions.
113 changes: 109 additions & 4 deletions db/v0.5.3/sql/join_tracking_table_crossings_vw.sql
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,116 @@ as
$$
begin
execute format('create or replace view wcrp_%I.combined_tracking_table_crossings_wcrp_vw_%I as
select
cv.*,
tt.*
select
tt.barrier_id,
cv.crossing_source,
cv.crossing_feature_type,
cv.pscis_status,
cv.crossing_type_code,
cv.crossing_subtype_code,
cv.barrier_status,
cv.pscis_road_name,
cv.pscis_stream_name,
cv.pscis_assessment_comment,
cv.pscis_assessment_date,
cv.transport_line_structured_name_1,
cv.rail_track_name,
cv.dam_name,
cv.dam_height,
cv.dam_owner,
cv.dam_use,
cv.dam_operating_status,
cv.utm_zone,
cv.utm_easting,
cv.utm_northing,
cv.blue_line_key,
cv.downstream_route_measure,
cv.wscode,
cv.localcode,
cv.watershed_group_code,
cv.gnis_stream_name,
cv.barriers_anthropogenic_dnstr,
cv.barriers_anthropogenic_dnstr_count,
cv.barriers_anthropogenic_habitat_wcrp_upstr
cv.barriers_antrhopogenic_habitat_wcrp_upstr_count,
cv.barriers_ch_cm_co_pk_sk_dnstr,
cv.barriers_st_dnstr,
cv.barriers_wct_dnstr,
cv.ch_spawning_km,
cv.ch_rearing_km,
cv.ch_spawning_belowupstrbarriers_km,
cv.ch_rearing_belowupstrbarriers_km,
cv.cm_spawning_km,
cv.cm_spawning_belowupstrbarriers_km,
cv.co_spawning_km,
cv.co_rearing_km,
cv.co_rearing_ha,
cv.co_spawning_belowupstrbarriers_km,
cv.co_rearing_belowupstrbarriers_km,
cv.co_rearing_belowupstrbarriers_ha,
cv.pk_spawning_km,
cv.pk_spawning_belowupstrbarriers_km,
cv.sk_spawning_km,
cv.sk_rearing_km,
cv.sk_rearing_ha,
cv.sk_spawning_belowupstrbarriers_km,
cv.sk_rearing_belowupstrbarriers_km,
cv.sk_rearing_belowupstrbarriers_ha,
cv.st_spawning_km,
cv.st_rearing_km,
cv.st_spawning_belowupstrbarriers_km,
cv.st_rearing_belowupstrbarriers_km,
cv.wct_spawning_km,
cv.wct_rearing_km,
cv.wct_spawning_belowupstrbarriers_km,
cv.wct_rearing_belowupstrbarriers_km,
cv.all_spawning_km,
cv.all_spawning_belowupstrbarriers_km,
cv.all_rearing_km,
cv.all_rearing_belowupstrbarriers_km,
cv.all_spawningrearing_km,
cv.all_spawningrearing_belowupstrbarriers_km,
cv.set_id,
cv.total_hab_gain_set,
cv.num_barriers_set,
cv.avg_gain_per_barrier,
cv.dnstr_set_ids,
cv.rank_avg_gain_per_barrier,
cv.rank_avg_gain_tiered,
cv.rank_total_upstr_hab,
cv.rank_combined,
cv.tier_combined,
cv.geom,
tt.internal_name,
tt.watercourse_name,
tt.road_name,
tt.structure_type,
tt.structure_owner,
tt.private_owner_details,
tt.structure_list_status,
tt.assessment_type_completed,
tt.reason_for_exclusion,
tt.method_of_exclusion,
tt.partial_passability,
tt.partial_passability_notes,
tt.upstream_habitat_quality,
tt.constructability,
tt.estimated_cost_$,
tt.priority,
tt.type_of_rehabilitation,
tt.rehabilitated_by,
tt.rehabilitated_date,
tt.estimated_rehabilitation_cost_$,
tt.actual_project_cost_$,
tt.next_steps,
tt.timeline_for_next_steps,
tt.lead_for_next_steps,
tt.others_involved_in_next_steps,
tt.reason,
tt.notes,
tt.supporting_links
from bcfishpass.crossings_wcrp_vw cv
join wcrp_%I.combined_tracking_table_%I tt
right join wcrp_%I.combined_tracking_table_%I tt
on tt.barrier_id = cv.aggregated_crossings_id', p_wcrp, p_wcrp, p_wcrp, p_wcrp);
end
$$
Expand Down

0 comments on commit 66695ec

Please sign in to comment.