envato / event_sourcery

A library for building event sourced applications in Ruby
MIT License
84 stars 10 forks source link

Add `TableOwner` `table_prefix` attr #103

Closed madlep closed 7 years ago

madlep commented 7 years ago

This allows projector (or other TableOwner) instances to specify a custom naming prefix for all tables they own.

This is useful when multiple instances of a projector are running in parallel, and each needs it's own set of working table.

An example of this is when using elasticsearch as a target for the projection data as in elements-ingestion, and blue/green management of two indexes, each managed by it's own projector is used.

e.g:

class ElementsItemSearchProjector
  def initialize(index_name:)
    @index_name = index_name
    self.table_prefix = index_name
  end

  # this actually creates table named `some_prefix_items` or specifically
  # `index1_items` or `index2_items`
  table :items do
    column :item_id, 'UUID'
    # ...
  end
end