Which data type for SemVer version number?


I produce software packages. I’d like each software package to include a list of previous versions along with the change notes.

I would like to sort these from newest to oldest, ideally by version number.
SemVer versioning is as follows: Major.Minor.Patch.
When attempting to store it as a single number field, I get an error.


If I store it as a text field, I believe that I would not be able to sort it.

What would you recommend to record this data? Three separate fields for Major, Minor, and Patch number? Can I sort along all 3?


I can think of three ways to do this;

  1. Separate the semver into distinct fields, and sort your collection list on each of those 3 parts ( first major, then minor, then patch ).

  2. Combine those into a sortkey ( string ) field, where you’ve padded it for sorting, e.g., and sort on that sortkey field.

  3. Ditch all that, and sort the results afterwards using script.

I have a sort function here, which handles semvers.
However it’s a numeric-only implementation.

Thanks! I think sorting by distinct fields works best for my use case since it is also supported in the CMS browser. I appreciate your help!