rails_event_store_active_record-legacy 0.28.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/Gemfile +8 -0
- data/Makefile +57 -0
- data/README.md +5 -0
- data/lib/rails_event_store_active_record/legacy/event_repository.rb +127 -0
- data/lib/rails_event_store_active_record/legacy/version.rb +5 -0
- data/lib/rails_event_store_active_record/legacy.rb +6 -0
- data/rails_event_store_active_record-legacy.gemspec +43 -0
- metadata +211 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 8ab119ac21718ff098874a0d1f3a9f9a6d3ebf8e31be590618c1c587326e585d
|
4
|
+
data.tar.gz: 814c5b6c278c0e59f396c334b434fdaa40a6fd9e4fb363a9b10ff1670a44a0aa
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: e899e7e2985dca66426c63066ce719eeac26344e6536be463c948d1bb01fb9d9459af46d364e888a9c2153b56b676723cddbbbfce8ed88d9cd720a5305c44972
|
7
|
+
data.tar.gz: 2d12fb2152109cbb695c856674bb974a7e8bf0527e10bbb202236ebf807fdc7866142c5b0c243c84dde33c9e7c48e585fa8314dd233dc3e03e15fa6d7d1aafd4
|
data/Gemfile
ADDED
data/Makefile
ADDED
@@ -0,0 +1,57 @@
|
|
1
|
+
GEM_VERSION = $(shell cat ../RES_VERSION)
|
2
|
+
GEM_NAME = rails_event_store_active_record-legacy
|
3
|
+
REQUIRE = rails_event_store_active_record/legacy
|
4
|
+
IGNORE =
|
5
|
+
SUBJECT ?= RailsEventStoreActiveRecord::Legacy*
|
6
|
+
DATABASE_URL ?= sqlite3::memory:
|
7
|
+
|
8
|
+
install: ## Install gem dependencies
|
9
|
+
@echo "Installing gem dependencies"
|
10
|
+
@bundle install
|
11
|
+
|
12
|
+
remove-lock:
|
13
|
+
@echo "Removing resolved dependency versions"
|
14
|
+
-rm Gemfile.lock
|
15
|
+
|
16
|
+
reinstall: remove-lock install ## Removing resolved dependency versions
|
17
|
+
|
18
|
+
|
19
|
+
test: ## Run unit tests
|
20
|
+
@echo "Running unit tests"
|
21
|
+
@BUNDLE_GEMFILE=Gemfile bundle exec rspec
|
22
|
+
|
23
|
+
mutate: test ## Run mutation tests
|
24
|
+
@echo "Running mutation tests"
|
25
|
+
@BUNDLE_GEMFILE=Gemfile DATABASE_URL=$(DATABASE_URL) bundle exec mutant --include lib \
|
26
|
+
$(addprefix --require ,$(REQUIRE)) \
|
27
|
+
$(addprefix --ignore-subject ,$(IGNORE)) \
|
28
|
+
--use rspec "$(SUBJECT)"
|
29
|
+
|
30
|
+
mutate-fast: ## Run mutation tests with --fail-fast
|
31
|
+
@echo "Running mutation tests with --fail-fast"
|
32
|
+
@BUNDLE_GEMFILE=Gemfile DATABASE_URL=$(DATABASE_URL) bundle exec mutant --include lib \
|
33
|
+
$(addprefix --require ,$(REQUIRE)) \
|
34
|
+
$(addprefix --ignore-subject ,$(IGNORE)) \
|
35
|
+
--fail-fast \
|
36
|
+
--use rspec "$(SUBJECT)"
|
37
|
+
|
38
|
+
build:
|
39
|
+
@echo "Building gem package"
|
40
|
+
@gem build -V $(GEM_NAME).gemspec
|
41
|
+
@mkdir -p pkg/
|
42
|
+
@mv $(GEM_NAME)-$(GEM_VERSION).gem pkg/
|
43
|
+
|
44
|
+
push:
|
45
|
+
@echo "Pushing package to RubyGems"
|
46
|
+
@gem push -k dev_arkency pkg/$(GEM_NAME)-$(GEM_VERSION).gem
|
47
|
+
|
48
|
+
clean:
|
49
|
+
@echo "Removing previously built package"
|
50
|
+
-rm pkg/$(GEM_NAME)-$(GEM_VERSION).gem
|
51
|
+
|
52
|
+
help:
|
53
|
+
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
|
54
|
+
|
55
|
+
.PHONY: help
|
56
|
+
.DEFAULT_GOAL := help
|
57
|
+
|
data/README.md
ADDED
@@ -0,0 +1,5 @@
|
|
1
|
+
# RailsEventStoreActiveRecord::Legacy
|
2
|
+
|
3
|
+
An Active Record based implementation of events repository for [Rails Event Store](https://github.com/RailsEventStore/rails_event_store).
|
4
|
+
|
5
|
+
This is the legacy repository used in `rails_event_store` gem. Exists for limited backwards-compatibilty and should not be chosen for new projects.
|
@@ -0,0 +1,127 @@
|
|
1
|
+
require 'active_record'
|
2
|
+
|
3
|
+
module RailsEventStoreActiveRecord
|
4
|
+
module Legacy
|
5
|
+
class EventRepository
|
6
|
+
SERIALIZED_GLOBAL_STREAM_NAME = 'all'.freeze
|
7
|
+
|
8
|
+
class LegacyEvent < ::ActiveRecord::Base
|
9
|
+
self.primary_key = :id
|
10
|
+
self.table_name = 'event_store_events'
|
11
|
+
serialize :metadata
|
12
|
+
serialize :data
|
13
|
+
end
|
14
|
+
|
15
|
+
private_constant :LegacyEvent
|
16
|
+
|
17
|
+
def initialize
|
18
|
+
warn <<-MSG
|
19
|
+
`RailsEventStoreActiveRecord::LegacyEventRepository` has been deprecated.
|
20
|
+
|
21
|
+
Please migrate to new database schema and use `RailsEventStoreActiveRecord::EventRepository`
|
22
|
+
instead:
|
23
|
+
|
24
|
+
rails generate rails_event_store_active_record:v1_v2_migration
|
25
|
+
|
26
|
+
MSG
|
27
|
+
end
|
28
|
+
|
29
|
+
def append_to_stream(events, stream, expected_version)
|
30
|
+
validate_unsupported_expected_version(expected_version)
|
31
|
+
validate_stream_is_empty(stream) if expected_version.none?
|
32
|
+
validate_expected_version_number(expected_version, stream) if Integer === expected_version.version
|
33
|
+
|
34
|
+
normalize_to_array(events).each do |event|
|
35
|
+
data = event.to_h
|
36
|
+
data[:stream] = stream.name
|
37
|
+
LegacyEvent.create!(data)
|
38
|
+
end
|
39
|
+
self
|
40
|
+
rescue ActiveRecord::RecordNotUnique
|
41
|
+
raise RubyEventStore::EventDuplicatedInStream
|
42
|
+
end
|
43
|
+
|
44
|
+
def link_to_stream(_event_ids, _stream, _expected_version)
|
45
|
+
raise RubyEventStore::NotSupported
|
46
|
+
end
|
47
|
+
|
48
|
+
def delete_stream(stream)
|
49
|
+
LegacyEvent.where({stream: stream.name}).update_all(stream: SERIALIZED_GLOBAL_STREAM_NAME)
|
50
|
+
end
|
51
|
+
|
52
|
+
def has_event?(event_id)
|
53
|
+
LegacyEvent.exists?(event_id: event_id)
|
54
|
+
end
|
55
|
+
|
56
|
+
def last_stream_event(stream)
|
57
|
+
build_event_entity(LegacyEvent.where(stream: stream.name).last)
|
58
|
+
end
|
59
|
+
|
60
|
+
def read_event(event_id)
|
61
|
+
build_event_entity(LegacyEvent.find_by(event_id: event_id)) or raise RubyEventStore::EventNotFound.new(event_id)
|
62
|
+
end
|
63
|
+
|
64
|
+
def read(spec)
|
65
|
+
stream = LegacyEvent.order(id: order(spec.direction))
|
66
|
+
stream = stream.limit(spec.count) if spec.limit?
|
67
|
+
stream = stream.where(start_condition(spec)) unless spec.head?
|
68
|
+
stream = stream.where(stream: spec.stream_name) unless spec.global_stream?
|
69
|
+
|
70
|
+
stream.map(&method(:build_event_entity)).each
|
71
|
+
end
|
72
|
+
|
73
|
+
private
|
74
|
+
|
75
|
+
def start_condition(specification)
|
76
|
+
event_record =
|
77
|
+
LegacyEvent.find_by!(event_id: specification.start)
|
78
|
+
case specification.direction
|
79
|
+
when :forward
|
80
|
+
['id > ?', event_record]
|
81
|
+
else
|
82
|
+
['id < ?', event_record]
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
def order(direction)
|
87
|
+
{forward: 'ASC', backward: 'DESC'}.fetch(direction)
|
88
|
+
end
|
89
|
+
|
90
|
+
|
91
|
+
def normalize_to_array(events)
|
92
|
+
return events if events.is_a?(Enumerable)
|
93
|
+
[events]
|
94
|
+
end
|
95
|
+
|
96
|
+
def build_event_entity(record)
|
97
|
+
return nil unless record
|
98
|
+
RubyEventStore::SerializedRecord.new(
|
99
|
+
event_id: record.event_id,
|
100
|
+
metadata: record.metadata,
|
101
|
+
data: record.data,
|
102
|
+
event_type: record.event_type,
|
103
|
+
)
|
104
|
+
end
|
105
|
+
|
106
|
+
def last_stream_version(stream)
|
107
|
+
LegacyEvent.where(stream: stream.name).count - 1
|
108
|
+
end
|
109
|
+
|
110
|
+
def stream_non_empty?(stream)
|
111
|
+
LegacyEvent.where(stream: stream.name).exists?
|
112
|
+
end
|
113
|
+
|
114
|
+
def validate_stream_is_empty(stream)
|
115
|
+
raise RubyEventStore::WrongExpectedEventVersion if stream_non_empty?(stream)
|
116
|
+
end
|
117
|
+
|
118
|
+
def validate_expected_version_number(expected_version, stream)
|
119
|
+
raise RubyEventStore::WrongExpectedEventVersion unless last_stream_version(stream).equal?(expected_version.version)
|
120
|
+
end
|
121
|
+
|
122
|
+
def validate_unsupported_expected_version(expected_version)
|
123
|
+
raise RubyEventStore::InvalidExpectedVersion, ":auto mode is not supported by LegacyEventRepository" if expected_version.auto?
|
124
|
+
end
|
125
|
+
end
|
126
|
+
end
|
127
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
|
2
|
+
lib = File.expand_path("../lib", __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require "rails_event_store_active_record/legacy/version"
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "rails_event_store_active_record-legacy"
|
8
|
+
spec.version = RailsEventStoreActiveRecord::Legacy::VERSION
|
9
|
+
spec.licenses = ['MIT']
|
10
|
+
spec.authors = ['Arkency']
|
11
|
+
spec.email = ['dev@arkency.com']
|
12
|
+
|
13
|
+
spec.summary = %q{Active Record events repository for Rails Event Store}
|
14
|
+
spec.description = %q{Implementation of events repository based on Rails Active Record for Rails Event Store. Exists for limited backwards-compatibilty and should not be chosen for new projects.}
|
15
|
+
|
16
|
+
spec.homepage = 'https://railseventstore.org'
|
17
|
+
spec.metadata = {
|
18
|
+
"homepage_uri" => "https://railseventstore.org/",
|
19
|
+
"changelog_uri" => "https://github.com/RailsEventStore/rails_event_store/releases",
|
20
|
+
"source_code_uri" => "https://github.com/RailsEventStore/rails_event_store",
|
21
|
+
"bug_tracker_uri" => "https://github.com/RailsEventStore/rails_event_store/issues",
|
22
|
+
}
|
23
|
+
|
24
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
25
|
+
f.match(%r{^(test|spec|features)/})
|
26
|
+
end
|
27
|
+
spec.bindir = "exe"
|
28
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
29
|
+
spec.require_paths = ["lib"]
|
30
|
+
|
31
|
+
spec.add_development_dependency 'bundler', '~> 1.15'
|
32
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
33
|
+
spec.add_development_dependency 'rspec', '~> 3.6'
|
34
|
+
spec.add_development_dependency 'rails', '~> 5.2'
|
35
|
+
spec.add_development_dependency 'sqlite3', '1.3.13'
|
36
|
+
spec.add_development_dependency 'pg', '0.21'
|
37
|
+
spec.add_development_dependency 'mysql2', '0.4.10'
|
38
|
+
spec.add_development_dependency 'mutant-rspec', '~> 0.8.14'
|
39
|
+
|
40
|
+
spec.add_dependency 'ruby_event_store', '= 0.28.0'
|
41
|
+
spec.add_dependency 'activesupport', '>= 3.0'
|
42
|
+
spec.add_dependency 'activemodel', '>= 3.0'
|
43
|
+
end
|
metadata
ADDED
@@ -0,0 +1,211 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rails_event_store_active_record-legacy
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.28.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Arkency
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2018-05-01 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.15'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.15'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.6'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.6'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rails
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '5.2'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '5.2'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: sqlite3
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - '='
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: 1.3.13
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - '='
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: 1.3.13
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: pg
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - '='
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0.21'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - '='
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0.21'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: mysql2
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - '='
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: 0.4.10
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - '='
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: 0.4.10
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: mutant-rspec
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - "~>"
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: 0.8.14
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - "~>"
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: 0.8.14
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: ruby_event_store
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - '='
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: 0.28.0
|
132
|
+
type: :runtime
|
133
|
+
prerelease: false
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - '='
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: 0.28.0
|
139
|
+
- !ruby/object:Gem::Dependency
|
140
|
+
name: activesupport
|
141
|
+
requirement: !ruby/object:Gem::Requirement
|
142
|
+
requirements:
|
143
|
+
- - ">="
|
144
|
+
- !ruby/object:Gem::Version
|
145
|
+
version: '3.0'
|
146
|
+
type: :runtime
|
147
|
+
prerelease: false
|
148
|
+
version_requirements: !ruby/object:Gem::Requirement
|
149
|
+
requirements:
|
150
|
+
- - ">="
|
151
|
+
- !ruby/object:Gem::Version
|
152
|
+
version: '3.0'
|
153
|
+
- !ruby/object:Gem::Dependency
|
154
|
+
name: activemodel
|
155
|
+
requirement: !ruby/object:Gem::Requirement
|
156
|
+
requirements:
|
157
|
+
- - ">="
|
158
|
+
- !ruby/object:Gem::Version
|
159
|
+
version: '3.0'
|
160
|
+
type: :runtime
|
161
|
+
prerelease: false
|
162
|
+
version_requirements: !ruby/object:Gem::Requirement
|
163
|
+
requirements:
|
164
|
+
- - ">="
|
165
|
+
- !ruby/object:Gem::Version
|
166
|
+
version: '3.0'
|
167
|
+
description: Implementation of events repository based on Rails Active Record for
|
168
|
+
Rails Event Store. Exists for limited backwards-compatibilty and should not be chosen
|
169
|
+
for new projects.
|
170
|
+
email:
|
171
|
+
- dev@arkency.com
|
172
|
+
executables: []
|
173
|
+
extensions: []
|
174
|
+
extra_rdoc_files: []
|
175
|
+
files:
|
176
|
+
- Gemfile
|
177
|
+
- Makefile
|
178
|
+
- README.md
|
179
|
+
- lib/rails_event_store_active_record/legacy.rb
|
180
|
+
- lib/rails_event_store_active_record/legacy/event_repository.rb
|
181
|
+
- lib/rails_event_store_active_record/legacy/version.rb
|
182
|
+
- rails_event_store_active_record-legacy.gemspec
|
183
|
+
homepage: https://railseventstore.org
|
184
|
+
licenses:
|
185
|
+
- MIT
|
186
|
+
metadata:
|
187
|
+
homepage_uri: https://railseventstore.org/
|
188
|
+
changelog_uri: https://github.com/RailsEventStore/rails_event_store/releases
|
189
|
+
source_code_uri: https://github.com/RailsEventStore/rails_event_store
|
190
|
+
bug_tracker_uri: https://github.com/RailsEventStore/rails_event_store/issues
|
191
|
+
post_install_message:
|
192
|
+
rdoc_options: []
|
193
|
+
require_paths:
|
194
|
+
- lib
|
195
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
196
|
+
requirements:
|
197
|
+
- - ">="
|
198
|
+
- !ruby/object:Gem::Version
|
199
|
+
version: '0'
|
200
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
201
|
+
requirements:
|
202
|
+
- - ">="
|
203
|
+
- !ruby/object:Gem::Version
|
204
|
+
version: '0'
|
205
|
+
requirements: []
|
206
|
+
rubyforge_project:
|
207
|
+
rubygems_version: 2.7.6
|
208
|
+
signing_key:
|
209
|
+
specification_version: 4
|
210
|
+
summary: Active Record events repository for Rails Event Store
|
211
|
+
test_files: []
|