evt-entity_snapshot-postgres 0.1.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 +7 -0
- data/lib/entity_snapshot/loader.rb +1 -0
- data/lib/entity_snapshot/postgres.rb +6 -0
- data/lib/entity_snapshot/postgres/controls.rb +12 -0
- data/lib/entity_snapshot/postgres/controls/batch.rb +20 -0
- data/lib/entity_snapshot/postgres/controls/entity.rb +35 -0
- data/lib/entity_snapshot/postgres/controls/entity_store.rb +15 -0
- data/lib/entity_snapshot/postgres/controls/id.rb +7 -0
- data/lib/entity_snapshot/postgres/controls/message.rb +26 -0
- data/lib/entity_snapshot/postgres/controls/snapshot.rb +15 -0
- data/lib/entity_snapshot/postgres/controls/stream_name.rb +7 -0
- data/lib/entity_snapshot/postgres/controls/time.rb +7 -0
- data/lib/entity_snapshot/postgres/controls/version.rb +7 -0
- data/lib/entity_snapshot/postgres/controls/write.rb +19 -0
- data/lib/entity_snapshot/postgres/log.rb +11 -0
- data/lib/entity_snapshot/postgres/postgres.rb +75 -0
- data/lib/entity_snapshot/postgres/recorded.rb +18 -0
- metadata +101 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: a29e06c3e4f248102951d8c68e9f79c8b6103fda
|
4
|
+
data.tar.gz: bfad08c308f3a2284da4ebf4d9dbf3ca2d2f9c31
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: e824120358f0fca89c82e1c59f47ba27a802b758d00396e4e97713204c8665e6b0fac0f4d623f2371a07187149e94ff1fea0eff9c7e6710725ff53d0407c3941
|
7
|
+
data.tar.gz: 1d037ea9bec3b4433361c40bea969ce243dffc552dacc056d924fc9547bd02ab46a48b71e045fdb5abd30d165332480dcdc5dd46328f6aef21b13b117c19cb43
|
@@ -0,0 +1 @@
|
|
1
|
+
postgres.rb
|
@@ -0,0 +1,12 @@
|
|
1
|
+
require 'entity_store/controls'
|
2
|
+
|
3
|
+
require 'entity_snapshot/postgres/controls/time'
|
4
|
+
require 'entity_snapshot/postgres/controls/id'
|
5
|
+
require 'entity_snapshot/postgres/controls/stream_name'
|
6
|
+
require 'entity_snapshot/postgres/controls/version'
|
7
|
+
require 'entity_snapshot/postgres/controls/message'
|
8
|
+
require 'entity_snapshot/postgres/controls/batch'
|
9
|
+
require 'entity_snapshot/postgres/controls/entity'
|
10
|
+
require 'entity_snapshot/postgres/controls/snapshot'
|
11
|
+
require 'entity_snapshot/postgres/controls/write'
|
12
|
+
require 'entity_snapshot/postgres/controls/entity_store'
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module EntitySnapshot
|
2
|
+
class Postgres
|
3
|
+
module Controls
|
4
|
+
module Batch
|
5
|
+
def self.example(count: nil, starting_number: nil)
|
6
|
+
count ||= 2
|
7
|
+
starting_number ||= 1
|
8
|
+
|
9
|
+
batch = []
|
10
|
+
count.times do |i|
|
11
|
+
number = ('1' * (i + starting_number)).to_i
|
12
|
+
batch << Controls::Message.example(number: number)
|
13
|
+
end
|
14
|
+
|
15
|
+
batch
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
module EntitySnapshot
|
2
|
+
class Postgres
|
3
|
+
module Controls
|
4
|
+
module Entity
|
5
|
+
def self.example
|
6
|
+
Example.build(Data.example)
|
7
|
+
end
|
8
|
+
|
9
|
+
class Example
|
10
|
+
include Schema::DataStructure
|
11
|
+
|
12
|
+
attribute :some_attribute
|
13
|
+
|
14
|
+
module Transformer
|
15
|
+
def self.raw_data(instance)
|
16
|
+
instance.to_h
|
17
|
+
end
|
18
|
+
|
19
|
+
def self.instance(raw_data)
|
20
|
+
Example.build(raw_data)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
module Data
|
26
|
+
def self.example
|
27
|
+
{
|
28
|
+
some_attribute: EventSource::Controls::RandomValue.example
|
29
|
+
}
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module EntitySnapshot
|
2
|
+
class Postgres
|
3
|
+
module Controls
|
4
|
+
module EntityStore
|
5
|
+
def self.example(category: nil, entity_class: nil, projection_class: nil, snapshot_interval: nil)
|
6
|
+
reader_class = EventSource::Postgres::Read
|
7
|
+
snapshot_class = EntitySnapshot::Postgres
|
8
|
+
snapshot_interval ||= 2
|
9
|
+
category ||= 'example'
|
10
|
+
::EntityStore::Controls::EntityStore.example(category: category, entity_class: entity_class, projection_class: projection_class, reader_class: reader_class, snapshot_class: snapshot_class, snapshot_interval: snapshot_interval)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
module EntitySnapshot
|
2
|
+
class Postgres
|
3
|
+
module Controls
|
4
|
+
module Message
|
5
|
+
def self.example(number: nil)
|
6
|
+
number ||= 1
|
7
|
+
Example.build number: number
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.first
|
11
|
+
Example.build :number => 1
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.second
|
15
|
+
Example.build :number => 11
|
16
|
+
end
|
17
|
+
|
18
|
+
class Example
|
19
|
+
include Messaging::Message
|
20
|
+
|
21
|
+
attribute :number
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module EntitySnapshot
|
2
|
+
class Postgres
|
3
|
+
module Controls
|
4
|
+
module Write
|
5
|
+
def self.batch(stream_name: nil, category: nil, count: nil, starting_number: nil)
|
6
|
+
stream_name ||= Controls::StreamName.example(category: category)
|
7
|
+
|
8
|
+
write = ::Messaging::Postgres::Write.build
|
9
|
+
|
10
|
+
batch = Batch.example(count: count, starting_number: starting_number)
|
11
|
+
|
12
|
+
write.(batch, stream_name)
|
13
|
+
|
14
|
+
stream_name
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,75 @@
|
|
1
|
+
module EntitySnapshot
|
2
|
+
class Postgres
|
3
|
+
include Log::Dependency
|
4
|
+
include EntityCache::Storage::Persistent
|
5
|
+
|
6
|
+
dependency :write, EventSource::Postgres::Put
|
7
|
+
dependency :read, EventSource::Postgres::Get::Last
|
8
|
+
|
9
|
+
attr_accessor :session
|
10
|
+
|
11
|
+
alias_method :entity_class, :subject
|
12
|
+
|
13
|
+
def snapshot_stream_name(id)
|
14
|
+
entity_class_name = entity_class.name.split('::').last
|
15
|
+
entity_cateogry = Casing::Camel.(entity_class_name)
|
16
|
+
|
17
|
+
Messaging::StreamName.stream_name(id, entity_cateogry, type: 'snapshot')
|
18
|
+
end
|
19
|
+
|
20
|
+
def configure(session: nil)
|
21
|
+
EventSource::Postgres::Session.configure(self, session: session)
|
22
|
+
EventSource::Postgres::Put.configure(self, session: self.session, attr_name: :write)
|
23
|
+
EventSource::Postgres::Get::Last.configure(self, session: self.session, attr_name: :read)
|
24
|
+
end
|
25
|
+
|
26
|
+
def put(id, entity, version, time)
|
27
|
+
unless entity.is_a? subject
|
28
|
+
raise Error, "Persistent storage for #{subject} cannot store #{entity}"
|
29
|
+
end
|
30
|
+
|
31
|
+
stream_name = snapshot_stream_name(id)
|
32
|
+
|
33
|
+
logger.trace "Writing snapshot (Stream: #{stream_name.inspect}, Entity Class: #{entity.class.name}, Version: #{version.inspect}, Time: #{time})"
|
34
|
+
|
35
|
+
entity_data = Transform::Write.raw_data(entity)
|
36
|
+
|
37
|
+
event_data = EventSource::EventData::Write.new
|
38
|
+
|
39
|
+
data = {
|
40
|
+
entity_data: entity_data,
|
41
|
+
entity_version: version
|
42
|
+
}
|
43
|
+
|
44
|
+
event_data.type = 'Recorded'
|
45
|
+
event_data.data = data
|
46
|
+
|
47
|
+
position = write.(event_data, stream_name)
|
48
|
+
|
49
|
+
logger.debug "Wrote snapshot (Stream: #{stream_name.inspect}, Entity Class: #{entity.class.name}, Version: #{version.inspect}, Time: #{time})"
|
50
|
+
|
51
|
+
position
|
52
|
+
end
|
53
|
+
|
54
|
+
def get(id)
|
55
|
+
stream_name = snapshot_stream_name(id)
|
56
|
+
|
57
|
+
logger.trace "Reading snapshot (Stream: #{stream_name.inspect}, Entity Class: #{entity_class.name})"
|
58
|
+
|
59
|
+
event_data = read.(stream_name)
|
60
|
+
|
61
|
+
if event_data.nil?
|
62
|
+
logger.debug "No snapshot could not be read (Stream: #{stream_name.inspect}, Entity Class: #{entity_class.name})"
|
63
|
+
return
|
64
|
+
end
|
65
|
+
|
66
|
+
entity = entity_class.build(event_data.data[:entity_data])
|
67
|
+
version = event_data.data[:entity_version]
|
68
|
+
time = event_data.time
|
69
|
+
|
70
|
+
logger.debug "Read snapshot (Stream: #{stream_name.inspect}, Entity Class: #{entity_class.name}, Version: #{version.inspect}, Time: #{time})"
|
71
|
+
|
72
|
+
return entity, version, time
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module EntitySnapshot
|
2
|
+
class Recorded
|
3
|
+
include Messaging::Message
|
4
|
+
|
5
|
+
attribute :entity_data
|
6
|
+
attribute :entity_version
|
7
|
+
|
8
|
+
module Serializer
|
9
|
+
def self.raw_data(instance)
|
10
|
+
instance.to_h
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.instance(raw_data)
|
14
|
+
Message.build raw_data
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
metadata
ADDED
@@ -0,0 +1,101 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: evt-entity_snapshot-postgres
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- The Eventide Project
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-01-31 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: evt-entity_store
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: evt-messaging-postgres
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: test_bench
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
description: " "
|
56
|
+
email: opensource@eventide-project.org
|
57
|
+
executables: []
|
58
|
+
extensions: []
|
59
|
+
extra_rdoc_files: []
|
60
|
+
files:
|
61
|
+
- lib/entity_snapshot/loader.rb
|
62
|
+
- lib/entity_snapshot/postgres.rb
|
63
|
+
- lib/entity_snapshot/postgres/controls.rb
|
64
|
+
- lib/entity_snapshot/postgres/controls/batch.rb
|
65
|
+
- lib/entity_snapshot/postgres/controls/entity.rb
|
66
|
+
- lib/entity_snapshot/postgres/controls/entity_store.rb
|
67
|
+
- lib/entity_snapshot/postgres/controls/id.rb
|
68
|
+
- lib/entity_snapshot/postgres/controls/message.rb
|
69
|
+
- lib/entity_snapshot/postgres/controls/snapshot.rb
|
70
|
+
- lib/entity_snapshot/postgres/controls/stream_name.rb
|
71
|
+
- lib/entity_snapshot/postgres/controls/time.rb
|
72
|
+
- lib/entity_snapshot/postgres/controls/version.rb
|
73
|
+
- lib/entity_snapshot/postgres/controls/write.rb
|
74
|
+
- lib/entity_snapshot/postgres/log.rb
|
75
|
+
- lib/entity_snapshot/postgres/postgres.rb
|
76
|
+
- lib/entity_snapshot/postgres/recorded.rb
|
77
|
+
homepage: https://github.com/eventide-project/entity-snapshot-postgres
|
78
|
+
licenses:
|
79
|
+
- MIT
|
80
|
+
metadata: {}
|
81
|
+
post_install_message:
|
82
|
+
rdoc_options: []
|
83
|
+
require_paths:
|
84
|
+
- lib
|
85
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: 2.3.3
|
90
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
91
|
+
requirements:
|
92
|
+
- - ">="
|
93
|
+
- !ruby/object:Gem::Version
|
94
|
+
version: '0'
|
95
|
+
requirements: []
|
96
|
+
rubyforge_project:
|
97
|
+
rubygems_version: 2.5.2
|
98
|
+
signing_key:
|
99
|
+
specification_version: 4
|
100
|
+
summary: Projected entity snapshotting for Postgres
|
101
|
+
test_files: []
|