Skip to content

Commit

Permalink
Added migration files
Browse files Browse the repository at this point in the history
db.v0.5.3 includes join_tracking_table_crossings_vw.sql and migrate.sh
  • Loading branch information
andrewp-CWF committed Nov 1, 2024
1 parent 1a045a6 commit 46ad123
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 1 deletion.
2 changes: 1 addition & 1 deletion data/wcrp_watersheds.csv
Original file line number Diff line number Diff line change
Expand Up @@ -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
8 changes: 8 additions & 0 deletions db/v0.5.3/migrate.sh
Original file line number Diff line number Diff line change
@@ -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##*/}'"
25 changes: 25 additions & 0 deletions db/v0.5.3/sql/join_tracking_table_crossings_vw.sql
Original file line number Diff line number Diff line change
@@ -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;

0 comments on commit 46ad123

Please sign in to comment.