ruby_event_store-active_record 2.9.0 → 2.9.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/ruby_event_store/active_record/event_repository_reader.rb +14 -8
- data/lib/ruby_event_store/active_record/generators/migration_generator.rb +14 -6
- data/lib/ruby_event_store/active_record/generators/rails_migration_generator.rb +11 -3
- data/lib/ruby_event_store/active_record/generators/templates/create_event_store_events_template.erb +16 -48
- data/lib/ruby_event_store/active_record/generators/templates/mysql/create_event_store_events_template.erb +23 -0
- data/lib/ruby_event_store/active_record/generators/templates/postgres/create_event_store_events_template.erb +23 -0
- data/lib/ruby_event_store/active_record/generators/templates/template_directory.rb +16 -0
- data/lib/ruby_event_store/active_record/tasks/migration_tasks.rake +3 -1
- data/lib/ruby_event_store/active_record/version.rb +1 -1
- data/lib/ruby_event_store/active_record.rb +1 -0
- metadata +8 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 531bd49e9c928fcdcbdeea01035c260b6019198d2d5357c7ecafe8aa6edcf54e
|
4
|
+
data.tar.gz: 891761c440d9b732ab456177d9b6276994841bcd90aaa1c2eccd37a75bde8360
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 488d98960694b1c32936c7caf1b45901d9355d0cc2a8cbc9be49dc147c2ea57567c56b43387cd4cb46fce796b2914d194852372d8be8dc2deb93b9bea19da8ee
|
7
|
+
data.tar.gz: 69c47a6136633f58af8605b3c371041bb71c84fe425e472867d3b01ff7f66a4ee55c2156d8f75bd28c98f9912e2097a1ed9e2f631b448a692b2e2f775a7ea149
|
@@ -114,11 +114,13 @@ module RubyEventStore
|
|
114
114
|
end
|
115
115
|
|
116
116
|
def as_of(spec)
|
117
|
-
|
117
|
+
expr = coalesce(@event_klass.arel_table[:valid_at], @event_klass.arel_table[:created_at])
|
118
|
+
spec.forward? ? expr.asc : expr.desc
|
118
119
|
end
|
119
120
|
|
120
121
|
def as_at(spec)
|
121
|
-
|
122
|
+
expr = @event_klass.arel_table[:created_at]
|
123
|
+
spec.forward? ? expr.asc : expr.desc
|
122
124
|
end
|
123
125
|
|
124
126
|
def start_offset_condition(specification, record_id, search_in)
|
@@ -163,28 +165,32 @@ module RubyEventStore
|
|
163
165
|
)
|
164
166
|
end
|
165
167
|
|
168
|
+
def coalesce(*exprs)
|
169
|
+
Arel::Nodes::NamedFunction.new "COALESCE", exprs
|
170
|
+
end
|
171
|
+
|
166
172
|
def time_comparison_field(specification)
|
167
173
|
if specification.time_sort_by_as_of?
|
168
|
-
|
174
|
+
coalesce(@event_klass.arel_table[:valid_at], @event_klass.arel_table[:created_at])
|
169
175
|
else
|
170
|
-
|
176
|
+
@event_klass.arel_table[:created_at]
|
171
177
|
end
|
172
178
|
end
|
173
179
|
|
174
180
|
def older_than_condition(specification)
|
175
|
-
|
181
|
+
time_comparison_field(specification).lt(specification.older_than)
|
176
182
|
end
|
177
183
|
|
178
184
|
def older_than_or_equal_condition(specification)
|
179
|
-
|
185
|
+
time_comparison_field(specification).lteq(specification.older_than_or_equal)
|
180
186
|
end
|
181
187
|
|
182
188
|
def newer_than_condition(specification)
|
183
|
-
|
189
|
+
time_comparison_field(specification).gt(specification.newer_than)
|
184
190
|
end
|
185
191
|
|
186
192
|
def newer_than_or_equal_condition(specification)
|
187
|
-
|
193
|
+
time_comparison_field(specification).gteq(specification.newer_than_or_equal)
|
188
194
|
end
|
189
195
|
|
190
196
|
def order(spec)
|
@@ -6,10 +6,10 @@ module RubyEventStore
|
|
6
6
|
class MigrationGenerator
|
7
7
|
DATA_TYPES = %w[binary json jsonb].freeze
|
8
8
|
|
9
|
-
def call(data_type, migration_path)
|
9
|
+
def call(data_type, database_adapter, migration_path)
|
10
10
|
raise ArgumentError, "Invalid value for data type. Supported for options are: #{DATA_TYPES.join(", ")}." unless DATA_TYPES.include?(data_type)
|
11
11
|
|
12
|
-
migration_code = migration_code(data_type)
|
12
|
+
migration_code = migration_code(data_type, database_adapter)
|
13
13
|
path = build_path(migration_path)
|
14
14
|
write_to_file(migration_code, path)
|
15
15
|
path
|
@@ -21,8 +21,16 @@ module RubyEventStore
|
|
21
21
|
File.expand_path(path, __dir__)
|
22
22
|
end
|
23
23
|
|
24
|
-
def migration_code(data_type)
|
25
|
-
migration_template(
|
24
|
+
def migration_code(data_type, database_adapter)
|
25
|
+
migration_template(template_root(database_adapter), "create_event_store_events").result_with_hash(migration_version: migration_version, data_type: data_type)
|
26
|
+
end
|
27
|
+
|
28
|
+
def template_root(database_adapter)
|
29
|
+
absolute_path("./templates/#{template_directory(database_adapter)}")
|
30
|
+
end
|
31
|
+
|
32
|
+
def template_directory(database_adapter)
|
33
|
+
TemplateDirectory.for_adapter(database_adapter)
|
26
34
|
end
|
27
35
|
|
28
36
|
def migration_template(template_root, name)
|
@@ -30,7 +38,7 @@ module RubyEventStore
|
|
30
38
|
end
|
31
39
|
|
32
40
|
def migration_version
|
33
|
-
|
41
|
+
::ActiveRecord::Migration.current_version
|
34
42
|
end
|
35
43
|
|
36
44
|
def timestamp
|
@@ -42,7 +50,7 @@ module RubyEventStore
|
|
42
50
|
end
|
43
51
|
|
44
52
|
def build_path(migration_path)
|
45
|
-
File.join(
|
53
|
+
File.join("#{migration_path}", "#{timestamp}_create_event_store_events.rb")
|
46
54
|
end
|
47
55
|
end
|
48
56
|
end
|
@@ -27,23 +27,31 @@ module RubyEventStore
|
|
27
27
|
def initialize(*args)
|
28
28
|
super
|
29
29
|
|
30
|
-
if DATA_TYPES.exclude?(
|
30
|
+
if DATA_TYPES.exclude?(data_type)
|
31
31
|
raise Error, "Invalid value for --data-type option. Supported for options are: #{DATA_TYPES.join(", ")}."
|
32
32
|
end
|
33
33
|
end
|
34
34
|
|
35
35
|
def create_migration
|
36
|
-
template "create_event_store_events_template.erb", "db/migrate/#{timestamp}_create_event_store_events.rb"
|
36
|
+
template "#{template_directory}create_event_store_events_template.erb", "db/migrate/#{timestamp}_create_event_store_events.rb"
|
37
37
|
end
|
38
38
|
|
39
39
|
private
|
40
40
|
|
41
|
+
def template_directory
|
42
|
+
TemplateDirectory.for_adapter(adapter)
|
43
|
+
end
|
44
|
+
|
41
45
|
def data_type
|
42
46
|
options.fetch("data_type")
|
43
47
|
end
|
44
48
|
|
49
|
+
def adapter
|
50
|
+
::ActiveRecord::Base.connection.adapter_name.downcase
|
51
|
+
end
|
52
|
+
|
45
53
|
def migration_version
|
46
|
-
|
54
|
+
::ActiveRecord::Migration.current_version
|
47
55
|
end
|
48
56
|
|
49
57
|
def timestamp
|
data/lib/ruby_event_store/active_record/generators/templates/create_event_store_events_template.erb
CHANGED
@@ -1,55 +1,23 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
class CreateEventStoreEvents < ActiveRecord::Migration<%= migration_version %>
|
3
|
+
class CreateEventStoreEvents < ActiveRecord::Migration[<%= migration_version %>]
|
4
4
|
def change
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
end
|
14
|
-
add_index :event_store_events_in_streams, [:stream, :position], unique: true
|
15
|
-
add_index :event_store_events_in_streams, [:created_at]
|
16
|
-
add_index :event_store_events_in_streams, [:stream, :event_id], unique: true
|
17
|
-
|
18
|
-
create_table(:event_store_events, id: :bigserial, force: false) do |t|
|
19
|
-
t.references :event, null: false, type: :uuid
|
20
|
-
t.string :event_type, null: false
|
21
|
-
t.<%= data_type %> :metadata
|
22
|
-
t.<%= data_type %> :data, null: false
|
23
|
-
t.datetime :created_at, null: false
|
24
|
-
t.datetime :valid_at, null: true
|
25
|
-
end
|
26
|
-
add_index :event_store_events, :event_id, unique: true
|
27
|
-
add_index :event_store_events, :created_at
|
28
|
-
add_index :event_store_events, :valid_at
|
29
|
-
add_index :event_store_events, :event_type
|
30
|
-
else
|
31
|
-
create_table(:event_store_events_in_streams, force: false) do |t|
|
32
|
-
t.string :stream, null: false
|
33
|
-
t.integer :position, null: true
|
34
|
-
t.references :event, null: false, type: :string, limit: 36
|
35
|
-
t.datetime :created_at, null: false, precision: 6
|
36
|
-
end
|
37
|
-
add_index :event_store_events_in_streams, [:stream, :position], unique: true
|
38
|
-
add_index :event_store_events_in_streams, [:created_at]
|
39
|
-
add_index :event_store_events_in_streams, [:stream, :event_id], unique: true
|
5
|
+
create_table(:event_store_events_in_streams, force: false) do |t|
|
6
|
+
t.string :stream, null: false
|
7
|
+
t.integer :position, null: true
|
8
|
+
t.references :event, null: false, type: :string, limit: 36, index: false
|
9
|
+
t.datetime :created_at, null: false, precision: 6, index: true
|
10
|
+
end
|
11
|
+
add_index :event_store_events_in_streams, [:stream, :position], unique: true
|
12
|
+
add_index :event_store_events_in_streams, [:stream, :event_id], unique: true
|
40
13
|
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
end
|
49
|
-
add_index :event_store_events, :event_id, unique: true
|
50
|
-
add_index :event_store_events, :created_at
|
51
|
-
add_index :event_store_events, :valid_at
|
52
|
-
add_index :event_store_events, :event_type
|
14
|
+
create_table(:event_store_events, force: false) do |t|
|
15
|
+
t.references :event, null: false, type: :string, limit: 36, index: { unique: true }
|
16
|
+
t.string :event_type, null: false, index: true
|
17
|
+
t.binary :metadata
|
18
|
+
t.binary :data, null: false
|
19
|
+
t.datetime :created_at, null: false, precision: 6, index: true
|
20
|
+
t.datetime :valid_at, null: true, precision: 6, index: true
|
53
21
|
end
|
54
22
|
end
|
55
23
|
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class CreateEventStoreEvents < ActiveRecord::Migration[<%= migration_version %>]
|
4
|
+
def change
|
5
|
+
create_table(:event_store_events_in_streams, force: false) do |t|
|
6
|
+
t.string :stream, null: false
|
7
|
+
t.integer :position, null: true
|
8
|
+
t.references :event, null: false, type: :string, limit: 36, index: false
|
9
|
+
t.datetime :created_at, null: false, precision: 6, index: true
|
10
|
+
end
|
11
|
+
add_index :event_store_events_in_streams, [:stream, :position], unique: true
|
12
|
+
add_index :event_store_events_in_streams, [:stream, :event_id], unique: true
|
13
|
+
|
14
|
+
create_table(:event_store_events, force: false) do |t|
|
15
|
+
t.references :event, null: false, type: :string, limit: 36, index: { unique: true }
|
16
|
+
t.string :event_type, null: false, index: true
|
17
|
+
t.binary :metadata
|
18
|
+
t.binary :data, null: false
|
19
|
+
t.datetime :created_at, null: false, precision: 6, index: true
|
20
|
+
t.datetime :valid_at, null: true, precision: 6, index: true
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class CreateEventStoreEvents < ActiveRecord::Migration[<%= migration_version %>]
|
4
|
+
def change
|
5
|
+
create_table(:event_store_events_in_streams, id: :bigserial, force: false) do |t|
|
6
|
+
t.string :stream, null: false
|
7
|
+
t.integer :position, null: true
|
8
|
+
t.references :event, null: false, type: :uuid, index: false
|
9
|
+
t.datetime :created_at, null: false, type: :timestamp, precision: 6, index: true
|
10
|
+
end
|
11
|
+
add_index :event_store_events_in_streams, [:stream, :position], unique: true
|
12
|
+
add_index :event_store_events_in_streams, [:stream, :event_id], unique: true
|
13
|
+
|
14
|
+
create_table(:event_store_events, id: :bigserial, force: false) do |t|
|
15
|
+
t.references :event, null: false, type: :uuid, index: { unique: true }
|
16
|
+
t.string :event_type, null: false, index: true
|
17
|
+
t.<%= data_type %> :metadata
|
18
|
+
t.<%= data_type %> :data, null: false
|
19
|
+
t.datetime :created_at, null: false, type: :timestamp, precision: 6, index: true
|
20
|
+
t.datetime :valid_at, null: true, type: :timestamp, precision: 6, index: true
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RubyEventStore
|
4
|
+
module ActiveRecord
|
5
|
+
class TemplateDirectory
|
6
|
+
def self.for_adapter(database_adapter)
|
7
|
+
case database_adapter.downcase
|
8
|
+
when "postgresql"
|
9
|
+
"postgres/"
|
10
|
+
when "mysql2"
|
11
|
+
"mysql/"
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -3,10 +3,12 @@ require_relative "../generators/migration_generator"
|
|
3
3
|
desc "Generate migration"
|
4
4
|
task "db:migrations:copy" do
|
5
5
|
data_type = ENV["DATA_TYPE"] || raise("Specify data type (binary, json, jsonb): rake db:migrations:copy DATA_TYPE=json")
|
6
|
+
::ActiveRecord::Base.establish_connection(ENV["DATABASE_URL"])
|
7
|
+
database_adapter = ::ActiveRecord::Base.connection.adapter_name
|
6
8
|
|
7
9
|
path = RubyEventStore::ActiveRecord::MigrationGenerator
|
8
10
|
.new
|
9
|
-
.call(data_type, ENV["MIGRATION_PATH"] || "db/migrate")
|
11
|
+
.call(data_type, database_adapter, ENV["MIGRATION_PATH"] || "db/migrate")
|
10
12
|
|
11
13
|
puts "Migration file created #{path}"
|
12
14
|
end
|
@@ -2,6 +2,7 @@
|
|
2
2
|
|
3
3
|
require_relative "active_record/generators/migration_generator"
|
4
4
|
require_relative "active_record/generators/rails_migration_generator"
|
5
|
+
require_relative "active_record/generators/templates/template_directory"
|
5
6
|
require_relative "active_record/event"
|
6
7
|
require_relative "active_record/with_default_models"
|
7
8
|
require_relative "active_record/with_abstract_base_class"
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ruby_event_store-active_record
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.9.
|
4
|
+
version: 2.9.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Arkency
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-
|
11
|
+
date: 2023-02-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: ruby_event_store
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - '='
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: 2.9.
|
19
|
+
version: 2.9.1
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - '='
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: 2.9.
|
26
|
+
version: 2.9.1
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: activerecord
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -60,6 +60,9 @@ files:
|
|
60
60
|
- lib/ruby_event_store/active_record/generators/migration_generator.rb
|
61
61
|
- lib/ruby_event_store/active_record/generators/rails_migration_generator.rb
|
62
62
|
- lib/ruby_event_store/active_record/generators/templates/create_event_store_events_template.erb
|
63
|
+
- lib/ruby_event_store/active_record/generators/templates/mysql/create_event_store_events_template.erb
|
64
|
+
- lib/ruby_event_store/active_record/generators/templates/postgres/create_event_store_events_template.erb
|
65
|
+
- lib/ruby_event_store/active_record/generators/templates/template_directory.rb
|
63
66
|
- lib/ruby_event_store/active_record/index_violation_detector.rb
|
64
67
|
- lib/ruby_event_store/active_record/pg_linearized_event_repository.rb
|
65
68
|
- lib/ruby_event_store/active_record/railtie.rb
|
@@ -92,7 +95,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
92
95
|
- !ruby/object:Gem::Version
|
93
96
|
version: '0'
|
94
97
|
requirements: []
|
95
|
-
rubygems_version: 3.3.
|
98
|
+
rubygems_version: 3.3.7
|
96
99
|
signing_key:
|
97
100
|
specification_version: 4
|
98
101
|
summary: Persistent event repository implementation for RubyEventStore based on ActiveRecord
|