rails_event_store_active_record 2.2.0 → 2.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/rails_event_store_active_record/event.rb +3 -3
- data/lib/rails_event_store_active_record/event_repository.rb +11 -5
- data/lib/rails_event_store_active_record/event_repository_reader.rb +21 -3
- data/lib/rails_event_store_active_record/generators/migration_generator.rb +4 -4
- data/lib/rails_event_store_active_record/generators/templates/create_event_store_events_template.rb +30 -25
- data/lib/rails_event_store_active_record/pg_linearized_event_repository.rb +1 -1
- data/lib/rails_event_store_active_record/version.rb +1 -1
- data/lib/rails_event_store_active_record/with_abstract_base_class.rb +2 -2
- data/lib/rails_event_store_active_record.rb +10 -10
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 47f9fb4041eeafab89312eabfbf9cada70da41480032fef06dcf3311f0e35d56
|
4
|
+
data.tar.gz: 79e021816506f4e49ff72e6f66f66820c9d588a30d1f3f8736d29cc478400340
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cfc072dd9e99031459dcc037cece006477f08c8b5ec014b592f579b3de403e57b7224a68691548b6e2e1b1d0d735aba841cb7a969f0d22916b8165360f4d64df
|
7
|
+
data.tar.gz: 440e6a1a06e37a05ec12590de43be4445314c8244d480f8a8a2ad261e5adcce05e5aa2115a9001011fcb063779ab6a74ff4e518dc0a463812bebe0eea67c50ff
|
@@ -1,16 +1,16 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require
|
3
|
+
require "active_record"
|
4
4
|
|
5
5
|
module RailsEventStoreActiveRecord
|
6
6
|
class Event < ::ActiveRecord::Base
|
7
7
|
self.primary_key = :id
|
8
|
-
self.table_name =
|
8
|
+
self.table_name = "event_store_events"
|
9
9
|
end
|
10
10
|
|
11
11
|
class EventInStream < ::ActiveRecord::Base
|
12
12
|
self.primary_key = :id
|
13
|
-
self.table_name =
|
13
|
+
self.table_name = "event_store_events_in_streams"
|
14
14
|
belongs_to :event, primary_key: :event_id
|
15
15
|
end
|
16
16
|
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require
|
4
|
-
require
|
3
|
+
require "active_support/core_ext/array"
|
4
|
+
require "activerecord-import"
|
5
5
|
|
6
6
|
module RailsEventStoreActiveRecord
|
7
7
|
class EventRepository
|
@@ -66,9 +66,15 @@ module RailsEventStoreActiveRecord
|
|
66
66
|
end
|
67
67
|
|
68
68
|
def streams_of(event_id)
|
69
|
-
@
|
70
|
-
|
71
|
-
|
69
|
+
@repo_reader.streams_of(event_id)
|
70
|
+
end
|
71
|
+
|
72
|
+
def position_in_stream(event_id, stream)
|
73
|
+
@repo_reader.position_in_stream(event_id, stream)
|
74
|
+
end
|
75
|
+
|
76
|
+
def global_position(event_id)
|
77
|
+
@repo_reader.global_position(event_id)
|
72
78
|
end
|
73
79
|
|
74
80
|
private
|
@@ -14,7 +14,7 @@ module RailsEventStoreActiveRecord
|
|
14
14
|
end
|
15
15
|
|
16
16
|
def last_stream_event(stream)
|
17
|
-
record_ = @stream_klass.where(stream: stream.name).order(
|
17
|
+
record_ = @stream_klass.where(stream: stream.name).order("position DESC, id DESC").first
|
18
18
|
record(record_) if record_
|
19
19
|
end
|
20
20
|
|
@@ -37,6 +37,24 @@ module RailsEventStoreActiveRecord
|
|
37
37
|
read_scope(spec).count
|
38
38
|
end
|
39
39
|
|
40
|
+
def streams_of(event_id)
|
41
|
+
@stream_klass.where(event_id: event_id)
|
42
|
+
.pluck(:stream)
|
43
|
+
.map { |name| RubyEventStore::Stream.new(name) }
|
44
|
+
end
|
45
|
+
|
46
|
+
def position_in_stream(event_id, stream)
|
47
|
+
record = @stream_klass.select("position").where(stream: stream.name).find_by(event_id: event_id)
|
48
|
+
raise RubyEventStore::EventNotFoundInStream if record.nil?
|
49
|
+
record.position
|
50
|
+
end
|
51
|
+
|
52
|
+
def global_position(event_id)
|
53
|
+
record = @event_klass.select("id").find_by(event_id: event_id)
|
54
|
+
raise RubyEventStore::EventNotFound.new(event_id) if record.nil?
|
55
|
+
record.id - 1
|
56
|
+
end
|
57
|
+
|
40
58
|
private
|
41
59
|
attr_reader :serializer
|
42
60
|
|
@@ -78,7 +96,7 @@ module RailsEventStoreActiveRecord
|
|
78
96
|
stream = stream.where(event_id: spec.with_ids) if spec.with_ids?
|
79
97
|
stream = stream.where(@event_klass.table_name => {event_type: spec.with_types}) if spec.with_types?
|
80
98
|
stream = ordered(stream.joins(:event), spec)
|
81
|
-
stream = stream.order(
|
99
|
+
stream = stream.order(id: order(spec))
|
82
100
|
stream = stream.limit(spec.limit) if spec.limit?
|
83
101
|
stream = stream.where(start_condition(spec)) if spec.start
|
84
102
|
stream = stream.where(stop_condition(spec)) if spec.stop
|
@@ -152,7 +170,7 @@ module RailsEventStoreActiveRecord
|
|
152
170
|
end
|
153
171
|
|
154
172
|
def order(spec)
|
155
|
-
spec.forward? ?
|
173
|
+
spec.forward? ? "ASC" : "DESC"
|
156
174
|
end
|
157
175
|
|
158
176
|
def record(record)
|
@@ -1,7 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
begin
|
4
|
-
require
|
4
|
+
require "rails/generators"
|
5
5
|
rescue LoadError
|
6
6
|
end
|
7
7
|
|
@@ -11,11 +11,11 @@ module RailsEventStoreActiveRecord
|
|
11
11
|
|
12
12
|
DATA_TYPES = %w(binary json jsonb).freeze
|
13
13
|
|
14
|
-
source_root File.expand_path(File.join(File.dirname(__FILE__),
|
14
|
+
source_root File.expand_path(File.join(File.dirname(__FILE__), "../generators/templates"))
|
15
15
|
class_option(
|
16
16
|
:data_type,
|
17
17
|
type: :string,
|
18
|
-
default:
|
18
|
+
default: "binary",
|
19
19
|
desc: "Configure the data type for `data` and `meta data` fields in Postgres migration (options: #{DATA_TYPES.join('/')})"
|
20
20
|
)
|
21
21
|
|
@@ -34,7 +34,7 @@ module RailsEventStoreActiveRecord
|
|
34
34
|
private
|
35
35
|
|
36
36
|
def data_type
|
37
|
-
options.fetch(
|
37
|
+
options.fetch("data_type")
|
38
38
|
end
|
39
39
|
|
40
40
|
def migration_version
|
data/lib/rails_event_store_active_record/generators/templates/create_event_store_events_template.rb
CHANGED
@@ -2,37 +2,42 @@
|
|
2
2
|
|
3
3
|
class CreateEventStoreEvents < ActiveRecord::Migration<%= migration_version %>
|
4
4
|
def change
|
5
|
-
postgres =
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
t.references :event, null: false, type: :uuid
|
13
|
-
else
|
14
|
-
t.references :event, null: false, type: :string, limit: 36
|
15
|
-
end
|
16
|
-
if postgres
|
5
|
+
postgres =
|
6
|
+
ActiveRecord::Base.connection.adapter_name == "PostgreSQL"
|
7
|
+
if postgres
|
8
|
+
create_table(:event_store_events_in_streams, id: :bigserial, force: false) do |t|
|
9
|
+
t.string :stream, null: false
|
10
|
+
t.integer :position, null: true
|
11
|
+
t.references :event, null: false, type: :uuid
|
17
12
|
t.datetime :created_at, null: false
|
18
|
-
else
|
19
|
-
t.datetime :created_at, null: false, precision: 6
|
20
13
|
end
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
add_index :event_store_events_in_streams, [:stream, :event_id], unique: true
|
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
|
25
17
|
|
26
|
-
|
27
|
-
create_table(:event_store_events, force: false) do |t|
|
18
|
+
create_table(:event_store_events, id: :bigserial, force: false) do |t|
|
28
19
|
t.references :event, null: false, type: :uuid
|
29
20
|
t.string :event_type, null: false
|
30
21
|
t.<%= data_type %> :metadata
|
31
|
-
t.<%= data_type %> :data,
|
22
|
+
t.<%= data_type %> :data, null: false
|
32
23
|
t.datetime :created_at, null: false
|
33
24
|
t.datetime :valid_at, null: true
|
34
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
|
35
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
|
40
|
+
|
36
41
|
create_table(:event_store_events, force: false) do |t|
|
37
42
|
t.references :event, null: false, type: :string, limit: 36
|
38
43
|
t.string :event_type, null: false
|
@@ -41,10 +46,10 @@ class CreateEventStoreEvents < ActiveRecord::Migration<%= migration_version %>
|
|
41
46
|
t.datetime :created_at, null: false, precision: 6
|
42
47
|
t.datetime :valid_at, null: true, precision: 6
|
43
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
|
44
53
|
end
|
45
|
-
add_index :event_store_events, :event_id, unique: true
|
46
|
-
add_index :event_store_events, :created_at
|
47
|
-
add_index :event_store_events, :valid_at
|
48
|
-
add_index :event_store_events, :event_type
|
49
54
|
end
|
50
55
|
end
|
@@ -21,7 +21,7 @@ module RailsEventStoreActiveRecord
|
|
21
21
|
Object.const_set("Event_#{instance_id}",
|
22
22
|
Class.new(@base_klass) do
|
23
23
|
self.primary_key = :id
|
24
|
-
self.table_name =
|
24
|
+
self.table_name = "event_store_events"
|
25
25
|
end
|
26
26
|
)
|
27
27
|
end
|
@@ -30,7 +30,7 @@ module RailsEventStoreActiveRecord
|
|
30
30
|
Object.const_set("EventInStream_#{instance_id}",
|
31
31
|
Class.new(@base_klass) do
|
32
32
|
self.primary_key = :id
|
33
|
-
self.table_name =
|
33
|
+
self.table_name = "event_store_events_in_streams"
|
34
34
|
belongs_to :event, primary_key: :event_id, class_name: "Event_#{instance_id}"
|
35
35
|
end
|
36
36
|
)
|
@@ -1,12 +1,12 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require_relative
|
4
|
-
require_relative
|
5
|
-
require_relative
|
6
|
-
require_relative
|
7
|
-
require_relative
|
8
|
-
require_relative
|
9
|
-
require_relative
|
10
|
-
require_relative
|
11
|
-
require_relative
|
12
|
-
require_relative
|
3
|
+
require_relative "rails_event_store_active_record/generators/migration_generator"
|
4
|
+
require_relative "rails_event_store_active_record/event"
|
5
|
+
require_relative "rails_event_store_active_record/with_default_models"
|
6
|
+
require_relative "rails_event_store_active_record/with_abstract_base_class"
|
7
|
+
require_relative "rails_event_store_active_record/event_repository"
|
8
|
+
require_relative "rails_event_store_active_record/batch_enumerator"
|
9
|
+
require_relative "rails_event_store_active_record/event_repository_reader"
|
10
|
+
require_relative "rails_event_store_active_record/index_violation_detector"
|
11
|
+
require_relative "rails_event_store_active_record/pg_linearized_event_repository"
|
12
|
+
require_relative "rails_event_store_active_record/version"
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rails_event_store_active_record
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Arkency
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-
|
11
|
+
date: 2021-09-09 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.
|
19
|
+
version: 2.3.0
|
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.
|
26
|
+
version: 2.3.0
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: activerecord
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|