ruby_event_store-rom 0.35.0 → 0.36.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (41) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +1 -0
  3. data/.rubocop_todo.yml +84 -0
  4. data/Gemfile +4 -4
  5. data/Makefile +3 -0
  6. data/Rakefile +3 -3
  7. data/db/migrate/20180327044629_create_ruby_event_store_tables.rb +17 -8
  8. data/lib/ruby_event_store/rom.rb +19 -16
  9. data/lib/ruby_event_store/rom/adapters/memory/changesets/create_events.rb +17 -0
  10. data/lib/ruby_event_store/rom/adapters/memory/changesets/create_stream_entries.rb +17 -0
  11. data/lib/ruby_event_store/rom/adapters/memory/changesets/update_events.rb +16 -0
  12. data/lib/ruby_event_store/rom/adapters/memory/relations/events.rb +14 -5
  13. data/lib/ruby_event_store/rom/adapters/memory/relations/stream_entries.rb +8 -4
  14. data/lib/ruby_event_store/rom/adapters/memory/unit_of_work.rb +6 -21
  15. data/lib/ruby_event_store/rom/adapters/sql/changesets/create_events.rb +13 -0
  16. data/lib/ruby_event_store/rom/adapters/sql/changesets/update_events.rb +39 -0
  17. data/lib/ruby_event_store/rom/adapters/sql/index_violation_detector.rb +15 -16
  18. data/lib/ruby_event_store/rom/adapters/sql/relations/events.rb +13 -1
  19. data/lib/ruby_event_store/rom/adapters/sql/relations/stream_entries.rb +8 -4
  20. data/lib/ruby_event_store/rom/adapters/sql/tasks/migration_tasks.rake +16 -3
  21. data/lib/ruby_event_store/rom/changesets/create_events.rb +29 -0
  22. data/lib/ruby_event_store/rom/changesets/create_stream_entries.rb +21 -0
  23. data/lib/ruby_event_store/rom/changesets/update_events.rb +29 -0
  24. data/lib/ruby_event_store/rom/event_repository.rb +16 -6
  25. data/lib/ruby_event_store/rom/mappers/event_to_serialized_record.rb +1 -1
  26. data/lib/ruby_event_store/rom/mappers/stream_entry_to_serialized_record.rb +1 -1
  27. data/lib/ruby_event_store/rom/memory.rb +15 -3
  28. data/lib/ruby_event_store/rom/repositories/events.rb +18 -30
  29. data/lib/ruby_event_store/rom/repositories/stream_entries.rb +17 -18
  30. data/lib/ruby_event_store/rom/sql.rb +62 -12
  31. data/lib/ruby_event_store/rom/types.rb +13 -0
  32. data/lib/ruby_event_store/rom/unit_of_work.rb +1 -1
  33. data/lib/ruby_event_store/rom/version.rb +1 -1
  34. data/lib/ruby_event_store/spec/rom/event_repository_lint.rb +55 -90
  35. data/lib/ruby_event_store/spec/rom/relations/events_lint.rb +12 -12
  36. data/lib/ruby_event_store/spec/rom/relations/stream_entries_lint.rb +44 -44
  37. data/lib/ruby_event_store/spec/rom/spec_helper_lint.rb +1 -1
  38. data/lib/ruby_event_store/spec/rom/unit_of_work_lint.rb +1 -1
  39. data/ruby_event_store-rom.gemspec +12 -13
  40. metadata +40 -31
  41. data/lib/ruby_event_store/rom/adapters/sql/unit_of_work.rb +0 -37
@@ -1,37 +0,0 @@
1
- module RubyEventStore
2
- module ROM
3
- module SQL
4
- class UnitOfWork < ROM::UnitOfWork
5
- def commit!(gateway, changesets, **options)
6
- # Committing changesets concurrently causes MySQL deadlocks
7
- # which are not caught and retried by Sequel's built-in
8
- # :retry_on option. This appears to be a result of how ROM
9
- # handles exceptions which don't bubble up so that Sequel
10
- # can retry transactions with the :retry_on option when there's
11
- # a deadlock.
12
- #
13
- # This is exacerbated by the fact that changesets insert multiple
14
- # tuples with individual INSERT statements because ROM specifies
15
- # to Sequel to return a list of primary keys created. The likelihood
16
- # of a deadlock is reduced with batched INSERT statements.
17
- #
18
- # For this reason we need to manually insert changeset records to avoid
19
- # MySQL deadlocks or to allow Sequel to retry transactions
20
- # when the :retry_on option is specified.
21
- options.merge!(
22
- retry_on: Sequel::SerializationFailure,
23
- before_retry: -> (num, ex) {
24
- env.logger.warn("RETRY TRANSACTION [#{self.class.name} => #{ex.class.name}] #{ex.message}")
25
- }
26
- )
27
-
28
- gateway.transaction(options) do
29
- changesets.each do |changeset|
30
- changeset.relation.multi_insert(changeset.to_a)
31
- end
32
- end
33
- end
34
- end
35
- end
36
- end
37
- end