VAA and remove dataURI Change-Id: I984173a6e85eb7dc269fb98964af4915a9b5105e Former-commit-id:77c23c6d0e
[formerly9b3f871c21
] [formerly6bf1fd8d3c
] [formerly77c23c6d0e
[formerly9b3f871c21
] [formerly6bf1fd8d3c
] [formerly72c322c667
[formerly6bf1fd8d3c
[formerly 148e7113abefd684dcacb5ccc28bb77192ff45c8]]]] Former-commit-id:72c322c667
Former-commit-id:a25621ae6d
[formerly476f9da5ad
] [formerly 58b83a2d53b306277cdc9a0820852147a2519f74 [formerly2831ceb356
]] Former-commit-id: f8fdfa9a908f980ca803296046b6496e1b85e6e3 [formerlycbd12d4cc7
] Former-commit-id:da9d1b2447
53 lines
1.9 KiB
Bash
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"
|