awips2/deltaScripts/13.4.1/createPluginDataObjectSequences.sh
Brad Gonzales 2c2f7f7edf Issue #1857 Added sequence generator annotation to PluginDataObject concrete classes.
Amend: comment updates from peer review.
       added sequence delta script.

Change-Id: Id8685fa0790926564d5d575e43a3da24db27dcf1

Former-commit-id: c7318522e1 [formerly 005c935be6] [formerly dc37712fda] [formerly b75ef08190 [formerly dc37712fda [formerly 562c9fa0341d0fb351adb8e57c14f1ce0bc59c95]]]
Former-commit-id: b75ef08190
Former-commit-id: a9e91f46554d9caefb1866f0820680559c325801 [formerly 16f030294d]
Former-commit-id: a21b495206
2013-04-16 14:44:06 -05:00

28 lines
1.1 KiB
Bash

#!/bin/bash
# DR #1857 - this update script will create sequences for the metadata database.
# No arguments are passed to this script. It reads sequences.txt from the local directory.
PSQL="/awips2/psql/bin/psql"
_sequences_txt=sequences.txt
echo "INFO: Creating sequences."
for sequence in `cat ${_sequences_txt}`;
do
table=${sequence%%seq}
echo "INFO: Creating sequence ${sequence} for table ${table}"
##To start sequence with (current max id + 1 ), uncomment the next two lines.
#sequenceStart=`${PSQL} -tU awips -d metadata -c "SELECT max(id) FROM ${table};" | tr -d '\n' | tr -d ' '`
#let sequenceStart=${sequenceStart}+1
${PSQL} -U awips -d metadata -c "CREATE SEQUENCE ${sequence} INCREMENT 1 MINVALUE 1 MAXVALUE 9223372036854775807 CACHE 1 START ${sequenceStart:=1};"
${PSQL} -U awips -d metadata -c "ALTER TABLE ${sequence} OWNER TO awips;"
if [ $? -ne 0 ]; then
echo "ERROR: Failed to create sequence ${sequence}."
echo "FATAL: The update has failed."
exit 1
fi
done
echo "INFO: sequence creation has completed successfully!"
exit 0