Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Gha setup #464

Merged
merged 12 commits into from
Feb 29, 2024
4 changes: 3 additions & 1 deletion db/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,6 @@ Additional internal tables are created by model scripts.

## Usage

./setup.sh
From repository root, with $DATABASE_URL connection defined as db superuser:

.jobs/setup
2 changes: 1 addition & 1 deletion db/functions/break_streams.sql
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
CREATE OR REPLACE FUNCTION bcfishpass.break_streams(point_table text, wsg text)
CREATE FUNCTION bcfishpass.break_streams(point_table text, wsg text)
RETURNS VOID
LANGUAGE plpgsql AS
$func$
Expand Down
2 changes: 1 addition & 1 deletion db/functions/create_barrier_table.sql
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
-- create table for holding barriers of given type

CREATE OR REPLACE FUNCTION bcfishpass.create_barrier_table(barriertype text)
CREATE FUNCTION bcfishpass.create_barrier_table(barriertype text)
RETURNS VOID
LANGUAGE plpgsql AS
$func$
Expand Down
2 changes: 1 addition & 1 deletion db/functions/load_dnstr.sql
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
-- compare records in table a and table b,
-- and record in output table (as an array) all ids from b that are downstream of given id for table a
CREATE OR REPLACE FUNCTION bcfishpass.load_dnstr(
CREATE FUNCTION bcfishpass.load_dnstr(
table_a text,
table_a_id text,
table_b text,
Expand Down
2 changes: 1 addition & 1 deletion db/functions/load_upstr.sql
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
-- compare records in table a and table b,
-- and record in output table (as an array) all ids from b that are downstream of given id for table a
CREATE OR REPLACE FUNCTION bcfishpass.load_upstr(
CREATE FUNCTION bcfishpass.load_upstr(
table_a text,
table_a_id text,
table_b text,
Expand Down
2 changes: 1 addition & 1 deletion db/functions/streamsasmvt.sql
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
CREATE OR REPLACE FUNCTION bcfishpass.streamsasmvt(
CREATE FUNCTION bcfishpass.streamsasmvt(
z integer, x integer, y integer)
RETURNS bytea
AS $$
Expand Down
2 changes: 1 addition & 1 deletion db/functions/utmzone.sql
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
-- DROP FUNCTION utmzone(geometry);
-- Usage: SELECT ST_Transform(the_geom, utmzone(ST_Centroid(the_geom)) )FROM sometable;

CREATE OR REPLACE FUNCTION public.utmzone(geometry)
CREATE FUNCTION public.utmzone(geometry)
RETURNS integer AS
$BODY$
DECLARE
Expand Down
1 change: 0 additions & 1 deletion db/functions/wcrp_barrier_count.sql
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
-- function to query the view (so it is visible in pgfs)
DROP FUNCTION IF EXISTS postgisftw.wcrp_barrier_count;
CREATE FUNCTION postgisftw.wcrp_barrier_count(
watershed_group_code TEXT,
model_status TEXT default 'ALL'
Expand Down
2 changes: 0 additions & 2 deletions db/functions/wcrp_barrier_extent.sql
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
DROP FUNCTION IF EXISTS postgisftw.wcrp_barrier_extent(TEXT);

CREATE FUNCTION postgisftw.wcrp_barrier_extent(watershed_group_code TEXT)

-- watershed_group_code: BULK, LNIC, HORS, BOWR, QUES, CARR, ELKR
Expand Down
2 changes: 0 additions & 2 deletions db/functions/wcrp_barrier_severity.sql
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
DROP FUNCTION IF EXISTS postgisftw.wcrp_barrier_severity(text);

CREATE FUNCTION postgisftw.wcrp_barrier_severity(watershed_group_code TEXT)

-- watershed_group_code: BULK, LNIC, HORS, BOWR, QUES, CARR, ELKR
Expand Down
3 changes: 0 additions & 3 deletions db/functions/wcrp_habitat_connectivity_status.sql
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
-- report on total modelled habitat vs accessible modelled habitat

DROP FUNCTION IF EXISTS postgisftw.wcrp_habitat_connectivity_status(TEXT,TEXT);

CREATE OR REPLACE FUNCTION postgisftw.wcrp_habitat_connectivity_status(
watershed_group_code TEXT,
habitat_type TEXT default 'ALL'
Expand Down
2 changes: 0 additions & 2 deletions db/functions/wsg_crossing_summary.sql
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
-- - total
-- - accessible (per model)
-- - with spawning rearing habitat upstream (per model)

DROP FUNCTION IF EXISTS bcfishpass.wsg_crossing_summary();
CREATE FUNCTION bcfishpass.wsg_crossing_summary()
RETURNS table (
watershed_group_code text,
Expand Down
1 change: 0 additions & 1 deletion db/functions/wsg_linear_summary.sql
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
-- - spawning or rearing habitat not isolated by dam or a known pscis barrier (accessible_a)
-- - spawning or rearing habitat not isolated by all anthropogenic barriers (observed and modelled) (accessible_b)

DROP FUNCTION IF EXISTS bcfishpass.wsg_linear_summary();
CREATE FUNCTION bcfishpass.wsg_linear_summary()
RETURNS table (
watershed_group_code text,
Expand Down
11 changes: 11 additions & 0 deletions db/schemas.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
create schema bcfishpass;
create schema cabd;
create schema whse_admin_boundaries;
create schema whse_cadastre;
create schema whse_environmental_monitoring;
create schema whse_forest_tenure;
create schema whse_forest_vegetation;
create schema whse_imagery_and_base_maps;
create schema whse_legal_admin_boundaries;
create schema whse_mineral_tenure;
create schema whse_tantalis;
3 changes: 0 additions & 3 deletions db/schemas/schemas.sql

This file was deleted.

21 changes: 0 additions & 21 deletions db/setup.sh

This file was deleted.

4 changes: 0 additions & 4 deletions db/tables/cabd.sql
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
-- dams
drop table if exists cabd.dams cascade;

create table cabd.dams (
cabd_id text ,
use_pollution_code integer ,
Expand Down Expand Up @@ -108,8 +106,6 @@ create table cabd.dams (
);

-- waterfalls
drop table if exists cabd.waterfalls cascade;

create table cabd.waterfalls (
cabd_id text ,
fall_name_fr text ,
Expand Down
3 changes: 0 additions & 3 deletions db/tables/crossings.sql
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@
-- 3. Modelled crossings (culverts and bridges)
-- 4. Other ?
-- --------------

drop table if exists bcfishpass.crossings cascade;

create table bcfishpass.crossings
(
-- Note how the aggregated crossing id combines the various ids to create a unique integer, after assigning PSCIS crossings their source crossing id
Expand Down
4 changes: 0 additions & 4 deletions db/tables/crossings_upstr_dnstr.sql
Original file line number Diff line number Diff line change
@@ -1,24 +1,20 @@
-- note other crossings/barriers upstream / downstream of crossings in crossings table / barriers anth table

drop table if exists bcfishpass.crossings_dnstr_crossings cascade;
create table bcfishpass.crossings_dnstr_crossings (
aggregated_crossings_id text primary key,
features_dnstr text[]
);

drop table if exists bcfishpass.crossings_dnstr_barriers_anthropogenic cascade;
create table bcfishpass.crossings_dnstr_barriers_anthropogenic (
aggregated_crossings_id text primary key,
features_dnstr text[]
);

drop table if exists bcfishpass.crossings_upstr_barriers_anthropogenic cascade;
create table bcfishpass.crossings_upstr_barriers_anthropogenic (
aggregated_crossings_id text primary key,
features_upstr text[]
);

drop table if exists bcfishpass.barriers_anthropogenic_dnstr_barriers_anthropogenic cascade;
create table bcfishpass.barriers_anthropogenic_dnstr_barriers_anthropogenic (
barriers_anthropogenic_id text primary key,
features_dnstr text[]
Expand Down
2 changes: 0 additions & 2 deletions db/tables/crossings_upstream_access.sql
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
-- report on potentially accessible lengths and areas upstream, per species scenario / model
drop table if exists bcfishpass.crossings_upstream_access cascade;

create table bcfishpass.crossings_upstream_access (
aggregated_crossings_id text primary key,
watershed_group_code character varying (4),
Expand Down
4 changes: 0 additions & 4 deletions db/tables/crossings_upstream_habitat.sql
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
-- report on habitat upstream, per species
drop table if exists bcfishpass.crossings_upstream_habitat cascade;

create table bcfishpass.crossings_upstream_habitat (
aggregated_crossings_id text primary key,
watershed_group_code character varying (4),
Expand Down Expand Up @@ -43,8 +41,6 @@ create table bcfishpass.crossings_upstream_habitat (
-- - barriers only
-- - currently ch/co/sk/st/wct where they exist in watersheds of interest
-- - apply 1.5x multiplier to co rearing in wetlands and all sk rearing
drop table if exists bcfishpass.crossings_upstream_habitat_wcrp cascade;

create table bcfishpass.crossings_upstream_habitat_wcrp (
aggregated_crossings_id text primary key,
watershed_group_code character varying (4),
Expand Down
14 changes: 6 additions & 8 deletions db/tables/gradient_barriers.sql
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
DROP TABLE IF EXISTS bcfishpass.gradient_barriers;

CREATE TABLE bcfishpass.gradient_barriers (
gradient_barrier_id bigint GENERATED ALWAYS AS ((((blue_line_key::bigint + 1) - 354087611) * 10000000) + round(downstream_route_measure::bigint)) STORED PRIMARY KEY,
blue_line_key integer ,
Expand All @@ -10,9 +8,9 @@ CREATE TABLE bcfishpass.gradient_barriers (
gradient_class integer
);

create index if not exists grdntbr_blk_idx on bcfishpass.gradient_barriers (blue_line_key);
create index if not exists grdntbr_wsgcode_idx on bcfishpass.gradient_barriers (watershed_group_code);
create index if not exists grdntbr_wscode_gidx on bcfishpass.gradient_barriers using gist (wscode_ltree);
create index if not exists grdntbr_wscode_bidx on bcfishpass.gradient_barriers using btree (wscode_ltree);
create index if not exists grdntbr_localcode_gidx on bcfishpass.gradient_barriers using gist (localcode_ltree);
create index if not exists grdntbr_localcode_bidx on bcfishpass.gradient_barriers using btree (localcode_ltree);
create index grdntbr_blk_idx on bcfishpass.gradient_barriers (blue_line_key);
create index grdntbr_wsgcode_idx on bcfishpass.gradient_barriers (watershed_group_code);
create index grdntbr_wscode_gidx on bcfishpass.gradient_barriers using gist (wscode_ltree);
create index grdntbr_wscode_bidx on bcfishpass.gradient_barriers using btree (wscode_ltree);
create index grdntbr_localcode_gidx on bcfishpass.gradient_barriers using gist (localcode_ltree);
create index grdntbr_localcode_bidx on bcfishpass.gradient_barriers using btree (localcode_ltree);
8 changes: 0 additions & 8 deletions db/tables/habitat_linear.sql
Original file line number Diff line number Diff line change
@@ -1,51 +1,43 @@
drop table if exists bcfishpass.habitat_linear_bt cascade;
create table bcfishpass.habitat_linear_bt (
segmented_stream_id text primary key,
spawning boolean,
rearing boolean
);

drop table if exists bcfishpass.habitat_linear_ch cascade;
create table bcfishpass.habitat_linear_ch (
segmented_stream_id text primary key,
spawning boolean,
rearing boolean
);

drop table if exists bcfishpass.habitat_linear_cm cascade;
create table bcfishpass.habitat_linear_cm (
segmented_stream_id text primary key,
spawning boolean
);

drop table if exists bcfishpass.habitat_linear_co cascade;
create table bcfishpass.habitat_linear_co (
segmented_stream_id text primary key,
spawning boolean,
rearing boolean
);

drop table if exists bcfishpass.habitat_linear_pk cascade;
create table bcfishpass.habitat_linear_pk (
segmented_stream_id text primary key,
spawning boolean
);

drop table if exists bcfishpass.habitat_linear_sk cascade;
create table bcfishpass.habitat_linear_sk (
segmented_stream_id text primary key,
spawning boolean,
rearing boolean
);

drop table if exists bcfishpass.habitat_linear_st cascade;
create table bcfishpass.habitat_linear_st (
segmented_stream_id text primary key,
spawning boolean,
rearing boolean
);

drop table if exists bcfishpass.habitat_linear_wct cascade;
create table bcfishpass.habitat_linear_wct (
segmented_stream_id text primary key,
spawning boolean,
Expand Down
10 changes: 5 additions & 5 deletions db/tables/log.sql
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
--drop table bcfishpass.parameters_habitat_thresholds_log;
--drop table bcfishpass.wsg_linear_summary;
--drop table bcfishpass.wsg_crossing_summary;
create table if not exists bcfishpass.log (
create table bcfishpass.log (
model_run_id serial primary key,
model_type text not null,
date_completed timestamp not null default CURRENT_TIMESTAMP,
Expand All @@ -20,13 +20,13 @@ create table if not exists bcfishpass.log (


-- log parameters used for the given model run
create table if not exists bcfishpass.parameters_habitat_method_log (
create table bcfishpass.parameters_habitat_method_log (
model_run_id integer references bcfishpass.log(model_run_id),
watershed_group_code character varying(4),
model text
);

create table if not exists bcfishpass.parameters_habitat_thresholds_log (
create table bcfishpass.parameters_habitat_thresholds_log (
model_run_id integer references bcfishpass.log(model_run_id),
species_code text ,
spawn_gradient_max numeric,
Expand All @@ -42,7 +42,7 @@ create table if not exists bcfishpass.parameters_habitat_thresholds_log (
rear_lake_ha_min integer
);

create table if not exists bcfishpass.wsg_linear_summary (
create table bcfishpass.wsg_linear_summary (
model_run_id integer references bcfishpass.log(model_run_id),
watershed_group_code text,
length_total numeric,
Expand Down Expand Up @@ -112,7 +112,7 @@ create table if not exists bcfishpass.wsg_linear_summary (
length_spawning_rearing_wct_accessible_b numeric
);

create table if not exists bcfishpass.wsg_crossing_summary (
create table bcfishpass.wsg_crossing_summary (
model_run_id integer references bcfishpass.log(model_run_id),
watershed_group_code text,
crossing_feature_type text,
Expand Down
18 changes: 8 additions & 10 deletions db/tables/observations.sql
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
DROP TABLE IF EXISTS bcfishpass.observations cascade;

CREATE TABLE bcfishpass.observations
(
fish_obsrvtn_event_id bigint primary key,
Expand All @@ -16,11 +14,11 @@ CREATE TABLE bcfishpass.observations
);

-- index
create index if not exists obsrvtn_linear_feature_id_idx on bcfishpass.observations (linear_feature_id);
create index if not exists obsrvtn_blue_line_key_idx on bcfishpass.observations (blue_line_key);
create index if not exists obsrvtn_watershed_group_code_idx on bcfishpass.observations (watershed_group_code);
create index if not exists obsrvtn_wsc_gidx on bcfishpass.observations using gist (wscode_ltree);
create index if not exists obsrvtn_wsc_bidx on bcfishpass.observations using btree (wscode_ltree);
create index if not exists obsrvtn_lc_gidx on bcfishpass.observations using gist (localcode_ltree);
create index if not exists obsrvtn_lc_bidx on bcfishpass.observations using btree (localcode_ltree);
create index if not exists obsrvtn_geom_idx on bcfishpass.observations using gist (geom);
create index obsrvtn_linear_feature_id_idx on bcfishpass.observations (linear_feature_id);
create index obsrvtn_blue_line_key_idx on bcfishpass.observations (blue_line_key);
create index obsrvtn_watershed_group_code_idx on bcfishpass.observations (watershed_group_code);
create index obsrvtn_wsc_gidx on bcfishpass.observations using gist (wscode_ltree);
create index obsrvtn_wsc_bidx on bcfishpass.observations using btree (wscode_ltree);
create index obsrvtn_lc_gidx on bcfishpass.observations using gist (localcode_ltree);
create index obsrvtn_lc_bidx on bcfishpass.observations using btree (localcode_ltree);
create index obsrvtn_geom_idx on bcfishpass.observations using gist (geom);
9 changes: 3 additions & 6 deletions db/tables/parameters.sql
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
-- method
-- specify which watersheds to include, which habitat model to use
-- --------------
drop table if exists bcfishpass.parameters_habitat_method cascade;
create table bcfishpass.parameters_habitat_method
(
watershed_group_code character varying(4),
Expand All @@ -15,7 +14,6 @@ create table bcfishpass.parameters_habitat_method
-- thresholds
-- define various spawning/rearing thresholds for species to be modelled
-- --------------
drop table if exists bcfishpass.parameters_habitat_thresholds cascade;
create table bcfishpass.parameters_habitat_thresholds (
species_code text,
spawn_gradient_max numeric,
Expand All @@ -31,10 +29,9 @@ create table bcfishpass.parameters_habitat_thresholds (
rear_lake_ha_min integer
);


-- --------------
-- list of watershed groups to process in access model/crossings
-- defaults to all
-- --------------
drop table if exists bcfishpass.watershed_groups_access;
create table bcfishpass.watershed_groups_access as select watershed_group_code from whse_basemapping.fwa_watershed_groups_poly;
create table bcfishpass.watershed_groups_access (
watershed_group_code character varying(4)
);
Loading
Loading