awips2/deltaScripts/archived/13.4.1/createPluginDataObjectSequences.sh
Richard Peter 55708f1d55 Issue #2854: Reorganize deltaScripts
Former-commit-id: 09f41a6b31 [formerly 56745c942e] [formerly 09f41a6b31 [formerly 56745c942e] [formerly c8e373c098 [formerly 469c2c597b80fd725f474e0d645656e4054fd69a]]]
Former-commit-id: c8e373c098
Former-commit-id: a526600e3e [formerly e1721cad00]
Former-commit-id: 18b4d133c7
2014-04-30 13:03:44 -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