I'm setting up the server side of a Google Cloud Messaging mechanism, using MySQL to store the registration ids provided by the mobile app. Giving that Google can issue up to 4k registration ids, I'm forced to store them in a TEXT field. All good so far, the problem is that I have to handle situations like this:
- A user logs into the app
- The app requests a registration id from google
- The app sends the new registration id to the app server
- The server stores that registration id and links it to the user who's currently logged in
- That user logs out and a new user logs in
- The app sends to the server the same registration id as before
- The server must be able to see that the registration id is already in the database but linked to another user
- The server unlinks the registration id from the previous user and links it to the new logged in user
So the problem is that I have to ensure a uniqueness for the registration id in the database but I cannot add a UNIQUE index for that TEXT field.
Possible solutions that I could think of:
- Compute a hash of the registration id and force that hash to be unique, but there could be collisions.
- I could store the unique device id along with the registration id and enforce that device id to be unique. The problem I see is that I don't know how long can be an android device id, and I think that there are some cases where it isn't available.
- I could perform a search every time that a new registration id is received, but I think this would end up in a very poor performance operation.
I'm sure that I'm not the only one facing that problem, but I can't find good solutions out there. Any thoughts on how can I solve this?