title: Firebase token structure and storage
body: <p>An FCM token is in the format of </p>
  
  <pre><code>fKk623mCfkm4:APA21bG2PqYzjxkwVElcODnMdTk9BP1AoNw-
  rogg8uUdK9lzIc0Ow0KVa_19PRZE85v_0VZjBPBve4PAwqX9mVstr
  o2fnzWoChgOVdIRU0YvOMRniOwg-KGB5EjajqD3Szl2lBwPZQBJ
  </code></pre>
  
  <p>Which is fairly long.</p>
  
  <p>If one wants to store the token in MySQL and make sure that the token is unique, how would one go about doing that? I reckon the string is a bit too long to index. Is it reasonable to assume that the part before the colon (in this case <code>fKk623mCfkm4</code>) is unique within the scope of the application? If so this would be a much more reasonable way to index the token. (Just VARCHAR still, but with <code>CREATE UNIQUE INDEX fcm_token ON myTable myColumn(12)</code>)</p>
  
  <p>I realize that that may be long shot, so: How would one solve this problem?</p>
  
  <p>I am interested in the uniqueness of the token because a device might change owner (or user, for whatever reason) which would require that the token is reassigned in my database - but that's hard (irresponsible) if I cannot find it because it's not indexed.</p>
  
  <p><strike>A string of 12 alphanumeric characters may produce 5.906682292E37 different results. That kind of randomness seems like it would be enough to avoid a collision within a single application.</strike> Edit: Bad idea.</p>
  
  <p>I am doing this currently:</p>
  
  <pre><code>CREATE TABLE `devices` (
   `ID` int(10) unsigned NOT NULL AUTO_INCREMENT,
   `USER` int(10) unsigned NOT NULL,
   `TOKEN` varchar(255) NOT NULL,
   `TOKENSHA1` binary(20) DEFAULT NULL,
   `MODIFIED` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
   PRIMARY KEY (`ID`),
   UNIQUE KEY `TOKENSHA1` (`TOKENSHA1`),
   KEY `USER` (`USER`),
   KEY `MODIFIED` (`MODIFIED`)
  ) ENGINE=InnoDB
  </code></pre>