Repository navigation
Description
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.idis version 4, as §7.1.2 asks.- Every other identifier is version 7: element identifiers (
Data.getId(), henceDataIdentity.id),Project,Commit,Branch,Tag, and the schema's internalderived_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 7Guid:net10.0:Guid.CreateVersion7();netstandard2.1, which has noGuid.CreateVersion7(): a local RFC 9562 §5.7 implementation, without a package dependency — a 48-bit big-endian Unix timestamp in milliseconds, 74 random bits fromRandomNumberGenerator, the version bits0111and the variant bits10.
- An extension that gives a new element its identifier, setting
IdandElementIdto the same value, usable on both the DTO and the POCOIElement. - Every identifier the SDK mints, other than
DataVersion.id, uses the helper:SysML2.NET/PSM/DTO/Mapping/CommitRequest.Mapping.cs(ToPimWithChange): the commit identifier; theDataVersionidentifiers stayGuid.NewGuid(), which is version 4 on both targets;SysML2.NET.Semantics/Implied/ImpliedRelationshipFactory.cs: the impliedSubclassification,Subsetting,FeatureandFeatureChainingidentifiers.
- The SQL schema mints
DataVersion.idas version 4.element_version.version_idisDataVersion.idfor elements and, through the composite FK, for theExternalData,ExternalRelationshipandProjectUsagerecords (§7b); the PG18 block currently defaults it touuidv7().SysML2.NET.CodeGenerator/Templates/Uml/core-sql-schema.hbs: removeelement_version.version_idfrom the PG18DOblock (§12) and declareDEFAULT gen_random_uuid()on the column in §5 (built in since PostgreSQL 13, so no version guard); keepuuidv7()onderived_version.derived_id,project.id,commit.id,branch.idandtag.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_idis version 4;derived_idstays version 7.doc/SQLSCHEMA-GUIDE.md: §8.1 (theversion_iddesign note), §13 (the self-activatinguuidv7()defaults bullet and the UUIDv7 bullet, both of which nameversion_idandGuid.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, andnullon the optional@idof 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@idand 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
Fix #469: Moved to V7 guid