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

Add mainstem lookup table #90

Merged
merged 3 commits into from
Jun 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion database/ci/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ LABEL org.opencontainers.image.authors="gs-w_eto_eb_federal_employees@usgs.gov"
LABEL org.opencontainers.image.title="NLDI CI Database"
LABEL org.opencontainers.image.description="A sample NLDI database used for continuous integration testing."

ENV CONTEXTS=ci
ENV LIQUIBASE_HOME /liquibase
ENV LIQUIBASE_WORKSPACE /liquibase
COPY --from=Liquibase ${LIQUIBASE_WORKSPACE} ${LIQUIBASE_WORKSPACE}
Expand All @@ -24,4 +25,3 @@ RUN apt-get update && apt-get install -y curl
COPY ./liquibase/changeLogs $LIQUIBASE_WORKSPACE
COPY ./liquibase/scripts/*.sh /docker-entrypoint-initdb.d/
COPY ./liquibase/scripts/dbInit /docker-entrypoint-initdb.d/
COPY ./liquibase/scripts/dbCi /docker-entrypoint-initdb.d/
6 changes: 6 additions & 0 deletions database/demo/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ LABEL org.opencontainers.image.authors="gs-w_eto_eb_federal_employees@usgs.gov"
LABEL org.opencontainers.image.title="NLDI Demo Database"
LABEL org.opencontainers.image.description="A demo of the NLDI database containing sample data."

ENV CONTEXTS=demo
ENV LIQUIBASE_HOME /liquibase
ENV LIQUIBASE_WORKSPACE /liquibase
COPY --from=Liquibase ${LIQUIBASE_WORKSPACE} ${LIQUIBASE_WORKSPACE}
Expand All @@ -32,3 +33,8 @@ RUN curl -L --verbose "https://github.com/internetofwater/nldi-db/releases/downl
RUN curl -L --verbose "https://github.com/internetofwater/nldi-db/releases/download/artifacts-1.0.0/feature_wqp_yahara.backup.gz" -o $LIQUIBASE_HOME/feature_wqp_yahara.backup.gz
RUN curl -L --verbose "https://github.com/internetofwater/nldi-db/releases/download/artifacts-1.0.0/feature_huc12pp_yahara.backup.gz" -o $LIQUIBASE_HOME/feature_huc12pp_yahara.backup.gz
RUN curl -L --verbose "https://github.com/internetofwater/nldi-db/releases/download/artifacts-1.0.0/feature_np21_nwis_yahara.backup.gz" -o $LIQUIBASE_HOME/feature_np21_nwis_yahara.backup.gz

ARG MAINSTEM_COMMIT="9052cbaeccbaa88f91317f8ec9891a90d378371f"
RUN curl -L "https://code.usgs.gov/wma/nhgf/gfv2.0/-/raw/${MAINSTEM_COMMIT}/workspace/data/mainstem_lookup.csv.gz?inline=false" \
-o ${LIQUIBASE_HOME}/mainstem_lookup.csv.gz
RUN gunzip ${LIQUIBASE_HOME}/mainstem_lookup.csv.gz
11 changes: 10 additions & 1 deletion liquibase/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,20 @@ ENV NLDI_READ_ONLY_PASSWORD=missing_read_only_password
ENV POSTGRES_PASSWORD=missing_postgres_password

USER root
RUN mkdir -p ${LIQUIBASE_WORKSPACE}

RUN apt-get --allow-releaseinfo-change update && apt-get install -y curl
COPY ./docker-entrypoint.sh /usr/local/bin/
RUN chmod +x /usr/local/bin/docker-entrypoint.sh

USER liquibase

COPY ./changeLogs /liquibase/workspace/.
COPY ./changeLogs ${LIQUIBASE_WORKSPACE}/.
COPY ./scripts/dbInit/* /docker-entrypoint-initdb.d/

ARG MAINSTEM_COMMIT="9052cbaeccbaa88f91317f8ec9891a90d378371f"
RUN curl -L "https://code.usgs.gov/wma/nhgf/gfv2.0/-/raw/${MAINSTEM_COMMIT}/workspace/data/mainstem_lookup.csv.gz?inline=false" \
-o ${LIQUIBASE_HOME}/mainstem_lookup.csv.gz
RUN gunzip ${LIQUIBASE_HOME}/mainstem_lookup.csv.gz

ENTRYPOINT ["docker-entrypoint.sh"]
2 changes: 2 additions & 0 deletions liquibase/changeLogs/nldi/nldi_data/changeLog.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,7 @@
<include file="functions/changeLog.xml" relativeToChangelogFile="true"/>
<include file="grants.sql" relativeToChangelogFile="true"/>
<include file="update_crawler_source/changeLog.yml" relativeToChangelogFile="true"/>
<include file="copyMainstemData.yml" relativeToChangelogFile="true"/>

</databaseChangeLog>

37 changes: 37 additions & 0 deletions liquibase/changeLogs/nldi/nldi_data/copyMainstemData.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
databaseChangeLog:
- preConditions:
- dbms:
type: PostgreSQL
- runningAs:
username: ${NLDI_DB_OWNER_USERNAME}

- changeSet:
author: egrahn
id: "load.nldi_data.mainstem_lookup"
runOnChange: true
context: "!ci"
changes:
- delete:
schemaName: nldi_data
tableName: mainstem_lookup
- loadData:
encoding: UTF-8
file: "${LIQUIBASE_HOME}/mainstem_lookup.csv"
relativeToChangelogFile: false
separator: ","
schemaName: nldi_data
tableName: mainstem_lookup
columns:
- column:
index: 0
name: nhdpv2_comid
type: NUMERIC
- column:
index: 1
name: mainstem_id
type: NUMERIC
- column:
index: 2
name: uri
type: STRING

17 changes: 17 additions & 0 deletions liquibase/changeLogs/nldi/nldi_data/tables.sql
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,11 @@ drop table nldi_data.feature_np21_nwis_temp;
--precondition-sql-check expectedResult:t select to_regclass('nldi_data."feature; select * from pg_class;_temp"') is not null
drop table nldi_data."feature; select * from pg_class;_temp";

--changeset egrahn:drop.nldi_data.sqlinjection_test
--preconditions onFail:MARK_RAN onError:HALT
--precondition-sql-check expectedResult:t select to_regclass('nldi_data."feature; select * from pg_class;"') is not null
drop table nldi_data."feature; select * from pg_class;";

--changeset egrahn:drop.nldi_data.feature_huc12pp_temp
--preconditions onFail:MARK_RAN onError:HALT
--precondition-sql-check expectedResult:t select to_regclass('nldi_data.feature_huc12pp_temp') is not null
Expand All @@ -112,3 +117,15 @@ drop table nldi_data.feature_huc12pp_temp;
--precondition-sql-check expectedResult:0 select count(column_name) from information_schema."columns" where table_schema = 'nldi_data' and table_name = 'feature' and column_name = 'shape'
alter table nldi_data.feature add column shape geometry(geometry,4269);
--rollback alter table nldi_data.feature drop column if exists shape;

--changeset egrahn:create.nldi_data.mainstem_lookup
--preconditions onFail:MARK_RAN onError:HALT
--precondition-sql-check expectedResult:0 select count(*) from information_schema.tables where table_schema = 'nldi_data' and table_name = 'mainstem_lookup'
create table nldi_data.mainstem_lookup
(
nhdpv2_comid integer,
mainstem_id integer,
uri text
);
alter table nldi_data.mainstem_lookup owner to ${NLDI_SCHEMA_OWNER_USERNAME};
--rollback drop table nldi_data.mainstem_lookup;
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ databaseChangeLog:
author: kkehl
id: "load.nldi_data.update_crawler_source"
runOnChange: true
context: "!ci"
changes:
- delete:
schemaName: nldi_data
Expand Down
13 changes: 0 additions & 13 deletions liquibase/scripts/dbCi/z3_clear_data.sh

This file was deleted.

6 changes: 0 additions & 6 deletions liquibase/scripts/dbInit/z1_postgres_liquibase.sh
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
#!/bin/bash

# create the nldi project user and database
#psql -v ON_ERROR_STOP=1 --username "$POSTGRES_USER" <<-EOSQL
# create role nldi with login createrole password '${NLDI_PASSWORD}';
# alter database nldi owner to nldi;
#EOSQL

# postgres to postgres db scripts
${LIQUIBASE_HOME}/liquibase \
--classpath=${LIQUIBASE_HOME}/lib/${JDBC_JAR} \
Expand Down
2 changes: 1 addition & 1 deletion liquibase/scripts/dbInit/z2_nldi_liquibase.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@ ${LIQUIBASE_HOME}/liquibase \
-DNLDI_DB_OWNER_USERNAME=${NLDI_DB_OWNER_USERNAME} \
-DNLDI_SCHEMA_OWNER_USERNAME=${NLDI_SCHEMA_OWNER_USERNAME} \
-DNHDPLUS_SCHEMA_OWNER_USERNAME=${NHDPLUS_SCHEMA_OWNER_USERNAME} \
-DNLDI_READ_ONLY_USERNAME=${NLDI_READ_ONLY_USERNAME}
-DNLDI_READ_ONLY_USERNAME=${NLDI_READ_ONLY_USERNAME}
2 changes: 1 addition & 1 deletion liquibase/scripts/z0_restart.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/bash

# Restart postgres to make sure we can connect
pg_ctl -D "$PGDATA" -m fast -o "$LOCALONLY" -w restart
pg_ctl -D "$PGDATA" -m fast -o "$LOCALONLY" -w restart