Added support for sequences with minvalue defined (#1429)

When a sequence is defined with a minimum value, and the sequence to migrate is empty, the setval fails due to 1 being the default (which may be lower than the defined minimum value)

Signed-off-by: Christoph Engelbert (noctarius) <me@noctarius.com>
This commit is contained in:
noctarius aka Christoph Engelbert 2022-09-12 16:17:49 +02:00 committed by GitHub
parent 8ff0c574b3
commit 644f2617e7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -408,7 +408,8 @@ BEGIN
|| trim(trailing ')'
from replace(pg_get_expr(d.adbin, d.adrelid),
'nextval', 'setval'))
|| ', (select greatest(max(' || quote_ident(a.attname) || '), 1) from only '
|| ', (select greatest(max(' || quote_ident(a.attname) || '), (select seqmin from pg_sequence where seqrelid = ('''
|| pg_get_serial_sequence(quote_ident(nspname) || '.' || quote_ident(relname), quote_ident(a.attname)) || ''')::regclass limit 1), 1) from only '
|| quote_ident(nspname) || '.' || quote_ident(relname) || '));' as sql
FROM pg_class c
JOIN pg_namespace n on n.oid = c.relnamespace