Simplified the DB creation process by running a postgres container directly

llm-extraction
youainti 3 years ago
parent 1bdcc2fd83
commit 9b26cd99df

@ -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

@ -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/

@ -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$

@ -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

@ -1 +0,0 @@
This is what is needed to setup the database.

@ -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()

Loading…
Cancel
Save