Skip to content

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.

@inxilpro
Copy link
Contributor Author

Discussed with Daniel. We'll change --reattach to --discover-states but otherwise looks good.

@gdespirito
Copy link

any updates on this? :)

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.

3 participants