awips2/deltaScripts/14.2.1/dropVAAdataURI.sh
Nate Jensen 74c0067901 Issue #2582 Fix decoding where OBS DTG are on separate lines, cleanup
VAA and remove dataURI

Change-Id: I984173a6e85eb7dc269fb98964af4915a9b5105e

Former-commit-id: 77c23c6d0e [formerly 9b3f871c21] [formerly 6bf1fd8d3c] [formerly 77c23c6d0e [formerly 9b3f871c21] [formerly 6bf1fd8d3c] [formerly 72c322c667 [formerly 6bf1fd8d3c [formerly 148e7113abefd684dcacb5ccc28bb77192ff45c8]]]]
Former-commit-id: 72c322c667
Former-commit-id: a25621ae6d [formerly 476f9da5ad] [formerly 58b83a2d53b306277cdc9a0820852147a2519f74 [formerly 2831ceb356]]
Former-commit-id: f8fdfa9a908f980ca803296046b6496e1b85e6e3 [formerly cbd12d4cc7]
Former-commit-id: da9d1b2447
2013-12-02 16:10:26 -06:00

53 lines
1.9 KiB
Bash

#!/bin/bash
# DR #2582 - this update script will drop the dataURI column from the vaa table
PSQL="/awips2/psql/bin/psql"
# takes one arg: a table name
# drops the datauri constraint and column if they exist
function dropDatauri {
echo "INFO: Dropping DataURI column from $1"
${PSQL} -U awips -d metadata -c "ALTER TABLE $1 DROP CONSTRAINT IF EXISTS ${1}_datauri_key;"
${PSQL} -U awips -d metadata -c "ALTER TABLE $1 DROP COLUMN IF EXISTS datauri;"
if [ $? -ne 0 ]; then
echo "ERROR: Failed to drop dataURI column for $table"
echo "FATAL: The update has failed."
exit 1
fi
}
function dropRecordType {
echo "INFO: Dropping recordType column from $1"
${PSQL} -U awips -d metadata -c "ALTER TABLE $1 DROP COLUMN IF EXISTS recordtype;"
if [ $? -ne 0 ]; then
echo "ERROR: Failed to drop recordType column for $table"
echo "FATAL: The update has failed."
exit 1
fi
}
# takes three args: table, constraint name, unique columns
# will first drop the constraint if it exists and then adds it back, this is
# fairly inefficient if it does exist but operationally it won't exist and for
# testing this allows the script to be run easily as a noop.
function dropDatauriAndAddConstraint {
dropDatauri $1
${PSQL} -U awips -d metadata -c "ALTER TABLE $1 DROP CONSTRAINT IF EXISTS $2;"
dropRecordType $1
${PSQL} -U awips -d metadata -c "ALTER TABLE $1 ADD CONSTRAINT $2 UNIQUE $3;"
if [ $? -ne 0 ]; then
echo "ERROR: Failed to add new unique constraint for $table"
echo "FATAL: The update has failed."
exit 1
fi
${PSQL} -U awips -d metadata -c "VACUUM FULL ANALYZE $1"
}
echo "INFO: Dropping dataURI columns."
dropDatauriAndAddConstraint vaa vaa_latitude_longitude_stationId_reftime_forecasttime_advisoryNumber_key "(latitude, longitude, stationId, reftime, forecasttime, advisoryNumber)"
echo "INFO: VAA dataURI column dropped successfully"