From 644f2617e7e779e93db3bba20ae734f193f6e30c Mon Sep 17 00:00:00 2001 From: noctarius aka Christoph Engelbert Date: Mon, 12 Sep 2022 16:17:49 +0200 Subject: [PATCH] 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) --- src/pgsql/pgsql-create-schema.lisp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/pgsql/pgsql-create-schema.lisp b/src/pgsql/pgsql-create-schema.lisp index 938e875..0a41bf1 100644 --- a/src/pgsql/pgsql-create-schema.lisp +++ b/src/pgsql/pgsql-create-schema.lisp @@ -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