2013-05-13 14:49:13 -05:00
|
|
|
#!/bin/bash
|
|
|
|
# DR #1869 - this update script will drop the dataURI column from all tables
|
|
|
|
# where it is no longer needed.
|
|
|
|
|
|
|
|
PSQL="/awips2/psql/bin/psql"
|
|
|
|
|
2013-05-14 18:13:44 -05:00
|
|
|
# takes one arg: a table name
|
|
|
|
# drops the datauri constraint and column if they exist
|
|
|
|
function dropDatauri {
|
|
|
|
echo "INFO: Dropping DataURI column from $1"
|
2013-05-15 11:45:51 -05:00
|
|
|
${PSQL} -U awips -d metadata -c "ALTER TABLE $1 DROP CONSTRAINT IF EXISTS ${1}_datauri_key;"
|
2013-05-14 18:13:44 -05:00
|
|
|
${PSQL} -U awips -d metadata -c "ALTER TABLE $1 DROP COLUMN IF EXISTS datauri;"
|
2013-05-13 14:49:13 -05:00
|
|
|
if [ $? -ne 0 ]; then
|
|
|
|
echo "ERROR: Failed to drop dataURI column for $table"
|
|
|
|
echo "FATAL: The update has failed."
|
|
|
|
exit 1
|
|
|
|
fi
|
2013-05-14 18:13:44 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
# 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;"
|
|
|
|
${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
|
2013-05-15 11:45:51 -05:00
|
|
|
${PSQL} -U awips -d metadata -c "VACUUM FULL $1"
|
2013-05-14 18:13:44 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
echo "INFO: Dropping dataURI columns."
|
|
|
|
|
|
|
|
dropDatauri gfe
|
2013-05-15 11:45:51 -05:00
|
|
|
${PSQL} -U awips -d metadata -c "VACUUM FULL gfe"
|
2013-05-14 18:13:44 -05:00
|
|
|
dropDatauriAndAddConstraint bufrmosavn bufrmosavn_location_id_reftime_forecasttime_key "(location_id, reftime, forecasttime)"
|
|
|
|
dropDatauriAndAddConstraint bufrmoshpc bufrmoshpc_location_id_reftime_forecasttime_key "(location_id, reftime, forecasttime)"
|
|
|
|
|
|
|
|
echo "INFO: dataURI columns dropped successfully"
|