Skip to content

Commit

Permalink
Add pgloader bash script to port TCR SQLite DB (#2471)
Browse files Browse the repository at this point in the history
* Support pgsql infra

* Make infra work with next

* Remove dev win

* The real dev win fix

* add bash script

* update load script to add sqlite db

* update docker compose file to include loading the data

* cleanup

* [pre-commit.ci] auto fixes from pre-commit hooks

* add chmod cmd

* [pre-commit.ci] auto fixes from pre-commit hooks

* typo

* remove temp code

---------

Co-authored-by: bamader <[email protected]>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
  • Loading branch information
3 people committed Sep 4, 2024
1 parent c30b241 commit 34e293c
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 0 deletions.
10 changes: 10 additions & 0 deletions containers/tefca-viewer/docker-compose-dev.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,13 @@ services:
interval: 2s
timeout: 5s
retries: 20
load_tcr_data:
image: "postgres:alpine"
depends_on:
db:
condition: service_healthy
volumes:
- "./tefca.env:/tefca.env"
- "./load_tcr_data.sh:/load_tcr_data.sh"
entrypoint:
["/bin/sh", "-c", "chmod +x /load_tcr_data.sh && /load_tcr_data.sh"]
41 changes: 41 additions & 0 deletions containers/tefca-viewer/load_tcr_data.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#!/bin/bash

source tefca.env

# Define the database connection
PG_CONN="postgresql://postgres:pw@db:5432/tefca_db"

tables=("concepts" "valuesets" "conditions")

# Function to check if tables contain data
check_tables() {
for table in "${tables[@]}"; do
count=$(psql "$PG_CONN" -c "SELECT COUNT(*) FROM $table;" -tA)
if [ "$count" -eq 0 ]; then
return 1
fi
done
return 0
}

# Check if the tables contain data
check_tables
if [ $? -ne 0 ]; then
echo "Tables are empty. Proceeding with data loading..."

# Install pgloader if not already installed
if ! command -v pgloader &> /dev/null; then
echo "Installing pgloader..."
apk add --no-cache pgloader
fi

# Download the ERSD SQLite file
echo "Downloading ERSD SQLite file..."
wget -O /tmp/ersd.db https://github.com/CDCgov/phdi/raw/main/containers/trigger-code-reference/seed-scripts/ersd.db

echo "Loading data into PostgreSQL..."
pgloader sqlite://tmp/ersd.db "$PG_CONN"

echo "Successfully loaded TCR data into tefca_db"

fi

0 comments on commit 34e293c

Please sign in to comment.