Skip to content

Add mismatched sequence size check#242

Open
hlascelles wants to merge 1 commit into
gregnavis:masterfrom
hlascelles:add-mismatched-sequence-check
Open

Add mismatched sequence size check#242
hlascelles wants to merge 1 commit into
gregnavis:masterfrom
hlascelles:add-mismatched-sequence-check

Conversation

@hlascelles

Copy link
Copy Markdown

In Postgres, sequences can be of different sizes, for example, integer and bigint. There is essentially no reason ever to have a sequence that will have a smaller size than the primary key that it is vending IDs for.

This PR adds a check to make sure that the sequence type matches that of the primary key ID column. Without it, a user may have a database column, which is bigint, and a sequence which is integer and will overflow unexpectedly.

Note here the AS integer line.

Bad:

CREATE SEQUENCE public.id_seq
    AS integer
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE

Good:

CREATE SEQUENCE public.id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE

In Postgres, sequences can be of different sizes, for example, `integer` and `bigint`. There is essentially no reason ever to have a sequence that will have a smaller size than the primary key that it is vending IDs for.

This PR adds a check to make sure that the sequence type matches that of the primary key ID column. Without it, a user may have a database column, which is `bigint`, and a sequence which is `integer` and will overflow unexpectedly.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant