You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Modification of existing event (ex. adding new attribute)
In order to support both use case we have done example customizations:
Renaming / moving event class
In such use case we had to implement custom repository:
moduleInfra# Clone of RailsEventStoreActiveRecord::EventRepository# with changes:# - constructor is accepting 'events_name_mapping' keyword with hash# configuration of renaming mapping# - with modified version of build_event_entity method, which is using this mapping# - with modified version of read_all_streams_forward method, with support for event_types# (used in rebuilding of read models, to reduce scope)classEventRepository < RailsEventStoreActiveRecord::EventRepositorydefinitialize(events_rename_mapping: {})@events_rename_mapping=events_rename_mappingsuper()end# improved version, please take a look documentation on topdefread_all_streams_forward(start_event_id,count,event_types)stream=adapterunlessstart_event_id.equal?(:head)starting_event=adapter.find_by(event_id: start_event_id)stream=stream.where('id > ?',starting_event)endscope=stream.order('id ASC')scope=scope.where(event_type: event_types)ifevent_typesscope=scope.limit(count)scope.map(&method(:build_event_entity))endprivateattr_reader:events_rename_mapping# improved version, please take a look documentation on topdefbuild_event_entity(record)returnnilunlessrecordevent_type=events_rename_mapping.fetch(record.event_type){record.event_type}event_type.constantize.new(event_id: record.event_id,metadata: record.metadata,data: record.data)endendend
Configure using of this repository by our configuration:
EVENTS_RENAME_MAPPING={# Example mapping in case of refactoring (move or rename)"Loans::Events::LoanGivenEvent"=>"Loans::Events::SomeGivenEvent"}classCoreConfigurationdefinitialize(repository: Infra::EventRepository.new(events_rename_mapping: EVENTS_RENAME_MAPPING),event_store: RailsEventStore::Client.new(repository: repository),command_bus: Infra::CommandBus.new,command_injector: Infra::CommandInjector.new(command_bus: command_bus))@event_store=event_store@command_bus=command_bus@command_injector=command_injectorconfigure_aggregate_root(event_store)setup_event_handler_strategysetup_read_models(event_store)register_event_handlers(event_store)register_command_handlers(command_bus)enddefconfigure_aggregate_root(event_store)AggregateRoot.configuredo |config|
config.default_event_store=event_storeendend
...
attr_reader:event_store,:command_bus,:all_command_handlers,:all_read_models,:all_event_handlers,:command_injectorend
modification of existing event (ex. adding new attribute, changing type of existing one, etc)
Hi @andrzejsliwa, I'm new to RES and reading through the issues to see how some intricacies like this are handled. This is definitely a challenging issue - would you do this in lieu of database migrations?
We have here few use cases:
In order to support both use case we have done example customizations:
In such use case we had to implement custom repository:
Configure using of this repository by our configuration:
by default version is equal 1 implicitly:
The text was updated successfully, but these errors were encountered: