summaryrefslogtreecommitdiff
path: root/debian/postgres_update_seqs.sh
blob: 6267615924740dabd23f6a071382f81fd8cdd401 (plain)
1
2
3
4
5
6
7
8
9
10
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