awips2/deltaScripts/13.4.1/updateWarningTables.sh
Richard Peter 6caff6bdf6 Issue #1951: Integrate warning_ugczone into parent tables and add active table indexes.
Change-Id: Ie3e8b595cf67c6d30047d74e689b2cf9bcd31bea

Former-commit-id: 31a84fb91f [formerly c63a4882e7] [formerly 99391cfe12] [formerly 31a84fb91f [formerly c63a4882e7] [formerly 99391cfe12] [formerly d4135dba62 [formerly 99391cfe12 [formerly 883a51484d03900852ed84820aa559e088c97335]]]]
Former-commit-id: d4135dba62
Former-commit-id: 2813a8fc47 [formerly 43a90c062c] [formerly adfd41ab237c568aeecc21759b668b8afa0b7822 [formerly a02955e40c]]
Former-commit-id: a8522f4158313026efd8946f1eccafa6f78a6ff3 [formerly 81ece036ac]
Former-commit-id: fe2e894307
2013-05-13 17:16:57 -05:00

75 lines
2.1 KiB
Bash

#!/bin/bash
# Main script for updating warning database structure
PSQL="/awips2/psql/bin/psql"
PYTHON="/awips2/python/bin/python"
SQL_SCRIPT="alterWarningTables.sql"
# ensure that the sql script is present
if [ ! -f ${SQL_SCRIPT} ]; then
echo "ERROR: the required sql script - ${SQL_SCRIPT} was not found."
echo "FATAL: the update has failed!"
exit 1
fi
echo "Adding ugczones column to warning tables"
${PSQL} -U awips -d metadata -f ${SQL_SCRIPT}
if [ $? -ne 0 ]; then
echo "FATAL: the update has failed!"
exit 1
fi
TABLES="practicewarning warning"
for table in $TABLES
do
echo
echo "Querying for $table ugc zones"
RETRIEVE_UGC_ZONES_SQL="SELECT parentwarning, zone FROM warning_ugczone where parentwarning in (select id from $table) order by parentwarning, key"
_ugc_zone_txt="${table}UgcZones.txt"
${PSQL} -U awips -d metadata -c "${RETRIEVE_UGC_ZONES_SQL}" -t -o ${_ugc_zone_txt}
if [ $? -ne 0 ]; then
echo "ERROR: Failed to retrieve the ugc zones for $table table."
echo "FATAL: The update has failed."
exit 1
fi
echo
echo "Parsing ugc zones for insertion into $table table"
PYTHON_PARSE_SCRIPT="parseUgcZones.py"
if [ ! -f ${PYTHON_PARSE_SCRIPT} ]; then
echo "ERROR: the required python script - ${PYTHON_PARSE_SCRIPT} was not found."
echo "FATAL: the update has failed!"
exit 1
fi
${PYTHON} ${PYTHON_PARSE_SCRIPT} ${table} ${_ugc_zone_txt}
if [ $? -ne 0 ]; then
echo "ERROR: Failed to parse ugc zones."
echo "FATAL: The update has failed."
exit 1
fi
echo
echo "Adding ugc zones to $table table"
# ${table}UgcZonesUpdates.sql generated from parseParmIds.py
${PSQL} -U awips -d metadata -q -f ${table}UgcZonesUpdates.sql
if [ $? -ne 0 ]; then
echo "ERROR: Failed to add ugc zones."
echo "FATAL: The update has failed."
exit 1
fi
done
#remove warning_ugczone
echo
echo "Dropping warning_ugczone table"
DROP_TABLE_SQL="DROP TABLE warning_ugczone"
${PSQL} -U awips -d metadata -c "${DROP_TABLE_SQL}"
echo
echo "Running full vacuum for warning"
${PSQL} -U awips -d metadata -c "VACUUM FULL VERBOSE ANALYZE warning"