Skip to content
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

Provide a way to re-attach events on replay #195

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

inxilpro
Copy link
Contributor

Sometimes events don't need state at first but eventually do. This adds a simple way to "re-attach" all the events state during replay, effectively ensuring that everything with a #[StateId] attribute now is connected to that state for future queries. Imagine:

class UserRegistered extends Event
{
  public int $user_id;
  public int $name;
}

And later needing to track some sort of "legacy rules" value for future events:

class UserRegistered extends Event
{
  #[StateId(UserState::class)]
  public int $user_id;
  public int $name;

  public function apply(UserState $state)
  {
    $state->legacy_rules_apply = now()->isBefore('2024-01-01');
  }
}

With this feature, you can run replays with the --reattach flag, and old events that were fired before we updated our code with #[StateId(UserState::class)] will automatically get attached to the UserState before replay.

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