Skip to content

Commit

Permalink
Added support for sequences with minvalue defined
Browse files Browse the repository at this point in the history
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) <[email protected]>
  • Loading branch information
noctarius committed Sep 12, 2022
1 parent 8ff0c57 commit e32066d
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/pgsql/pgsql-create-schema.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit e32066d

Please sign in to comment.