-
Notifications
You must be signed in to change notification settings - Fork 0
/
create_assertion_formatted_table.sh
executable file
·40 lines (28 loc) · 1.5 KB
/
create_assertion_formatted_table.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#!/bin/bash
# This script creates assertion details from the PostgreSQL database.
# The script is designed to run on a local machine and requires the following:
# - psql (PostgreSQL client) installed on the local machine
# - Access to the PostgreSQL database (host, name, user, and password)
# - .env file in the root directory with values set for $DB_NAME, $DB_HOST, $DB_USER and $DB_PASSWORD
SCRIPT_PARENT_DIR=$( cd "$( dirname "$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" )" && pwd )
ENV_FILE="$SCRIPT_PARENT_DIR/.env"
if [[ ! -f "$ENV_FILE" ]]; then
echo "Error: .env file not found in $SCRIPT_PARENT_DIR, copy the .env.example file to .env and update the values."
exit 1
fi
source "$ENV_FILE"
if [[ -z "$DB_HOST" || -z "$DB_USER" || -z "$DB_NAME" || -z "$DB_PASSWORD" ]]; then
echo "Error: Required environment variables are not set in the .env file"
exit 1
fi
FILE_PATH="$SCRIPT_PARENT_DIR/sql-queries/assertion_details_multiple_queries.sql"
start_time=$(date +%s)
echo "creating assertion details table in the database..."
PGPASSWORD="$DB_PASSWORD" psql -f "$FILE_PATH" -h "$DB_HOST" -U "$DB_USER" -d "$DB_NAME"
echo "assertion details table created successfully."
end_time=$(date +%s)
total_elapsed_time=$((end_time - start_time))
total_hours=$((total_elapsed_time / 3600))
total_minutes=$(( (total_elapsed_time % 3600) / 60 ))
total_seconds=$((total_elapsed_time % 60))
echo "Total time taken by the entire script: $total_hours hours, $total_minutes minutes, and $total_seconds seconds."