Change-Id: I421aed1572c10c80a592381c849d85eac8d1e809 Former-commit-id:16d01f1ca7
[formerly562e85e45b
] [formerlye6feb413f7
] [formerly16d01f1ca7
[formerly562e85e45b
] [formerlye6feb413f7
] [formerly059e057cdb
[formerlye6feb413f7
[formerly 88918268a6d72d35dd2f19be09fbb429851fe46b]]]] Former-commit-id:059e057cdb
Former-commit-id:f58034617d
[formerlyd4236a7fc0
] [formerly eb6b4892671bdfa9f3570ac483b6bc6a075ba84b [formerlybc2f099cc6
]] Former-commit-id: 20d520612f8768a8f88dbd545ab39da3abd62969 [formerly47f20fb577
] Former-commit-id:31ce99c9f1
42 lines
1.5 KiB
Bash
42 lines
1.5 KiB
Bash
#!/bin/bash
|
|
# DR #2581 - this update script will drop the dataURI column from the lsr 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
|
|
}
|
|
|
|
|
|
|
|
# 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
|
|
${PSQL} -U awips -d metadata -c "VACUUM FULL ANALYZE $1"
|
|
}
|
|
|
|
echo "INFO: Dropping dataURI columns."
|
|
|
|
dropDatauriAndAddConstraint lsr lsr_latitude_longitude_officeId_reftime_forecasttime_eventtype_key "(latitude, longitude, officeId, reftime, forecasttime, eventtype)"
|
|
|
|
|
|
echo "INFO: LSR dataURI column dropped successfully"
|