Skip to content

Instantly share code, notes, and snippets.

@tiensonqin
Last active August 29, 2015 14:17
Show Gist options
  • Save tiensonqin/52ad79c91be738f04f8a to your computer and use it in GitHub Desktop.
Save tiensonqin/52ad79c91be738f04f8a to your computer and use it in GitHub Desktop.
# generate a new flake ID
SELECT ((FLOOR((UNIX_TIMESTAMP(NOW(3)) - 946702800) * 1000)) << 23) | ROUND((RAND() * 4194303));
# replace auto increment IDs with flake IDs based on updateAt column
UPDATE ids SET id = (SELECT ((FLOOR(((ids.createdAt + 0.000) - 946702800) * 1000)) << 23) | ROUND((RAND() * 4194303)));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment