Bug Description
Schema Diff generates an ALTER SEQUENCE that PostgreSQL refuses whenever the new MINVALUE is above the value the target sequence currently sits at.
Comparing a source sequence declared START 3 MINVALUE 3 against a target sitting at 1 produces:
ALTER SEQUENCE IF EXISTS test_schema_diff.seq_start_diff
START 3
MINVALUE 3;
which fails with:
ERROR: RESTART value (1) cannot be less than MINVALUE (3)
PostgreSQL will not leave a sequence positioned outside its own bounds, so raising MINVALUE past the current value (or, symmetrically, lowering MAXVALUE below it) is only accepted when the same statement also repositions the sequence with RESTART. pgAdmin never adds one, so the change cannot be applied at all: the statement is rejected as a whole, and the rest of the sequence's differences go with it.
The same applies to editing a sequence in the dialog, since both paths render sequences/sql/default/update.sql.
Expected Behaviour
Where the new bounds would exclude the sequence's current value, the generated statement should reposition the sequence onto the nearest legal value, e.g.
ALTER SEQUENCE IF EXISTS test_schema_diff.seq_start_diff
START 3
MINVALUE 3
RESTART 3;
Where the current value is already within the new bounds, nothing should change: repositioning a sequence that does not need it would hand out values that have already been used.
Context
Found by making the Schema Diff regression test assert that the SQL it generates actually applies (#10293).
Bug Description
Schema Diff generates an
ALTER SEQUENCEthat PostgreSQL refuses whenever the newMINVALUEis above the value the target sequence currently sits at.Comparing a source sequence declared
START 3 MINVALUE 3against a target sitting at 1 produces:which fails with:
PostgreSQL will not leave a sequence positioned outside its own bounds, so raising
MINVALUEpast the current value (or, symmetrically, loweringMAXVALUEbelow it) is only accepted when the same statement also repositions the sequence withRESTART. pgAdmin never adds one, so the change cannot be applied at all: the statement is rejected as a whole, and the rest of the sequence's differences go with it.The same applies to editing a sequence in the dialog, since both paths render
sequences/sql/default/update.sql.Expected Behaviour
Where the new bounds would exclude the sequence's current value, the generated statement should reposition the sequence onto the nearest legal value, e.g.
Where the current value is already within the new bounds, nothing should change: repositioning a sequence that does not need it would hand out values that have already been used.
Context
Found by making the Schema Diff regression test assert that the SQL it generates actually applies (#10293).