sequent 5.0.0 → 6.0.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.
- checksums.yaml +4 -4
- data/bin/sequent +1 -1
- data/db/sequent_schema.rb +3 -3
- data/lib/sequent/configuration.rb +19 -1
- data/lib/sequent/core/aggregate_root.rb +2 -6
- data/lib/sequent/core/aggregate_roots.rb +2 -6
- data/lib/sequent/core/command.rb +8 -12
- data/lib/sequent/core/command_service.rb +13 -2
- data/lib/sequent/core/core.rb +1 -0
- data/lib/sequent/core/event.rb +2 -2
- data/lib/sequent/core/event_store.rb +15 -2
- data/lib/sequent/core/ext/ext.rb +17 -0
- data/lib/sequent/core/helpers/attribute_support.rb +1 -0
- data/lib/sequent/core/helpers/default_validators.rb +3 -0
- data/lib/sequent/core/helpers/param_support.rb +2 -0
- data/lib/sequent/core/helpers/string_to_value_parsers.rb +5 -0
- data/lib/sequent/core/helpers/time_validator.rb +23 -0
- data/lib/sequent/core/helpers/value_validators.rb +11 -0
- data/lib/sequent/core/middleware/chain.rb +37 -0
- data/lib/sequent/core/middleware/middleware.rb +3 -0
- data/lib/sequent/core/projector.rb +3 -11
- data/lib/sequent/core/workflow.rb +3 -11
- data/lib/sequent/generator/template_project/Rakefile +2 -2
- data/lib/sequent/generator/template_project/db/sequent_schema.rb +3 -3
- data/lib/sequent/generator/template_project/spec/spec_helper.rb +1 -1
- data/lib/sequent/migrations/migrations.rb +1 -0
- data/lib/sequent/migrations/projectors.rb +2 -2
- data/lib/sequent/migrations/sequent_schema.rb +40 -0
- data/lib/sequent/migrations/view_schema.rb +39 -3
- data/lib/sequent/rake/migration_tasks.rb +36 -33
- data/lib/sequent/support/database.rb +29 -13
- data/lib/sequent/test/command_handler_helpers.rb +1 -1
- data/lib/sequent/test/database_helpers.rb +20 -0
- data/lib/sequent/test/time_comparison.rb +2 -5
- data/lib/sequent/test/{event_handler_helpers.rb → workflow_helpers.rb} +24 -10
- data/lib/sequent/test.rb +2 -1
- data/lib/sequent/util/dry_run.rb +1 -1
- data/lib/version.rb +1 -1
- metadata +11 -7
- data/lib/sequent/rake/tasks.rb +0 -121
@@ -79,6 +79,29 @@ module Sequent
|
|
79
79
|
|
80
80
|
attr_reader :view_schema, :db_config, :logger
|
81
81
|
|
82
|
+
class << self
|
83
|
+
# @see #create_view_tables
|
84
|
+
# @param env [String] The environment used for connecting the database
|
85
|
+
def create_view_tables(env:)
|
86
|
+
fail ArgumentError, 'env is required' if env.blank?
|
87
|
+
|
88
|
+
db_config = Sequent::Support::Database.read_config(env)
|
89
|
+
Sequent::Support::Database.establish_connection(db_config)
|
90
|
+
new(db_config: db_config).create_view_tables
|
91
|
+
end
|
92
|
+
|
93
|
+
# @see #create_view_schema_if_not_exists
|
94
|
+
# @param env [String] The environment used for connecting the database
|
95
|
+
def create_view_schema_if_not_exists(env:)
|
96
|
+
fail ArgumentError, 'env is required' if env.blank?
|
97
|
+
|
98
|
+
db_config = Sequent::Support::Database.read_config(env)
|
99
|
+
Sequent::Support::Database.establish_connection(db_config)
|
100
|
+
|
101
|
+
new(db_config: db_config).create_view_schema_if_not_exists
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
82
105
|
def initialize(db_config:)
|
83
106
|
@db_config = db_config
|
84
107
|
@view_schema = Sequent.configuration.view_schema_name
|
@@ -98,6 +121,9 @@ module Sequent
|
|
98
121
|
# the entire view schema without replaying the events
|
99
122
|
def create_view_tables
|
100
123
|
create_view_schema_if_not_exists
|
124
|
+
return if Sequent.migration_class == Sequent::Migrations::Projectors
|
125
|
+
return if Sequent.new_version == current_version
|
126
|
+
|
101
127
|
in_view_schema do
|
102
128
|
Sequent::Core::Migratable.all.flat_map(&:managed_tables).each do |table|
|
103
129
|
sql_file = "#{Sequent.configuration.migration_sql_files_directory}/#{table.table_name}.sql"
|
@@ -112,6 +138,7 @@ module Sequent
|
|
112
138
|
statements.each(&method(:exec_sql))
|
113
139
|
end
|
114
140
|
end
|
141
|
+
Versions.create!(version: Sequent.new_version)
|
115
142
|
end
|
116
143
|
end
|
117
144
|
|
@@ -119,8 +146,12 @@ module Sequent
|
|
119
146
|
# Utility method that replays events for all managed_tables from all Sequent::Core::Projector's
|
120
147
|
#
|
121
148
|
# This method is mainly useful in test scenario's or development tasks
|
122
|
-
def replay_all!
|
123
|
-
replay!(
|
149
|
+
def replay_all!(group_exponent: 1)
|
150
|
+
replay!(
|
151
|
+
Sequent.configuration.online_replay_persistor_class.new,
|
152
|
+
projectors: Core::Migratable.projectors,
|
153
|
+
group_exponent: group_exponent,
|
154
|
+
)
|
124
155
|
end
|
125
156
|
|
126
157
|
##
|
@@ -158,6 +189,8 @@ module Sequent
|
|
158
189
|
# These tables will be called `table_name_VERSION`.
|
159
190
|
# 3. Replay all events to populate the tables
|
160
191
|
# It keeps track of all events that are already replayed.
|
192
|
+
# 4. Resets the table names of the activerecord models (projections)
|
193
|
+
# back to their original values (so without the VERSION suffix)
|
161
194
|
#
|
162
195
|
# If anything fails an exception is raised and everything is rolled back
|
163
196
|
#
|
@@ -178,6 +211,7 @@ module Sequent
|
|
178
211
|
in_view_schema do
|
179
212
|
executor.create_indexes_after_execute_online(plan)
|
180
213
|
end
|
214
|
+
executor.reset_table_names(plan)
|
181
215
|
# rubocop:disable Lint/RescueException
|
182
216
|
rescue Exception => e
|
183
217
|
# rubocop:enable Lint/RescueException
|
@@ -391,7 +425,9 @@ module Sequent
|
|
391
425
|
.where("NOT EXISTS (SELECT 1 FROM #{ReplayedIds.table_name} WHERE event_id = event_records.id)")
|
392
426
|
end
|
393
427
|
event_stream = event_stream.where('event_records.created_at > ?', 1.day.ago) if exclude_already_replayed
|
394
|
-
event_stream
|
428
|
+
event_stream
|
429
|
+
.order('aggregate_id ASC, sequence_number ASC')
|
430
|
+
.select('id, event_type, event_json, sequence_number')
|
395
431
|
end
|
396
432
|
|
397
433
|
## shortcut methods
|
@@ -6,6 +6,7 @@ require 'rake/tasklib'
|
|
6
6
|
|
7
7
|
require 'sequent/support'
|
8
8
|
require 'sequent/migrations/view_schema'
|
9
|
+
require 'sequent/migrations/sequent_schema'
|
9
10
|
|
10
11
|
module Sequent
|
11
12
|
module Rake
|
@@ -15,24 +16,35 @@ module Sequent
|
|
15
16
|
def register_tasks!
|
16
17
|
namespace :sequent do
|
17
18
|
desc <<~EOS
|
18
|
-
|
19
|
+
Set the SEQUENT_ENV to RAILS_ENV or RACK_ENV if not already set
|
19
20
|
EOS
|
20
|
-
task :
|
21
|
+
task :set_env_var do
|
22
|
+
ENV['SEQUENT_ENV'] ||= ENV['RAILS_ENV'] || ENV['RACK_ENV']
|
23
|
+
end
|
24
|
+
|
25
|
+
desc <<~EOS
|
26
|
+
Rake task that runs before all sequent rake tasks and after the environment is set.
|
27
|
+
Hook applications can use to for instance run other rake tasks:
|
28
|
+
|
29
|
+
Rake::Task['sequent:init'].enhance(['my_task'])
|
30
|
+
|
31
|
+
EOS
|
32
|
+
task init: :set_env_var
|
21
33
|
|
22
34
|
namespace :db do
|
23
35
|
desc 'Creates the database and initializes the event_store schema for the current env'
|
24
36
|
task create: ['sequent:init'] do
|
25
|
-
|
37
|
+
ensure_sequent_env_set!
|
26
38
|
|
27
39
|
db_config = Sequent::Support::Database.read_config(@env)
|
28
40
|
Sequent::Support::Database.create!(db_config)
|
29
41
|
|
30
|
-
|
42
|
+
Sequent::Migrations::SequentSchema.create_sequent_schema_if_not_exists(env: @env, fail_if_exists: true)
|
31
43
|
end
|
32
44
|
|
33
45
|
desc 'Drops the database for the current env'
|
34
46
|
task :drop, [:production] => ['sequent:init'] do |_t, args|
|
35
|
-
|
47
|
+
ensure_sequent_env_set!
|
36
48
|
|
37
49
|
if @env == 'production' && args[:production] != 'yes_drop_production'
|
38
50
|
fail <<~OES
|
@@ -46,39 +58,30 @@ module Sequent
|
|
46
58
|
|
47
59
|
desc 'Creates the view schema for the current env'
|
48
60
|
task create_view_schema: ['sequent:init'] do
|
49
|
-
|
61
|
+
ensure_sequent_env_set!
|
50
62
|
|
51
|
-
|
52
|
-
Sequent::Support::Database.establish_connection(db_config)
|
53
|
-
Sequent::Migrations::ViewSchema.new(db_config: db_config).create_view_schema_if_not_exists
|
63
|
+
Sequent::Migrations::ViewSchema.create_view_schema_if_not_exists(env: @env)
|
54
64
|
end
|
55
65
|
|
56
66
|
desc 'Creates the event_store schema for the current env'
|
57
67
|
task create_event_store: ['sequent:init'] do
|
58
|
-
|
59
|
-
|
60
|
-
create_event_store(db_config)
|
68
|
+
ensure_sequent_env_set!
|
69
|
+
Sequent::Migrations::SequentSchema.create_sequent_schema_if_not_exists(env: @env, fail_if_exists: true)
|
61
70
|
end
|
62
71
|
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
unless File.exist?(sequent_schema)
|
68
|
-
fail "File #{sequent_schema} does not exist. Check your Sequent configuration."
|
69
|
-
end
|
72
|
+
desc 'Utility tasks that can be used to guard against unsafe usage of rails db:migrate directly'
|
73
|
+
task :dont_use_db_migrate_directly do
|
74
|
+
fail <<~EOS unless ENV['SEQUENT_MIGRATION_SCHEMAS'].present?
|
75
|
+
Don't call rails db:migrate directly but wrap in your own task instead:
|
70
76
|
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
77
|
+
task :migrate_db do
|
78
|
+
ENV['SEQUENT_MIGRATION_SCHEMAS'] = 'public'
|
79
|
+
Rake::Task['db:migrate'].invoke
|
80
|
+
end
|
75
81
|
|
76
|
-
|
77
|
-
|
78
|
-
load(sequent_schema)
|
79
|
-
end
|
82
|
+
You can choose whatever name for migrate_db you like.
|
83
|
+
EOS
|
80
84
|
end
|
81
|
-
# rubocop:enable Lint/NestedMethodDefinition
|
82
85
|
end
|
83
86
|
|
84
87
|
namespace :migrate do
|
@@ -89,7 +92,7 @@ module Sequent
|
|
89
92
|
|
90
93
|
desc 'Prints the current version in the database'
|
91
94
|
task current_version: ['sequent:init', :init] do
|
92
|
-
|
95
|
+
ensure_sequent_env_set!
|
93
96
|
|
94
97
|
Sequent::Support::Database.connect!(@env)
|
95
98
|
|
@@ -100,7 +103,7 @@ module Sequent
|
|
100
103
|
Migrates the Projectors while the app is running. Call +sequent:migrate:offline+ after this successfully completed.
|
101
104
|
EOS
|
102
105
|
task online: ['sequent:init', :init] do
|
103
|
-
|
106
|
+
ensure_sequent_env_set!
|
104
107
|
|
105
108
|
db_config = Sequent::Support::Database.read_config(@env)
|
106
109
|
view_schema = Sequent::Migrations::ViewSchema.new(db_config: db_config)
|
@@ -112,7 +115,7 @@ module Sequent
|
|
112
115
|
Migrates the events inserted while +online+ was running. It is expected +sequent:migrate:online+ ran first.
|
113
116
|
EOS
|
114
117
|
task offline: ['sequent:init', :init] do
|
115
|
-
|
118
|
+
ensure_sequent_env_set!
|
116
119
|
|
117
120
|
db_config = Sequent::Support::Database.read_config(@env)
|
118
121
|
view_schema = Sequent::Migrations::ViewSchema.new(db_config: db_config)
|
@@ -160,8 +163,8 @@ module Sequent
|
|
160
163
|
private
|
161
164
|
|
162
165
|
# rubocop:disable Naming/MemoizedInstanceVariableName
|
163
|
-
def
|
164
|
-
@env ||= ENV['
|
166
|
+
def ensure_sequent_env_set!
|
167
|
+
@env ||= ENV['SEQUENT_ENV'] || fail('SEQUENT_ENV not set')
|
165
168
|
end
|
166
169
|
# rubocop:enable Naming/MemoizedInstanceVariableName
|
167
170
|
end
|
@@ -1,5 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require 'erb'
|
3
4
|
require 'active_support/hash_with_indifferent_access'
|
4
5
|
|
5
6
|
module Sequent
|
@@ -30,17 +31,37 @@ module Sequent
|
|
30
31
|
end
|
31
32
|
|
32
33
|
def self.create!(db_config)
|
33
|
-
|
34
|
-
ActiveRecord::Base.connection.create_database(db_config
|
34
|
+
establish_connection(db_config, {database: 'postgres'})
|
35
|
+
ActiveRecord::Base.connection.create_database(get_db_config_attribute(db_config, :database))
|
35
36
|
end
|
36
37
|
|
37
38
|
def self.drop!(db_config)
|
38
|
-
|
39
|
-
ActiveRecord::Base.connection.drop_database(db_config
|
39
|
+
establish_connection(db_config, {database: 'postgres'})
|
40
|
+
ActiveRecord::Base.connection.drop_database(get_db_config_attribute(db_config, :database))
|
40
41
|
end
|
41
42
|
|
42
|
-
def self.
|
43
|
-
|
43
|
+
def self.get_db_config_attribute(db_config, attribute)
|
44
|
+
if Sequent.configuration.can_use_multiple_databases?
|
45
|
+
db_config[Sequent.configuration.primary_database_key][attribute]
|
46
|
+
else
|
47
|
+
db_config[attribute]
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
def self.establish_connection(db_config, db_config_overrides = {})
|
52
|
+
if Sequent.configuration.can_use_multiple_databases?
|
53
|
+
db_config = db_config.deep_merge(
|
54
|
+
Sequent.configuration.primary_database_key => db_config_overrides,
|
55
|
+
).stringify_keys
|
56
|
+
ActiveRecord.legacy_connection_handling = false
|
57
|
+
ActiveRecord::Base.configurations = db_config.stringify_keys
|
58
|
+
ActiveRecord::Base.connects_to database: {
|
59
|
+
Sequent.configuration.primary_database_role => Sequent.configuration.primary_database_key,
|
60
|
+
}
|
61
|
+
else
|
62
|
+
db_config = db_config.merge(db_config_overrides)
|
63
|
+
ActiveRecord::Base.establish_connection(db_config)
|
64
|
+
end
|
44
65
|
end
|
45
66
|
|
46
67
|
def self.disconnect!
|
@@ -62,25 +83,20 @@ module Sequent
|
|
62
83
|
execute_sql "DROP SCHEMA if exists #{schema_name} cascade"
|
63
84
|
end
|
64
85
|
|
65
|
-
def self.with_schema_search_path(search_path, db_config, env = ENV['
|
86
|
+
def self.with_schema_search_path(search_path, db_config, env = ENV['SEQUENT_ENV'])
|
66
87
|
fail ArgumentError, 'env is required' unless env
|
67
88
|
|
68
89
|
disconnect!
|
69
|
-
original_search_paths = db_config[:schema_search_path].dup
|
70
90
|
|
71
91
|
if ActiveRecord::VERSION::MAJOR < 6
|
72
92
|
ActiveRecord::Base.configurations[env.to_s] =
|
73
93
|
ActiveSupport::HashWithIndifferentAccess.new(db_config).stringify_keys
|
74
94
|
end
|
75
95
|
|
76
|
-
db_config
|
77
|
-
|
78
|
-
ActiveRecord::Base.establish_connection db_config
|
79
|
-
|
96
|
+
establish_connection(db_config, {schema_search_path: search_path})
|
80
97
|
yield
|
81
98
|
ensure
|
82
99
|
disconnect!
|
83
|
-
db_config[:schema_search_path] = original_search_paths
|
84
100
|
establish_connection(db_config)
|
85
101
|
end
|
86
102
|
|
@@ -125,7 +125,7 @@ module Sequent
|
|
125
125
|
def aggregate_type_for_event(event)
|
126
126
|
@event_to_aggregate_type ||= ThreadSafe::Cache.new
|
127
127
|
@event_to_aggregate_type.fetch_or_store(event.class) do |klass|
|
128
|
-
Sequent::Core::
|
128
|
+
Sequent::Core::AggregateRoot.descendants.find { |x| x.message_mapping.key?(klass) }
|
129
129
|
end
|
130
130
|
end
|
131
131
|
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Sequent
|
4
|
+
module Test
|
5
|
+
module DatabaseHelpers
|
6
|
+
ALLOWED_ENVS = %w[development test spec].freeze
|
7
|
+
|
8
|
+
class << self
|
9
|
+
# Utility method to let Sequent handle creation of sequent_schema and view_schema
|
10
|
+
# rather than using the available rake tasks.
|
11
|
+
def maintain_test_database_schema(env: 'test')
|
12
|
+
fail ArgumentError, "env must one of [#{ALLOWED_ENVS.join(',')}] '#{env}'" unless ALLOWED_ENVS.include?(env)
|
13
|
+
|
14
|
+
Migrations::SequentSchema.create_sequent_schema_if_not_exists(env: env, fail_if_exists: false)
|
15
|
+
Migrations::ViewSchema.create_view_tables(env: env)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -17,11 +17,8 @@ module Sequent
|
|
17
17
|
# omit nsec in datetime comparisons
|
18
18
|
def <=>(other)
|
19
19
|
if other&.is_a?(DateTimePatches::Normalize)
|
20
|
-
|
21
|
-
return
|
22
|
-
|
23
|
-
# use usec here, which *truncates* the nsec (ie. like Postgres)
|
24
|
-
return normalize.usec <=> other.normalize.usec
|
20
|
+
precision = Sequent.configuration.time_precision
|
21
|
+
return normalize.iso8601(precision) <=> other.normalize.iso8601(precision)
|
25
22
|
end
|
26
23
|
public_send(:'___<=>', other)
|
27
24
|
end
|
@@ -5,7 +5,7 @@ module Sequent
|
|
5
5
|
##
|
6
6
|
# Use in tests
|
7
7
|
#
|
8
|
-
# This provides a nice DSL for testing your
|
8
|
+
# This provides a nice DSL for testing your Workflows.
|
9
9
|
# E.g.
|
10
10
|
#
|
11
11
|
# when_event UserWasRegistered.new(args)
|
@@ -14,12 +14,15 @@ module Sequent
|
|
14
14
|
# Example for Rspec config
|
15
15
|
#
|
16
16
|
# RSpec.configure do |config|
|
17
|
-
# config.include Sequent::Test::WorkflowHelpers
|
17
|
+
# config.include Sequent::Test::WorkflowHelpers, workflows: true
|
18
18
|
# end
|
19
19
|
#
|
20
|
-
#
|
20
|
+
# Please note that you **must** add the metadata tag `workflows` since
|
21
|
+
# the WorkflowHelpers will use a `FakeCommandService` to track
|
22
|
+
# the commands enqueued for execution. You can set the metadata
|
23
|
+
# on group level or on an individual spec.
|
21
24
|
#
|
22
|
-
# describe SendWelcomeMailWorkflow do
|
25
|
+
# describe SendWelcomeMailWorkflow, workflows: true do
|
23
26
|
# let(:workflow) { SendWelcomeMailWorkflow.new }
|
24
27
|
#
|
25
28
|
# it "sends a welcome mail" do
|
@@ -75,7 +78,9 @@ module Sequent
|
|
75
78
|
end
|
76
79
|
|
77
80
|
def when_event(event)
|
78
|
-
|
81
|
+
fake_transaction_provider.transactional do
|
82
|
+
workflow.handle_message event
|
83
|
+
end
|
79
84
|
end
|
80
85
|
|
81
86
|
def then_commands(*commands)
|
@@ -86,13 +91,22 @@ module Sequent
|
|
86
91
|
end
|
87
92
|
|
88
93
|
def self.included(spec)
|
94
|
+
fail "Missing metadata argument `workflows: true` when including #{name}" unless spec.metadata[:workflows]
|
95
|
+
|
89
96
|
spec.let(:fake_command_service) { FakeCommandService.new }
|
90
97
|
spec.let(:fake_transaction_provider) { FakeTransactionProvider.new }
|
91
|
-
spec.
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
98
|
+
spec.let(:old_config) { Sequent.configuration }
|
99
|
+
spec.before :each, :workflows do
|
100
|
+
new_config = old_config.dup
|
101
|
+
|
102
|
+
new_config.command_service = fake_command_service
|
103
|
+
new_config.transaction_provider = fake_transaction_provider
|
104
|
+
|
105
|
+
Sequent::Configuration.restore(new_config)
|
106
|
+
end
|
107
|
+
|
108
|
+
spec.after :each, :workflows do
|
109
|
+
Sequent::Configuration.restore(old_config)
|
96
110
|
end
|
97
111
|
end
|
98
112
|
end
|
data/lib/sequent/test.rb
CHANGED
data/lib/sequent/util/dry_run.rb
CHANGED
@@ -66,7 +66,7 @@ module Sequent
|
|
66
66
|
end
|
67
67
|
|
68
68
|
def process_event(event)
|
69
|
-
[*Sequent::Core::
|
69
|
+
[*Sequent::Core::Workflow.descendants, *Sequent::Core::Projector.descendants].each do |handler_class|
|
70
70
|
next unless handler_class.handles_message?(event)
|
71
71
|
|
72
72
|
if handler_class < Sequent::Workflow
|
data/lib/version.rb
CHANGED
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:
|
4
|
+
version: 6.0.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:
|
15
|
+
date: 2023-09-01 00:00:00.000000000 Z
|
16
16
|
dependencies:
|
17
17
|
- !ruby/object:Gem::Dependency
|
18
18
|
name: activemodel
|
@@ -119,7 +119,7 @@ dependencies:
|
|
119
119
|
version: 2.6.5
|
120
120
|
- - "<"
|
121
121
|
- !ruby/object:Gem::Version
|
122
|
-
version: '3.
|
122
|
+
version: '3.3'
|
123
123
|
type: :runtime
|
124
124
|
prerelease: false
|
125
125
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -129,7 +129,7 @@ dependencies:
|
|
129
129
|
version: 2.6.5
|
130
130
|
- - "<"
|
131
131
|
- !ruby/object:Gem::Version
|
132
|
-
version: '3.
|
132
|
+
version: '3.3'
|
133
133
|
- !ruby/object:Gem::Dependency
|
134
134
|
name: pg
|
135
135
|
requirement: !ruby/object:Gem::Requirement
|
@@ -304,7 +304,7 @@ email:
|
|
304
304
|
- bforma@zilverline.com
|
305
305
|
- erozendaal@zilverline.com
|
306
306
|
- mvdiepen@zilverline.com
|
307
|
-
-
|
307
|
+
- stephan@vandiepen.info
|
308
308
|
executables:
|
309
309
|
- sequent
|
310
310
|
extensions: []
|
@@ -370,9 +370,12 @@ files:
|
|
370
370
|
- lib/sequent/core/helpers/string_support.rb
|
371
371
|
- lib/sequent/core/helpers/string_to_value_parsers.rb
|
372
372
|
- lib/sequent/core/helpers/string_validator.rb
|
373
|
+
- lib/sequent/core/helpers/time_validator.rb
|
373
374
|
- lib/sequent/core/helpers/type_conversion_support.rb
|
374
375
|
- lib/sequent/core/helpers/uuid_helper.rb
|
375
376
|
- lib/sequent/core/helpers/value_validators.rb
|
377
|
+
- lib/sequent/core/middleware/chain.rb
|
378
|
+
- lib/sequent/core/middleware/middleware.rb
|
376
379
|
- lib/sequent/core/persistors/active_record_persistor.rb
|
377
380
|
- lib/sequent/core/persistors/persistor.rb
|
378
381
|
- lib/sequent/core/persistors/persistors.rb
|
@@ -425,10 +428,10 @@ files:
|
|
425
428
|
- lib/sequent/migrations/migrations.rb
|
426
429
|
- lib/sequent/migrations/planner.rb
|
427
430
|
- lib/sequent/migrations/projectors.rb
|
431
|
+
- lib/sequent/migrations/sequent_schema.rb
|
428
432
|
- lib/sequent/migrations/sql.rb
|
429
433
|
- lib/sequent/migrations/view_schema.rb
|
430
434
|
- lib/sequent/rake/migration_tasks.rb
|
431
|
-
- lib/sequent/rake/tasks.rb
|
432
435
|
- lib/sequent/sequent.rb
|
433
436
|
- lib/sequent/support.rb
|
434
437
|
- lib/sequent/support/database.rb
|
@@ -436,9 +439,10 @@ files:
|
|
436
439
|
- lib/sequent/support/view_schema.rb
|
437
440
|
- lib/sequent/test.rb
|
438
441
|
- lib/sequent/test/command_handler_helpers.rb
|
439
|
-
- lib/sequent/test/
|
442
|
+
- lib/sequent/test/database_helpers.rb
|
440
443
|
- lib/sequent/test/event_stream_helpers.rb
|
441
444
|
- lib/sequent/test/time_comparison.rb
|
445
|
+
- lib/sequent/test/workflow_helpers.rb
|
442
446
|
- lib/sequent/util/dry_run.rb
|
443
447
|
- lib/sequent/util/printer.rb
|
444
448
|
- lib/sequent/util/skip_if_already_processing.rb
|
data/lib/sequent/rake/tasks.rb
DELETED
@@ -1,121 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'active_record'
|
4
|
-
require 'rake'
|
5
|
-
require 'rake/tasklib'
|
6
|
-
|
7
|
-
require 'sequent/support'
|
8
|
-
|
9
|
-
module Sequent
|
10
|
-
module Rake
|
11
|
-
class Tasks < ::Rake::TaskLib
|
12
|
-
include ::Rake::DSL
|
13
|
-
|
14
|
-
DEFAULT_OPTIONS = {
|
15
|
-
migrations_path: 'db/migrate',
|
16
|
-
event_store_schema: 'public',
|
17
|
-
}.freeze
|
18
|
-
|
19
|
-
attr_reader :options
|
20
|
-
|
21
|
-
def initialize(options)
|
22
|
-
super()
|
23
|
-
@options = DEFAULT_OPTIONS.merge(options)
|
24
|
-
end
|
25
|
-
|
26
|
-
def display_deprecation_warning
|
27
|
-
warn '[DEPRECATED] Sequent::Rake::Tasks is deprecated. Please use Sequent::Rake::MigrationTasks tasks instead.'
|
28
|
-
end
|
29
|
-
|
30
|
-
def register!
|
31
|
-
display_deprecation_warning
|
32
|
-
|
33
|
-
register_db_tasks!
|
34
|
-
register_view_schema_tasks!
|
35
|
-
end
|
36
|
-
|
37
|
-
def register_db_tasks!
|
38
|
-
namespace :db do
|
39
|
-
desc 'Create the database'
|
40
|
-
task :create do
|
41
|
-
display_deprecation_warning
|
42
|
-
|
43
|
-
current_environments.each do |env|
|
44
|
-
env_db = db_config(env)
|
45
|
-
puts "Create database #{env_db['database']}"
|
46
|
-
Sequent::Support::Database.create!(env_db)
|
47
|
-
end
|
48
|
-
end
|
49
|
-
|
50
|
-
desc 'Drop the database'
|
51
|
-
task :drop do
|
52
|
-
display_deprecation_warning
|
53
|
-
|
54
|
-
current_environments.each do |env|
|
55
|
-
env_db = db_config(env)
|
56
|
-
puts "Drop database #{env_db['database']}"
|
57
|
-
Sequent::Support::Database.drop!(env_db)
|
58
|
-
end
|
59
|
-
end
|
60
|
-
|
61
|
-
task :establish_connection do
|
62
|
-
env_db = db_config(options.fetch(:environment))
|
63
|
-
ActiveRecord::Base.establish_connection(env_db)
|
64
|
-
end
|
65
|
-
|
66
|
-
desc 'Migrate the database'
|
67
|
-
task migrate: :establish_connection do
|
68
|
-
display_deprecation_warning
|
69
|
-
|
70
|
-
database.create_schema!(options.fetch(:event_store_schema))
|
71
|
-
database.migrate(options.fetch(:migrations_path))
|
72
|
-
end
|
73
|
-
end
|
74
|
-
end
|
75
|
-
|
76
|
-
def register_view_schema_tasks!
|
77
|
-
namespace :view_schema do
|
78
|
-
desc 'Build the view schema'
|
79
|
-
task build: :'db:establish_connection' do
|
80
|
-
display_deprecation_warning
|
81
|
-
|
82
|
-
if database.schema_exists?(view_projection.schema_name)
|
83
|
-
puts "View version #{view_projection.version} already exists; no need to build it"
|
84
|
-
else
|
85
|
-
database.create_schema!(view_projection.schema_name)
|
86
|
-
view_projection.build!
|
87
|
-
end
|
88
|
-
end
|
89
|
-
|
90
|
-
desc 'Drop the view schema'
|
91
|
-
task drop: :'db:establish_connection' do
|
92
|
-
display_deprecation_warning
|
93
|
-
|
94
|
-
database.drop_schema!(view_projection.schema_name)
|
95
|
-
end
|
96
|
-
end
|
97
|
-
end
|
98
|
-
|
99
|
-
private
|
100
|
-
|
101
|
-
def current_environments
|
102
|
-
environment = options.fetch(:environment)
|
103
|
-
envs = [environment]
|
104
|
-
envs << 'test' if environment == 'development'
|
105
|
-
envs
|
106
|
-
end
|
107
|
-
|
108
|
-
def database
|
109
|
-
@database ||= Sequent::Support::Database.new
|
110
|
-
end
|
111
|
-
|
112
|
-
def db_config(environment)
|
113
|
-
options.fetch(:db_config_supplier)[environment] or fail "No database config for #{environment}"
|
114
|
-
end
|
115
|
-
|
116
|
-
def view_projection
|
117
|
-
options.fetch(:view_projection)
|
118
|
-
end
|
119
|
-
end
|
120
|
-
end
|
121
|
-
end
|