Skip to content

Commit

Permalink
Created a separate validations cleanup script and added instructions …
Browse files Browse the repository at this point in the history
…in Readme file
  • Loading branch information
rishi-salunkhe-mettle committed Aug 5, 2024
1 parent f48b778 commit 5acbddc
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 2 deletions.
10 changes: 8 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -375,9 +375,15 @@ Change directory to the /scripts inside lantern-back-end and run:
./history_cleanup.sh
```
Note: Ensure that the duplicateInfoHistoryIds.csv file is present in /lantern-back-end before executing this script.
This will start the deletion of data from fhir_endpoints_info_history table using the captured identifiers of repetitive entries.
This will start the deletion of data from fhir_endpoints_info_history, validations and validation_results tables using the captured identifiers of repetitive entries.
```bash
./validations_cleanup.sh
```
This will start the deletion of data from validations and validation_results tables using the captured identifiers of repetitive entries.
Note: Ensure that the duplicateInfoHistoryIds.csv file is present in /lantern-back-end before executing the above scripts.
# Running Lantern Services Individually
Expand Down
52 changes: 52 additions & 0 deletions scripts/validations_cleanup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#!/bin/sh

csv_file="../duplicateInfoHistoryIds.csv"
DB_NAME=lantern
DB_USER=lantern

# Check if the file exists
if [ ! -f "$csv_file" ]; then
echo "File $csv_file not found!"
exit 1
fi

# Initial a variable that will hold the validation_result_id from the previous entry.
VAL_RES_ID=-1

while IFS=',' read -r col1 col2 col3 col4; do

# If the validation_result_id is not 0 and not already processed, then perform the deletion
if [ "${col4}" -ne "0" ] && [ "${VAL_RES_ID}" -ne "${col4}" ]; then

VAL_RES_ID=$col4

# Check whether there are entries in the history table having the given validation_result_id and operation = 'I'
QUERY=$(echo "SELECT COUNT(*) FROM fhir_endpoints_info_history WHERE operation='I' AND validation_result_id='$col4';")
COUNT=$(docker exec -t lantern-back-end_postgres_1 psql -t -U${DB_USER} -d ${DB_NAME} -c "${QUERY}") || echo "Error counting entries from the history table"

# Delete corresponding entries from the validations and validation_results tables ONLY IF the count is zero.
NUMBER=$(echo ${COUNT} | tr -cd '[[:digit:]]')
if [ "${NUMBER}" -eq "0" ]; then
echo "($(date)) Deleting entries from the validations table for validation_result_id: $col4"

# Delete corresponding entry from the validations table
QUERY=$(echo "DELETE FROM validations WHERE validation_result_id = '$col4';")
(docker exec -t lantern-back-end_postgres_1 psql -t -U${DB_USER} -d ${DB_NAME} -c "${QUERY}") || echo "Error deleting entry from the validations table"

# Check whether there are entries in the info table having the given validation_result_id
QUERY=$(echo "SELECT COUNT(*) FROM fhir_endpoints_info WHERE validation_result_id='$col4';")
COUNT=$(docker exec -t lantern-back-end_postgres_1 psql -t -U${DB_USER} -d ${DB_NAME} -c "${QUERY}") || echo "Error counting entries from the validation_results table"

# Delete corresponding entry from the validation results table ONLY IF the count is zero.
NUMBER=$(echo ${COUNT} | tr -cd '[[:digit:]]')
if [ "${NUMBER}" -eq "0" ]; then
echo "($(date)) Deleting entries from the validation_results table for id: $col4"

QUERY=$(echo "DELETE FROM validation_results WHERE id = '$col4';")
(docker exec -t lantern-back-end_postgres_1 psql -t -U${DB_USER} -d ${DB_NAME} -c "${QUERY}") || echo "Error deleting entry from the validation_results table"
fi
fi
fi
done < "$csv_file"

echo "Validation data cleanup complete."

0 comments on commit 5acbddc

Please sign in to comment.