diff --git a/data/wcrp_watersheds.csv b/data/wcrp_watersheds.csv index abbf5e1f..93439a0f 100644 --- a/data/wcrp_watersheds.csv +++ b/data/wcrp_watersheds.csv @@ -1,20 +1,20 @@ -watershed_group_code,ch,cm,co,pk,sk,st,wct,notes -ATNA,t,,t,,t,,, -BELA,t,,t,,t,,, -BONP,t,,t,,t,,, -BOWR,t,,t,,t,,, -BULK,t,,t,,t,t,, -CARR,t,,t,,t,,, -ELKR,,,,,,,t, -HORS,t,,t,,t,,, -LNIC,t,,t,,,t,, -NECL,t,,t,,t,,, -QUES,t,,t,,t,,, -SHUL,t,,t,,t,,, -USHU,t,,t,,t,,, -TAKL,t,,,,t,,, -MIDR,t,,,,t,,, -UTRE,t,,,,t,,, -LTRE,t,,,,t,,, -STUL,t,,,,t,,, -STUR,t,,,,t,,, \ No newline at end of file +watershed_group_code,ch,cm,co,pk,sk,st,wct,notes,wcrp +ATNA,t,,t,,t,,,,bela_atna_necl +BELA,t,,t,,t,,,,bela_atna_necl +BONP,t,,t,,t,,,,tho_shu +BOWR,t,,t,,t,,,,bowr_ques_carr +BULK,t,,t,,t,t,,,bulk +CARR,t,,t,,t,,,,bowr_ques_carr +ELKR,,,,,,,t,,elkr +HORS,t,,t,,t,,,,hors +LNIC,t,,t,,,t,,,lnic +NECL,t,,t,,t,,,,bela_atna_necl +QUES,t,,t,,t,,,,bowr_ques_carr +SHUL,t,,t,,t,,,,tho_shu +USHU,t,,t,,t,,,,tho_shu +TAKL,t,,,,t,,,,tuzistol_tah +MIDR,t,,,,t,,,,tuzistol_tah +UTRE,t,,,,t,,,,tuzistol_tah +LTRE,t,,,,t,,,,tuzistol_tah +STUL,t,,,,t,,,,tuzistol_tah +STUR,t,,,,t,,,,tuzistol_tah \ No newline at end of file diff --git a/db/v0.5.3/migrate.sh b/db/v0.5.3/migrate.sh new file mode 100755 index 00000000..25d93de0 --- /dev/null +++ b/db/v0.5.3/migrate.sh @@ -0,0 +1,12 @@ +#!/bin/bash +set -euxo pipefail + +# add wcrp name column to wcrp table +psql $DATABASE_URL -v ON_ERROR_STOP=1 -c "alter table bcfishpass.wcrp_watersheds add column wcrp varchar(32);" + +# add wcrp tracking views +echo "On systems supporting CWF WCRP reporting, add join_tracking_table_crossings_view.sql" +echo "psql $DATABASE_URL -v ON_ERROR_STOP=1 -f sql/join_tracking_table_crossings_view.sql" + +# note version +psql $DATABASE_URL -v ON_ERROR_STOP=1 -c "update bcfishpass.db_version set tag = '${PWD##*/}'" \ No newline at end of file diff --git a/db/v0.5.3/sql/join_tracking_table_crossings_vw.sql b/db/v0.5.3/sql/join_tracking_table_crossings_vw.sql new file mode 100644 index 00000000..f5ed09ef --- /dev/null +++ b/db/v0.5.3/sql/join_tracking_table_crossings_vw.sql @@ -0,0 +1,24 @@ +-- This function joins the tracking table to bcfishpass.crossings_wcrp_vw on the barrier ID +create or replace function wcrp_hors.join_tracking_table_crossings_wcrp_vw(p_wcrp text) + returns void +as +$$ +begin + execute format('create or replace view wcrp_%I.combined_tracking_table_crossings_wcrp_vw_%I as + select + cv.*, + tt.* + from bcfishpass.crossings_wcrp_vw cv + 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 +$$ +language plpgsql; + +-- loop through each WCRP and create a view for each one +with data (wcrp) as ( + select wcrp + from bcfishpass.wcrp_watersheds +) +select wcrp_hors.join_tracking_table_crossings_wcrp_vw(wcrp) +from data; \ No newline at end of file