Event ID Mapper is a plug-in for Rails Event Store (RES) library that let you serialize and control the event_id
format perceived by the repository.
Its original purpose is to encode the primary key and the foreign key in binary format for MySQL compatible databases. Leveraging on ActiveRecord repository for the underlying repository implementation.
However, since the mapper is generic you can easily use it with any Ruby Event Store repository implementations.
The upstream introduced too many breaking changes. (e.g., unconfigurable schema checking)
I can't keep following to make this gem useful, and also I have a lot of disagreements on how the event repository should be done.
I moved on, but feel free to fork.
Add ruby_event_store_event_id_mapper
to the Gemfile:
gem 'ruby_event_store_event_id_mapper'
Download and install by running:
bundle install
When Rails Event Store generates a migration for you. You can edit the migration file to suit your needs.
For instance:
def change
create_table(:event_store_events, id: :binary, limit: 16, force: false) do |t|
t.string :event_type, null: false
t.binary :data, limit: 256.kilobytes, null: false
t.binary :metadata, limit: 256.kilobytes
t.datetime :created_at, index: true, null: false
end
create_table(:event_store_events_in_streams, force: false) do |t|
t.string :stream, null: false
t.integer :position
t.binary :event_id, limit: 16, index: true, null: false
t.datetime :created_at, index: true, null: false
end
add_index :event_store_events_in_streams, [:stream, :position], unique: true
add_index :event_store_events_in_streams, [:stream, :event_id], unique: true
end
Please note the limit: 16
addition on the primary and foreign key attributes.
Now in Ruby code, you can create an event_store
instance with a custom repository following the guide on Rails Event Store website letting RubyEventStoreEventIdMapper::RepositoryWrapper
tap in.
event_store = RailsEventStore::Client.new(
repository: RubyEventStoreEventIdMapper::RepositoryWrapper.new(
repository: RailsEventStoreActiveRecord::EventRepository.new,
serializer: RubyEventStoreEventIdMapper::BinaryUUIDSerializer,
)
)
It is recommended to verify the compatibility of your setup with
the test suite
provided by Ruby Event Store.
It is also recommended to see
how this tiny gem actually works.
It is possible that you have a better use case for the mapper but for now, I can't think of any concrete one.
Bug reports, pull requests, and inquiries are welcome on the GitHub repository.
The gem is available as open source under the terms of the MIT License.