diff options
Diffstat (limited to 'debian/postgres_update_seqs.sh')
-rwxr-xr-x | debian/postgres_update_seqs.sh | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/debian/postgres_update_seqs.sh b/debian/postgres_update_seqs.sh new file mode 100755 index 0000000..6267615 --- /dev/null +++ b/debian/postgres_update_seqs.sh @@ -0,0 +1,11 @@ +#!/bin/sh +[ -z "$1" -o ! -f "$1" ] && echo "No schema given or schema does not exist." && exit 1 +schema="$1" +for s in $(sed -n 's/^CREATE SEQUENCE \(.\+\);/\1/ p' < $schema); do + for c in $(grep $s $schema | grep nextval | awk '{print $1}'); do +# echo "SELECT MAX($c) FROM ${s#_seq};" +# echo "SELECT nextval('$s');" + echo "ALTER SEQUENCE $s MINVALUE 1;" + echo "SELECT setval('$s', (SELECT MAX($c) FROM ${s%_seq})+1, false);" + done +done |