Fix the missing DB entry in Gerrit DB
Due to an unknown reason (still under investigation), a few of the new
LDAP users were not able to login after first time because the Gerrit DB
was missing one of the two entries needed to authenticate the user (the
second entry is only needed for the users with non-null usernames).
The entry with external Id - "gerrit:abc" was never inserted to DB
in such cases whereas the entry with external id - "username:abc" was
created resulting in an account creation for the user.
This causes inconsistency in the DB. An account gets created in first login
attempt and second attempt fails to create missing external id because the
"username:abc" entry already exists causing the DB action to rollback.
As this bug is very infrequent and hard to replicate, this change
provides an after-fix for the issue i.e. fixes the problem when an entry
is missing in Gerrit DB. It checks if there exists an account already
for the given username and links the newly created external ID to that
account. It prevents the need to manually enter the missing entries in
DB to solve the issue.
Bug: Issue 7652