slashdotdash / conduit

RealWorld example backend implementing the CQRS/ES pattern in Elixir and Phoenix
MIT License
353 stars 67 forks source link

Uniqueness middleware issue after event removed #24

Open Yamilquery opened 5 years ago

Yamilquery commented 5 years ago

Support.Middleware.Uniqueness module works fine if the only thing that you need to validate is if the command hasn't been dispatched before with a common field name.

But what happens if you dispatch a command to remove something and later you try to create it again with the same value in the unique field? You would get an error, even if the record doesn't exist anymore.

To avoid that it would be great to add a timestamp comparing the dispatched commands in order to avoid comparing commands in long periods of time. At the end of the day, we just need this uniqueness feature to avoid duplicated event creation.

I'm going to try to make the changes and submit a pull request.