Skip to content

feat(persistence): auto-generated entity ids#75

Merged
tgiachi merged 4 commits into
mainfrom
develop
Jul 8, 2026
Merged

feat(persistence): auto-generated entity ids#75
tgiachi merged 4 commits into
mainfrom
develop

Conversation

@tgiachi

@tgiachi tgiachi commented Jul 8, 2026

Copy link
Copy Markdown
Owner

Adds opt-in server-assigned keys to SquidStd.Persistence.

What

  • IIdGenerator<TKey> (Initial + Next) with built-in IdGenerators.Int32/Int64
  • RegisterPersistedEntity gains optional keySetter + idGenerator; when a generator is supplied the type is auto-id
  • EntityStore.UpsertAsync assigns the next key when the caller leaves it at default, writing it back onto the entity
  • Per-type high-water key, advanced by max on every upsert (live and on journal replay), never lowered on delete
  • High-water persisted in a reserved snapshot bucket (type id 65535) so ids continue across restart and never regress

Compatibility

  • Existing keySelector-only registrations and the descriptor constructor are unchanged
  • No journal binary-format change

Tests

  • New: IdGenerators, descriptor auto-id, EntityStore auto-id, PersistenceService end-to-end durability (continue-across-reload + delete-highest-no-reuse)
  • Full suite green: 1233/1233

tgiachi added 4 commits July 8, 2026 12:55
- IIdGenerator<TKey> (Initial + Next) models a successor-based id strategy
- IdGenerators.Int32/Int64 factories for the common integral keys
- PersistenceStateStore keeps a per-type high-water key (GetLastKey/SetLastKey), cleared with buckets
- descriptor gains optional keySetter + idGenerator; AllocateNextKey, NoteKey (max, never lowers),
  IsDefaultKey, SetKey, and high-water serialize/load hooks
- an auto-id registration requires a keySetter
…ter on replay

- EntityStore.UpsertAsync allocates the next key when an auto-id entity has a default key,
  writes it back onto the clone and the caller's instance, and advances the high-water on explicit keys
- descriptor ApplyUpsert notes the key so journal replay resumes numbering without reuse
- add internal IInternalAutoIdDescriptor seam so EntityStore reaches auto-id ops through the interface
…terPersistedEntity

- snapshot captures per-type high-water keys into a reserved bucket (type id 65535) and restores them on load
- RegisterPersistedEntity gains optional keySetter + idGenerator; rejects the reserved type id
- ids continue across restart and never regress after deleting the highest entity
@tgiachi tgiachi merged commit 91881c1 into main Jul 8, 2026
1 of 2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant