-
Notifications
You must be signed in to change notification settings - Fork 0
Fix pk sequence value update when negative pk values are in use #51
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix pk sequence value update when negative pk values are in use #51
Conversation
Coverage Report Results
1 empty file skipped. |
d942807 to
faa4e62
Compare
a589f56 to
3d22d07
Compare
faa4e62 to
b6346a5
Compare
marcelofern
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good. One comment for consideration
tests/test_repack.py
Outdated
| @pytest.mark.xfail( | ||
| raises=NumericValueOutOfRange, | ||
| reason=""" | ||
| E psycopg.errors.NumericValueOutOfRange: integer out of range | ||
| E CONTEXT: SQL function "psycopack_repacked_6723301_fun" statement 1 | ||
| E SQL statement "SELECT "public"."psycopack_repacked_6723301_fun"(NEW."id", NEW."id")" | ||
| E PL/pgSQL function psycopack_repacked_6723301_tgr() line 4 at PERFORM | ||
| """, | ||
| ) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm wondering what happens here for other different types of primary keys and if the code handles them. I.e., if we parametrise the test like this:
@pytest.mark.parametrize(
"initial_pk_type",
(
"integer",
"serial",
"smallint",
"smallserial",
),
)Thoughts?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added another commit to cover the above. With slight adjustment to a test factory, the code handles all these PK types.
3d22d07 to
f7314da
Compare
…nstraint Disallow deferrable unique constraints
5384935 to
652f9e0
Compare
If the table is being converted to a bigint pk and the pk sequence has been set to negative, we want to reset the sequence value to 2**31 so that it can start using the new bigint range (and not run out of negative values when the sequence advances to 1).
Previously that reset was done in the
swapstage. But that led to errors, since the old table was being updated by a trigger, and it only had an integer pk.This change moves the sequence reset to the
clean_upstage after the trigger has been dropped, which fixes the bug. The change also ensures that the sequence on the new table has the same min value as the old sequence (which could be negative).Fixes #49