-
Notifications
You must be signed in to change notification settings - Fork 1
Refactor entity and transaction IDs to UUIDs #4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Major changes:
- Entity IDs are now random java.util.UUID instead of sequential integers
- Transaction IDs use time-ordered squuids from com.yetanalytics/squuid
- Legacy tempid formats (negative integers, strings) are auto-converted to UUIDs
- String tempids like {:db/id "e1"} now work and map to UUIDs in :tempids
Key implementation changes in db.cljc:
- Extended find-vector-upserts to detect regular unique identity upserts
for vector ops (not just tuple attrs)
- Added conflicting upsert detection for vector ops when same tempid
resolves to different entities
- Added :db/current-tx upsert conflict detection
- Fixed ref tempid handling in find-vector-upserts
Test updates:
- Updated all tests to use string tempids and capture UUIDs from :tempids
- Fixed test isolation issues (fresh db for each assertion)
- Updated error message regex patterns to match new formats
- Fixed entity-map ref extraction (wraps refs in {:db/id uuid})
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- Remove `numeric-eid-exists?` alias - Remove positive integer handling in `resolve-id` (now throws error) - Make `entid` throw error for integers instead of returning nil - Rename `legacy-tempid?` to `tempid?` (negative ints and strings are valid tempids, not legacy) - Update comments to remove "legacy" terminology - Fix test to use string tempids instead of positive integers 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
…e UUIDs for entity IDs.
🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Entity IDs are now UUIDs, not integers. Updated the quick path optimization in getter-fn and removed the obsolete number? type guard in entity.cljc. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
One point in Ideas for DataScript 2 is:
With this PR dbval would use UUIDs for entity IDs.
The biggest motivator for me is to avoid the need to assign an external ID to each entity. In past we often made the mistake to share Datomic entity IDs with the outside world (via an API for example), while this is strictly discouraged. In Datomic and Datascript each transaction also receive its own entity ID. dbval uses colossal-squuid UUIDs for transaction entity IDs. They increase strictly monotonically, meaning:
With
com.yetanalytics.squuid/uuid->timeyou can extract the timestamp that is encoded in the leading bits of the SQUUID:This timestamp can serve as
:db/txInstantto capture when the transaction has been transacted. UUIDs for entity and transaction IDs would allow to entirely get rid of tempids. However, they are still supported by dbval for convenience and to assign data to the transaction entity:Another compelling option of using UUIDs is that dbval databases become mergeable, if they adhere to the same schema. Thereby you can solve the following challenge: if you have a separate database per customer it is no longer possible to run database queries to get statistics across your customer base. With dbval you can merge all customer databases into a big one to run these statistics queries.
One obvious downside of UUIDs is that they need twice as much storage in comparison to 64 bit integers.