DevToys-app / DevToys

A Swiss Army knife for developers.
https://devtoys.app/
MIT License
27.27k stars 1.46k forks source link

UUID v7 support please #1238

Closed oliver-sturrock closed 4 months ago

oliver-sturrock commented 4 months ago

What improvement do you think would an existing feature or tool in DevToys?

We are transitioning to V7 UUIDs for better indexing in database primary keys. V7 UUIDs are the same format as V4 but use microseconds since epoch for the first 48 bits giving time-ordered creation sequence and improved partitioning when used as keys.

Solution/Idea

Add UUID v7 to the version dropdown and use a UUID generator function that supports V7 to generate.

Comments

No response

niyari commented 4 months ago

WIP image

niyari commented 4 months ago

@oliver-sturrock https://github.com/DevToys-app/DevToys.Tools/pull/45

The value of rand_a is a random number, not a ticks value or a counter value. https://datatracker.ietf.org/doc/html/rfc9562#monotonicity_counters

oliver-sturrock commented 4 months ago

Agreed, but section 5.7 states that "UUIDv7 values are created by allocating a Unix timestamp in milliseconds in the most significant 48 bits and filling the remaining 74 bits, excluding the required version and variant bits, with random bits for each new UUIDv7 generated to provide uniqueness as per Section 6.9. Alternatively, implementations MAY fill the 74 bits, jointly, with a combination of the following subfields, in this order from the most significant bits to the least, to guarantee additional monotonicity within a millisecond", so both monotonicity and usable millisecond-accurate timestamps are achieved.

niyari commented 4 months ago

At the moment, DevToys' UUIDTool repeats a single output n times without considering the number of pieces needed. What changes would you suggest be made in adding UUIDv7? I think there are a few ways.

Additional information is needed, such as the environment in which DevToys is running, and how the output UUID will be used.

oliver-sturrock commented 4 months ago

Being able to provide many UUIDs per ms shouldn't be a problem, since there is still a random part that should ensure uniqueness. It would be good if the output were monotonically increasing in value. Can you generate and sort?

My use case is for creating UUIDs during development of test data, but there may be other uses I didn't think about.

niyari commented 4 months ago

Thanks. As for sorting the UUIDs, this can be solved by using this tool in combination with a text analyzer tool.

https://github.com/DevToys-app/DevToys/assets/2970321/63365f93-44a9-4f61-882c-49f1fca09a0c