xebia-functional/nine-cards-v2

Check this error when user logs in:

anamariamv opened this issue · 1 comments

ERROR: duplicate key value violates unique constraint "users_pkey"
Detail: Key (id)=(2) already exists.

This kind of error is rooted at Postgresql handling of serial types. It arises when a row is created using a value for the serial column larger than the latest used value.

This error can be reproduced in the localhost db as follows:

  • Start an sbt session with the localhost.conf file, and execute flywayClean and flywayMigrate to reset the database.
  • Start a psql session with the ninecards_user user into the ninecards DB.
  • In psql, execute the following commands:
insert into users(id,email,sessiontoken,apikey) values (2,'a','a','a') ; 
insert into users(email,sessiontoken,apikey) values ('b','b','b') ; 
insert into users(email,sessiontoken,apikey) values ('b','b','b') ; 

Once the error appears, the next insertion proceeds normally. This error should not normally occur, since the only insertions to this tables are through the signup operation. Nevertheless, some solutions are proposed here.