Skip to content

[Feature]: Helper to mint UUID v7 identifiers for new data #469

In review

Description

@antoineatsoprasteria

What type of issue is this?

  • Bug report
  • Feature request

Prerequisites

  • I have written a descriptive issue title
  • I have verified that I am running the latest version of the SysML2.NET
  • I have searched open and closed issues to ensure it has not already been reported

Description

Provide one helper that mints a UUID version 7, so that consumers creating new data use time-ordered identifiers without each writing their own.

SysML2.NET.Dal is designed for time-ordered keys (doc/SQLSCHEMA-GUIDE.md §13, audit finding R8): the schema sets uuidv7() defaults on PostgreSQL 18 and names Guid.CreateVersion7() as the primary id source. A v7 identifier turns each project's inserts from random b-tree pages into rightmost-leaf appends, in data_identity and in every index that carries an element identifier. Element identifiers are minted by client tools when they create elements, so the SDK is where a common helper belongs.

Identifier versions

Systems Modeling API and Services §7.1.1 requires Record.id to conform to RFC 4122 (§3 [UUID]), and §7.1.2 sets DataVersion.id to "a new, randomly generated UUID".

  • DataVersion.id is version 4, as §7.1.2 asks.
  • Every other identifier is version 7: element identifiers (Data.getId(), hence DataIdentity.id), Project, Commit, Branch, Tag, and the schema's internal derived_id. RFC 9562 obsoletes RFC 4122, keeps its layout and variant, and defines version 7.
  • Standard-library elements keep their name-based version 5 identifiers (KerML §9.1, SysML §9.1).

Scope:

  • A public helper (e.g. Identifier.NewId()) returning a version 7 Guid:
    • net10.0: Guid.CreateVersion7();
    • netstandard2.1, which has no Guid.CreateVersion7(): a local RFC 9562 §5.7 implementation, without a package dependency — a 48-bit big-endian Unix timestamp in milliseconds, 74 random bits from RandomNumberGenerator, the version bits 0111 and the variant bits 10.
  • An extension that gives a new element its identifier, setting Id and ElementId to the same value, usable on both the DTO and the POCO IElement.
  • Every identifier the SDK mints, other than DataVersion.id, uses the helper:
    • SysML2.NET/PSM/DTO/Mapping/CommitRequest.Mapping.cs (ToPimWithChange): the commit identifier; the DataVersion identifiers stay Guid.NewGuid(), which is version 4 on both targets;
    • SysML2.NET.Semantics/Implied/ImpliedRelationshipFactory.cs: the implied Subclassification, Subsetting, Feature and FeatureChaining identifiers.
  • The SQL schema mints DataVersion.id as version 4. element_version.version_id is DataVersion.id for elements and, through the composite FK, for the ExternalData, ExternalRelationship and ProjectUsage records (§7b); the PG18 block currently defaults it to uuidv7().
    • SysML2.NET.CodeGenerator/Templates/Uml/core-sql-schema.hbs: remove element_version.version_id from the PG18 DO block (§12) and declare DEFAULT gen_random_uuid() on the column in §5 (built in since PostgreSQL 13, so no version guard); keep uuidv7() on derived_version.derived_id, project.id, commit.id, branch.id and tag.id; correct the block's header comment, which states that every server-minted key is time-ordered.
    • SysML2.NET.CodeGenerator.Tests/Sql/schema.golden.sql: regenerate.
    • doc/SQLSCHEMA.md, finding R8: version_id is version 4; derived_id stays version 7.
    • doc/SQLSCHEMA-GUIDE.md: §8.1 (the version_id design note), §13 (the self-activating uuidv7() defaults bullet and the UUIDv7 bullet, both of which name version_id and Guid.CreateVersion7() as its source), §19 glossary (the UUID v4 / v5 / v7 entry).

Byte order trap on netstandard2.1. RFC 9562 lays the 16 bytes out big-endian, while System.Guid stores its first three fields (int, short, short) little-endian, and netstandard2.1 has no new Guid(bytes, bigEndian: true). Passing the RFC byte array to new Guid(byte[]) yields a Guid whose textual form is not a v7 (the version nibble is misplaced) and whose timestamp no longer leads the bytes a database driver writes, which loses the index locality the helper exists for. The implementation must either reverse bytes 0–3, 4–5 and 6–7 before calling new Guid(byte[]), or build the Guid through the Guid(int, short, short, byte[]) constructor from the timestamp fields.

A test should cover it on both targets: the textual form carries 7 as the version digit and the variant 8–b, the first 12 hexadecimal digits are the generation timestamp in milliseconds, and identifiers minted at increasing milliseconds sort in creation order both as text and as Guid.

The R8 locality gain no longer applies to element_version, the largest table: its inserts go back to random positions within each project's range of the (project_id, version_id) index. The planned UUIDv4-vs-v7 A/B in doc/SQLSCHEMA.md measures this cost.

Out of scope:

  • Assigning an identifier in the constructors of the DTOs and POCOs. Guid.Empty, and null on the optional @id of the PSM requests, is how a deserializer, a mapping or a server tells that no identifier was given; a default would hide a payload sent without @id and spend an identifier on every object that is only read.
  • Monotonic ordering within one millisecond, which Guid.CreateVersion7() does not guarantee either.
  • Standard-library elements, which keep their name-based version 5 identifiers.

A v7 identifier embeds its creation time to the millisecond, which anyone who can read the identifier can recover.

Steps to Reproduce

N/A (feature request).

System Configuration

  • SysML2.NET version: 0.27.1
  • Environment (Operating system, version and so on): any
  • .NET Framework version: netstandard2.1, net10.0
  • Additional information: none

Activity

  1. added a commit that references this issue on Dec 3, 2026
    08eee3d
  2. linked a pull request that will close this issueFix #469: Moved to V7 guid #470on Dec 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions