Skip to content

Commit

Permalink
modified: IMOMaritimeSingleWindow/Server/populate_db.sh
Browse files Browse the repository at this point in the history
  • Loading branch information
vrsorheim committed Jul 10, 2024
1 parent c41fcb3 commit e8cc923
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions IMOMaritimeSingleWindow/Server/populate_db.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit e8cc923

Please sign in to comment.