Skip to content

feat(yes-auth): rebuild principals mirror rows on resource-access Restored events#30

Merged
ncri merged 2 commits into
mainfrom
feat-resource-access-restored-handlers
Jun 11, 2026
Merged

feat(yes-auth): rebuild principals mirror rows on resource-access Restored events#30
ncri merged 2 commits into
mainfrom
feat-resource-access-restored-handlers

Conversation

@ncri

@ncri ncri commented Jun 11, 2026

Copy link
Copy Markdown
Contributor

Summary

The On...Removed handlers hard-delete the auth_principals_* mirror rows. When an Authorization::{Write,Read}ResourceAccessRestored event arrives later, there is no state left to rebuild the row from — the event carries no snapshot by design.

This adds On{Write,Read}ResourceAccessRestored handlers that replay the aggregate's stream through the existing per-field event handlers to reconstruct the row. Lifecycle events are excluded from the replay: a Removed would delete (and freeze) the row mid-replay, a Restored would recurse. The two event types are registered in Yes::Auth::Subscriptions.

The row itself is recreated blank by the builder's regular find_or_create read-model resolution before the handler runs; the replay fills the attributes back in.

Testing

  • yes-auth: 81 examples, 0 failures (includes new RestoreReplay integration spec + handler specs)
  • RuboCop clean

ncri and others added 2 commits June 11, 2026 18:04
…tored events

The On...Removed handlers hard-delete mirror rows, so a later
...Restored event found no state to rebuild from. The new
On...Restored handlers replay the aggregate's stream through the
existing per-field event handlers (lifecycle events excluded) to
reconstruct the row, and the Restored event types are registered in
Yes::Auth::Subscriptions.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
…spec requires

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@ncri ncri merged commit 5fbdaeb into main Jun 11, 2026
5 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