-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added migration folder v0.5.3 (#592)
* 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 --------- Co-authored-by: Simon Norris <snorris@hillcrestgeo.ca>
- Loading branch information
1 parent
6edeb73
commit fd63568
Showing
3 changed files
with
56 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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,,, | ||
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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##*/}'" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; |