summaryrefslogtreecommitdiff
path: root/debian/postgres_update_seqs.sh
diff options
context:
space:
mode:
authorOlivier Gayot <duskcoder@gmail.com>2018-03-12 22:57:42 +0100
committerOlivier Gayot <duskcoder@gmail.com>2018-03-12 22:57:42 +0100
commita8c22829d8e8845cd4ddf4ef8b61a1ed79edfffc (patch)
treef0ae554b863266fbe523582d1be09216436c7472 /debian/postgres_update_seqs.sh
Imported from the SVN repository
http://svn.wolffelaar.nl/wsvn/phpbb/branches/jessie/ Signed-off-by: Olivier Gayot <duskcoder@gmail.com>
Diffstat (limited to 'debian/postgres_update_seqs.sh')
-rwxr-xr-xdebian/postgres_update_seqs.sh11
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