diff --git a/data/wcrp_watersheds.csv b/data/wcrp_watersheds.csv index 1077c452..93439a0f 100644 --- a/data/wcrp_watersheds.csv +++ b/data/wcrp_watersheds.csv @@ -17,4 +17,4 @@ 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 +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 100644 index 00000000..a1c92b8f --- /dev/null +++ b/db/v0.5.3/migrate.sh @@ -0,0 +1,8 @@ +#!/bin/bash +set -euxo pipefail + +echo "On systems supporting CWF WCRP reporting, add join_tracking_table_crossings_view.sql" +echo "psql $DATABASE_URL -f sql/join_tracking_table_crossings_view.sql" + +# note version +psql $DATABASE_URL -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..074f2539 --- /dev/null +++ b/db/v0.5.3/sql/join_tracking_table_crossings_vw.sql @@ -0,0 +1,25 @@ + +-- 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