diff --git a/AACT_downloader/ClinicalTrialHistory/Dockerfile b/AACT_downloader/ClinicalTrialHistory/Dockerfile deleted file mode 100644 index e8b5481..0000000 --- a/AACT_downloader/ClinicalTrialHistory/Dockerfile +++ /dev/null @@ -1,7 +0,0 @@ -FROM youainti/aact_from_dump -LABEL AUTHOR 'Will King (youainti@protonmail.com)' -LABEL DESCRIPTION 'add extra processing to the aact database in preparation for downloading history.' - -#copy additional init scripts -COPY ./docker-entrypoint-initdb.d/ /docker-entrypoint-initdb.d/ -#these will be run after the database is initialized diff --git a/AACT_downloader/docker-compose.yaml b/AACT_downloader/docker-compose.yaml index fbdd998..fdefa02 100644 --- a/AACT_downloader/docker-compose.yaml +++ b/AACT_downloader/docker-compose.yaml @@ -1,15 +1,14 @@ version: '3' volumes: - aact_pg_database: #This is to hold the database. + aact_pg_database: #This is to hold the database, making it easy to purge if needed. networks: - pharmaceutical_research: - external: true + pharmaceutical_research: #because it helps to have a way to link specifically to this. services: - aact: - build: ./ClinicalTrialHistory #build and use the clinical trial history db. + aact_db: + image: postgres:14-alpine networks: - pharmaceutical_research container_name: aact_db @@ -21,6 +20,10 @@ services: ports: - "5432:5432" #host:container volumes: #host:container is the format. - - aact_pg_database:/var/lib/postgresql/ # this is persistant storage for the database + # this is persistant storage for the database + - aact_pg_database:/var/lib/postgresql/ + # this is the database dump to restore from - ./aact_downloads/postgres_data.dmp:/mnt/host_data/postgres_data.dmp + # this is the folder containing entrypoint info. + - ./docker-entrypoint-initdb.d/:/docker-entrypoint-initdb.d/ diff --git a/AACT_downloader/docker-entrypoint-initdb.d/005_CreateAactUsers.sql b/AACT_downloader/docker-entrypoint-initdb.d/005_CreateAactUsers.sql new file mode 100644 index 0000000..4a96326 --- /dev/null +++ b/AACT_downloader/docker-entrypoint-initdb.d/005_CreateAactUsers.sql @@ -0,0 +1,21 @@ +--Create ctti user and grant permissions +CREATE ROLE ctti; +GRANT ALL PRIVILEGES ON DATABASE aact_db TO ctti; + +/* +Add the root user if it doesn't exist. +With the default configuration this shouldn't be an issue, +but I can see myself forgetting and changing the default POSTGRES_USER +*/ +DO LANGUAGE plpgsql +$do$ +BEGIN + IF NOT EXISTS ( + SELECT FROM pg_catalog.pg_roles -- SELECT list can be empty for this + WHERE rolname = 'root') + THEN + CREATE ROLE root LOGIN PASSWORD 'root'; --SECURITY ISSUE + GRANT ALL PRIVILEGES ON DATABASE aact_db TO root; + END IF; +END +$do$ diff --git a/AACT_downloader/docker-entrypoint-initdb.d/010_load_db_dump.sh b/AACT_downloader/docker-entrypoint-initdb.d/010_load_db_dump.sh new file mode 100644 index 0000000..17c7e74 --- /dev/null +++ b/AACT_downloader/docker-entrypoint-initdb.d/010_load_db_dump.sh @@ -0,0 +1,18 @@ +#!/bin/bash +set -e +set -x + + +# This file loads the database dump into the postgres database + +dump_path="/mnt/host_data/postgres_data.dmp" + +#Double check the postgres user and database are set +if [[ -z $POSTGRES_USER && -z $POSTGRES_DB ]]; #if either POSTGRES_USER or POSTGRES_DB are empty, throw an error. +then + echo "Missing either the POSTGRESS_USER or the POSTGRES_DB environment variable" + exit 4 +else + #restore the DB + pg_restore -e -v -O -x --dbname="$POSTGRES_DB" --username="$POSTGRES_USER" --no-owner "$dump_path" +fi diff --git a/AACT_downloader/ClinicalTrialHistory/docker-entrypoint-initdb.d/020_HttpSchema.sql b/AACT_downloader/docker-entrypoint-initdb.d/020_HttpSchema.sql similarity index 100% rename from AACT_downloader/ClinicalTrialHistory/docker-entrypoint-initdb.d/020_HttpSchema.sql rename to AACT_downloader/docker-entrypoint-initdb.d/020_HttpSchema.sql diff --git a/AACT_downloader/ClinicalTrialHistory/docker-entrypoint-initdb.d/030_HistoricalSchema.sql b/AACT_downloader/docker-entrypoint-initdb.d/030_HistoricalSchema.sql similarity index 100% rename from AACT_downloader/ClinicalTrialHistory/docker-entrypoint-initdb.d/030_HistoricalSchema.sql rename to AACT_downloader/docker-entrypoint-initdb.d/030_HistoricalSchema.sql diff --git a/AACT_downloader/ClinicalTrialHistory/docker-entrypoint-initdb.d/090_AnalysisViews.sql b/AACT_downloader/docker-entrypoint-initdb.d/090_AnalysisViews.sql similarity index 100% rename from AACT_downloader/ClinicalTrialHistory/docker-entrypoint-initdb.d/090_AnalysisViews.sql rename to AACT_downloader/docker-entrypoint-initdb.d/090_AnalysisViews.sql diff --git a/AACT_downloader/readme.md b/AACT_downloader/readme.md deleted file mode 100644 index 89ff05e..0000000 --- a/AACT_downloader/readme.md +++ /dev/null @@ -1 +0,0 @@ -This is what is needed to setup the database. diff --git a/history_downloader/db_connection.py b/history_downloader/db_connection.py index 3a85f92..02fe828 100644 --- a/history_downloader/db_connection.py +++ b/history_downloader/db_connection.py @@ -8,7 +8,7 @@ conn = psyco.connect(dbname="aact_db", user="root", host="will-office", password curse = conn.cursor() -curse.execute("select * FROM http.responses LIMIT 100;") +curse.execute("select nct_id FROM ctgov.studies LIMIT 10;") print(curse.fetchall()) curse.close()