-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add pgloader bash script to port TCR SQLite DB (#2471)
* 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
1 parent
c30b241
commit 34e293c
Showing
2 changed files
with
51 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |