Attempting to add a new tree fails with an "integer out of range" error. This is due to the createIdForTree function generating ids that are larger the int maximum in Postgres (i.e. -2147483648 to +2147483647). I was able to verify this by hard coding the inserted id. When the id was 2147483647 (i.e. the int max), the insert was successful. However, when the id was 2147483648 (i.e. 1 + the int max). the insert failed.
Recreate the Issue
Sending a POST request to localhost:3002/api/trees when a body of
Why not just store it as a string? It's just an opaque unique identifier, and doesn't need to be treated as an int once it's created, as I understand it.
Context
Attempting to add a new tree fails with an "integer out of range" error. This is due to the createIdForTree function generating ids that are larger the int maximum in Postgres (i.e. -2147483648 to +2147483647). I was able to verify this by hard coding the inserted id. When the id was 2147483647 (i.e. the int max), the insert was successful. However, when the id was 2147483648 (i.e. 1 + the int max). the insert failed.
Recreate the Issue
Sending a POST request to localhost:3002/api/trees when a body of
generates an id of 886478645782219 and has a response of
Possible Solution
We can change the treedata.id column to bigint type, which has a range of -9223372036854775808 to +9223372036854775807.
This resource proposes one method of altering the column type.
Screenshot