Choosing Stable Identifiers for Stored Records
An identifier remains attached to an entity when mutable descriptions change. It gives collections a reliable key for updates and links.
- Source
- Anbloq
- Language
- English
- Created
- Updated
- Chapters
- 4
- Reading time
- 1 min
In this article4 chapters
Follow a rename
A course labeled Intro Programming can change to Programming Basics while retaining ID 34. A map keyed by ID still points to the same course after the rename. Record identity and equality explain why a name change can alter a snapshot without creating another entity.
Verify distinct entities
Two courses can temporarily share a display title. Use distinct keys for such records and add tests for updates and lookups. Named fields in records distinguish the identifier's role from its displayed label.[1]
Test a rename without changing identity
A record with ID 42 might change its display name from North Gate to Main Gate. References keyed by the ID still resolve. References keyed by the old display name can fail or accidentally attach to a different record if the name is reused. Test by creating two records with the same display name and renaming just one. See composite dictionary keys for cases where identity belongs to a namespace.
Decide whether a replacement inherits references
Deleting a record and creating another at the same list position does not justify reusing its identity. Durable links and past events may still refer to the earlier object. A scoped ID can combine collection identity and a never-reused local value. When merging sources, define which identifiers can be compared across them. Test one stored foreign reference after a deletion and reinsertion. See two-pass index building.