From e8cc923232b81d2dcbae7e0503d8a704bc878aed Mon Sep 17 00:00:00 2001 From: vegardrs Date: Wed, 10 Jul 2024 16:10:21 +0200 Subject: [PATCH] modified: IMOMaritimeSingleWindow/Server/populate_db.sh --- IMOMaritimeSingleWindow/Server/populate_db.sh | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/IMOMaritimeSingleWindow/Server/populate_db.sh b/IMOMaritimeSingleWindow/Server/populate_db.sh index 6004770c..612b06ce 100755 --- a/IMOMaritimeSingleWindow/Server/populate_db.sh +++ b/IMOMaritimeSingleWindow/Server/populate_db.sh @@ -6,15 +6,23 @@ # export PGDATABASE="db-imo-msw-dev-1" # export PGPORT=5432 -echo "Eduard Begin" +# echo "Eduard Begin" # Count the tables in the 'public' schema +BACKEND_LOG="./backend.log.json" + TABLE_COUNT=$(psql -h $PGHOST -U $PGUSER -d $PGDATABASE -p $PGPORT -t -c "SELECT COUNT(*) FROM information_schema.tables WHERE table_schema = 'public';" 2>&1) -echo "$TABLE_COUNT" -echo "Finished" +# echo "$TABLE_COUNT" +# echo "Finished" # Check if there are any tables if [ "$TABLE_COUNT" -ne 0 ]; then - echo "Database is already populated. Exiting script." + echo '{ + "/message": "Database is already populated. Exiting script." + } ' > $BACKEND_LOG + else # If no tables, run your SQL script + echo '{ + "/message": "Running script to populate database." + } ' > $BACKEND_LOG psql -h $PGHOST -U $PGUSER -d $PGDATABASE -p $PGPORT -f /workspaces/backend/SqlScripts/Create_and_populate_DB.sql fi