sequent 6.0.1 → 7.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (41) hide show
  1. checksums.yaml +4 -4
  2. data/db/sequent_schema.rb +5 -0
  3. data/lib/sequent/configuration.rb +64 -13
  4. data/lib/sequent/core/aggregate_repository.rb +2 -2
  5. data/lib/sequent/core/aggregate_snapshotter.rb +4 -0
  6. data/lib/sequent/core/base_command_handler.rb +5 -0
  7. data/lib/sequent/core/core.rb +1 -1
  8. data/lib/sequent/core/event.rb +2 -2
  9. data/lib/sequent/core/event_record.rb +1 -0
  10. data/lib/sequent/core/event_store.rb +20 -16
  11. data/lib/sequent/core/helpers/attribute_support.rb +7 -7
  12. data/lib/sequent/core/helpers/message_handler.rb +10 -11
  13. data/lib/sequent/core/helpers/message_router.rb +13 -7
  14. data/lib/sequent/core/persistors/active_record_persistor.rb +4 -0
  15. data/lib/sequent/core/persistors/persistor.rb +5 -0
  16. data/lib/sequent/core/persistors/replay_optimized_postgres_persistor.rb +140 -133
  17. data/lib/sequent/core/projector.rb +4 -0
  18. data/lib/sequent/core/transactions/active_record_transaction_provider.rb +2 -1
  19. data/lib/sequent/core/workflow.rb +4 -0
  20. data/lib/sequent/dry_run/dry_run.rb +4 -0
  21. data/lib/sequent/dry_run/read_only_replay_optimized_postgres_persistor.rb +26 -0
  22. data/lib/sequent/dry_run/view_schema.rb +36 -0
  23. data/lib/sequent/generator/template_project/db/sequent_schema.rb +1 -0
  24. data/lib/sequent/migrations/errors.rb +12 -0
  25. data/lib/sequent/migrations/migrations.rb +0 -1
  26. data/lib/sequent/migrations/planner.rb +11 -7
  27. data/lib/sequent/migrations/versions.rb +82 -0
  28. data/lib/sequent/migrations/view_schema.rb +101 -58
  29. data/lib/sequent/rake/migration_tasks.rb +89 -6
  30. data/lib/sequent/sequent.rb +4 -11
  31. data/lib/sequent/support/database.rb +3 -11
  32. data/lib/sequent/support.rb +0 -2
  33. data/lib/sequent/util/util.rb +1 -0
  34. data/lib/sequent/util/web/clear_cache.rb +19 -0
  35. data/lib/sequent.rb +1 -0
  36. data/lib/version.rb +1 -1
  37. metadata +20 -30
  38. data/lib/sequent/core/helpers/message_dispatcher.rb +0 -20
  39. data/lib/sequent/migrations/migrate_events.rb +0 -67
  40. data/lib/sequent/support/view_projection.rb +0 -61
  41. data/lib/sequent/support/view_schema.rb +0 -24
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sequent
3
3
  version: !ruby/object:Gem::Version
4
- version: 6.0.1
4
+ version: 7.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Lars Vonk
@@ -12,7 +12,7 @@ authors:
12
12
  autorequire:
13
13
  bindir: bin
14
14
  cert_chain: []
15
- date: 2023-09-28 00:00:00.000000000 Z
15
+ date: 2024-09-26 00:00:00.000000000 Z
16
16
  dependencies:
17
17
  - !ruby/object:Gem::Dependency
18
18
  name: activemodel
@@ -20,40 +20,28 @@ dependencies:
20
20
  requirements:
21
21
  - - ">="
22
22
  - !ruby/object:Gem::Version
23
- version: '5.0'
24
- - - "<"
25
- - !ruby/object:Gem::Version
26
- version: '7.1'
23
+ version: '6.0'
27
24
  type: :runtime
28
25
  prerelease: false
29
26
  version_requirements: !ruby/object:Gem::Requirement
30
27
  requirements:
31
28
  - - ">="
32
29
  - !ruby/object:Gem::Version
33
- version: '5.0'
34
- - - "<"
35
- - !ruby/object:Gem::Version
36
- version: '7.1'
30
+ version: '6.0'
37
31
  - !ruby/object:Gem::Dependency
38
32
  name: activerecord
39
33
  requirement: !ruby/object:Gem::Requirement
40
34
  requirements:
41
35
  - - ">="
42
36
  - !ruby/object:Gem::Version
43
- version: '5.0'
44
- - - "<"
45
- - !ruby/object:Gem::Version
46
- version: '7.1'
37
+ version: '6.0'
47
38
  type: :runtime
48
39
  prerelease: false
49
40
  version_requirements: !ruby/object:Gem::Requirement
50
41
  requirements:
51
42
  - - ">="
52
43
  - !ruby/object:Gem::Version
53
- version: '5.0'
54
- - - "<"
55
- - !ruby/object:Gem::Version
56
- version: '7.1'
44
+ version: '6.0'
57
45
  - !ruby/object:Gem::Dependency
58
46
  name: bcrypt
59
47
  requirement: !ruby/object:Gem::Requirement
@@ -119,7 +107,7 @@ dependencies:
119
107
  version: 2.6.5
120
108
  - - "<"
121
109
  - !ruby/object:Gem::Version
122
- version: '3.3'
110
+ version: '3.4'
123
111
  type: :runtime
124
112
  prerelease: false
125
113
  version_requirements: !ruby/object:Gem::Requirement
@@ -129,7 +117,7 @@ dependencies:
129
117
  version: 2.6.5
130
118
  - - "<"
131
119
  - !ruby/object:Gem::Version
132
- version: '3.3'
120
+ version: '3.4'
133
121
  - !ruby/object:Gem::Dependency
134
122
  name: pg
135
123
  requirement: !ruby/object:Gem::Requirement
@@ -176,16 +164,16 @@ dependencies:
176
164
  name: tzinfo
177
165
  requirement: !ruby/object:Gem::Requirement
178
166
  requirements:
179
- - - "~>"
167
+ - - ">="
180
168
  - !ruby/object:Gem::Version
181
- version: '2.0'
169
+ version: '1.1'
182
170
  type: :runtime
183
171
  prerelease: false
184
172
  version_requirements: !ruby/object:Gem::Requirement
185
173
  requirements:
186
- - - "~>"
174
+ - - ">="
187
175
  - !ruby/object:Gem::Version
188
- version: '2.0'
176
+ version: '1.1'
189
177
  - !ruby/object:Gem::Dependency
190
178
  name: pry
191
179
  requirement: !ruby/object:Gem::Requirement
@@ -358,7 +346,6 @@ files:
358
346
  - lib/sequent/core/helpers/equal_support.rb
359
347
  - lib/sequent/core/helpers/helpers.rb
360
348
  - lib/sequent/core/helpers/mergable.rb
361
- - lib/sequent/core/helpers/message_dispatcher.rb
362
349
  - lib/sequent/core/helpers/message_handler.rb
363
350
  - lib/sequent/core/helpers/message_handler_option_registry.rb
364
351
  - lib/sequent/core/helpers/message_matchers/any.rb
@@ -396,6 +383,9 @@ files:
396
383
  - lib/sequent/core/transactions/transactions.rb
397
384
  - lib/sequent/core/value_object.rb
398
385
  - lib/sequent/core/workflow.rb
386
+ - lib/sequent/dry_run/dry_run.rb
387
+ - lib/sequent/dry_run/read_only_replay_optimized_postgres_persistor.rb
388
+ - lib/sequent/dry_run/view_schema.rb
399
389
  - lib/sequent/generator.rb
400
390
  - lib/sequent/generator/aggregate.rb
401
391
  - lib/sequent/generator/command.rb
@@ -428,21 +418,20 @@ files:
428
418
  - lib/sequent/generator/template_project/spec/app/projectors/post_projector_spec.rb
429
419
  - lib/sequent/generator/template_project/spec/lib/post/post_command_handler_spec.rb
430
420
  - lib/sequent/generator/template_project/spec/spec_helper.rb
421
+ - lib/sequent/migrations/errors.rb
431
422
  - lib/sequent/migrations/executor.rb
432
423
  - lib/sequent/migrations/functions.rb
433
- - lib/sequent/migrations/migrate_events.rb
434
424
  - lib/sequent/migrations/migrations.rb
435
425
  - lib/sequent/migrations/planner.rb
436
426
  - lib/sequent/migrations/projectors.rb
437
427
  - lib/sequent/migrations/sequent_schema.rb
438
428
  - lib/sequent/migrations/sql.rb
429
+ - lib/sequent/migrations/versions.rb
439
430
  - lib/sequent/migrations/view_schema.rb
440
431
  - lib/sequent/rake/migration_tasks.rb
441
432
  - lib/sequent/sequent.rb
442
433
  - lib/sequent/support.rb
443
434
  - lib/sequent/support/database.rb
444
- - lib/sequent/support/view_projection.rb
445
- - lib/sequent/support/view_schema.rb
446
435
  - lib/sequent/test.rb
447
436
  - lib/sequent/test/command_handler_helpers.rb
448
437
  - lib/sequent/test/database_helpers.rb
@@ -454,6 +443,7 @@ files:
454
443
  - lib/sequent/util/skip_if_already_processing.rb
455
444
  - lib/sequent/util/timer.rb
456
445
  - lib/sequent/util/util.rb
446
+ - lib/sequent/util/web/clear_cache.rb
457
447
  - lib/version.rb
458
448
  homepage: https://github.com/zilverline/sequent
459
449
  licenses:
@@ -467,14 +457,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
467
457
  requirements:
468
458
  - - ">="
469
459
  - !ruby/object:Gem::Version
470
- version: '2.7'
460
+ version: '3.0'
471
461
  required_rubygems_version: !ruby/object:Gem::Requirement
472
462
  requirements:
473
463
  - - ">="
474
464
  - !ruby/object:Gem::Version
475
465
  version: '0'
476
466
  requirements: []
477
- rubygems_version: 3.4.10
467
+ rubygems_version: 3.5.16
478
468
  signing_key:
479
469
  specification_version: 4
480
470
  summary: Event sourcing framework for Ruby
@@ -1,20 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Sequent
4
- module Core
5
- module Helpers
6
- class MessageDispatcher
7
- def initialize(message_router, context)
8
- @message_router = message_router
9
- @context = context
10
- end
11
-
12
- def dispatch_message(message)
13
- @message_router
14
- .match_message(message)
15
- .each { |handler| @context.instance_exec(message, &handler) }
16
- end
17
- end
18
- end
19
- end
20
- end
@@ -1,67 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- ##
4
- # When you need to upgrade the event store based on information of the previous schema version
5
- # this is the place you need to implement a migration.
6
- # Examples are: corrupt events (due to insufficient testing for instance...)
7
- # or adding extra events to the event stream if a new concept is introduced.
8
- #
9
- # To implement a migration you should create a class according to the following contract:
10
- # module Database
11
- # class MigrateToVersionXXX
12
- # def initialize(env)
13
- # @env = env
14
- # end
15
- #
16
- # def migrate
17
- # # your migration code here...
18
- # end
19
- # end
20
- # end
21
- #
22
- module Sequent
23
- module Migrations
24
- class MigrateEvents
25
- ##
26
- # @param env The string representing the current environment. E.g. "development", "production"
27
- def initialize(env)
28
- warn <<~EOS
29
- [DEPRECATED] Use of MigrateEvents is deprecated and will be removed from future version. Please use Sequent::Migrations::ViewSchema instead. See the changelog on how to update.
30
- EOS
31
- @env = env
32
- end
33
-
34
- ##
35
- #
36
- # @param current_version The current version of the application. E.g. 10
37
- # @param new_version The version to migrate to. E.g. 11
38
- # @param &after_migration_block an optional block (with the current upgrade version as param)
39
- # to run after the migrations run. E.g. close resources
40
- #
41
- def execute_migrations(current_version, new_version)
42
- migrations(current_version, new_version).each do |migration_class|
43
- migration = migration_class.new(@env)
44
- begin
45
- migration.migrate
46
- ensure
47
- yield(migration.version) if block_given?
48
- end
49
- end
50
- end
51
-
52
- def migrations(current_version, new_version)
53
- return [] if current_version == 0
54
-
55
- ((current_version + 1)..new_version).map do |upgrade_to_version|
56
- Class.const_get("Database::MigrateToVersion#{upgrade_to_version}")
57
- rescue NameError
58
- nil
59
- end.compact
60
- end
61
-
62
- def has_migrations?(current_version, new_version)
63
- migrations(current_version, new_version).any?
64
- end
65
- end
66
- end
67
- end
@@ -1,61 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'postgresql_cursor'
4
-
5
- module Sequent
6
- module Support
7
- class ViewProjection
8
- attr_reader :name, :version, :schema_definition
9
-
10
- def initialize(options)
11
- @name = options.fetch(:name)
12
- @version = options.fetch(:version)
13
- @schema_definition = options.fetch(:definition)
14
- @replay_event_handlers = options.fetch(:event_handlers)
15
- end
16
-
17
- def build!
18
- with_default_configuration do
19
- Sequent.configuration.event_handlers = @replay_event_handlers
20
-
21
- load schema_definition
22
- event_store = Sequent.configuration.event_store
23
- ordering = Events::ORDERED_BY_STREAM
24
- event_store.replay_events_from_cursor(
25
- block_size: 10_000,
26
- get_events: -> { ordering[event_store] },
27
- )
28
- end
29
- end
30
-
31
- def schema_name
32
- "#{name}_#{version}"
33
- end
34
-
35
- private
36
-
37
- def with_default_configuration
38
- original_configuration = Sequent.configuration
39
- Sequent::Configuration.reset
40
- yield
41
- Sequent::Configuration.restore(original_configuration)
42
- end
43
- end
44
-
45
- module Events
46
- extend ActiveRecord::ConnectionAdapters::Quoting
47
-
48
- ORDERED_BY_STREAM = ->(_event_store) do
49
- event_records = quote_table_name(Sequent.configuration.event_record_class.table_name)
50
- stream_records = quote_table_name(Sequent.configuration.stream_record_class.table_name)
51
- snapshot_event_type = quote(Sequent.configuration.snapshot_event_class)
52
-
53
- Sequent.configuration.event_record_class
54
- .select('event_type, event_json')
55
- .joins("INNER JOIN #{stream_records} ON #{event_records}.stream_record_id = #{stream_records}.id")
56
- .where("event_type <> #{snapshot_event_type}")
57
- .order!("#{stream_records}.id, #{event_records}.sequence_number")
58
- end
59
- end
60
- end
61
- end
@@ -1,24 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Sequent
4
- module Support
5
- class ViewSchema < ActiveRecord::Schema
6
- def define(info, &block)
7
- view_projection = info[:view_projection]
8
- switch_to_schema(view_projection) if view_projection
9
- super
10
- ensure
11
- switch_back_to_original_schema if view_projection
12
- end
13
-
14
- def switch_to_schema(view_projection)
15
- @original_schema_search_path = connection.schema_search_path
16
- connection.schema_search_path = view_projection.schema_name
17
- end
18
-
19
- def switch_back_to_original_schema
20
- connection.schema_search_path = @original_schema_search_path
21
- end
22
- end
23
- end
24
- end