nexia_event_store 0.7.5 → 0.8.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 47f3dda99420a603ac4a0289321ac8b7697068c5
4
- data.tar.gz: ea93e049eaa9bf2bad597e0ba032bcbd5a51f077
3
+ metadata.gz: 0482c47fcd18e73eb1faaddc9762fc4d7315c023
4
+ data.tar.gz: 2300cc30c2e1c37bdfc4b9fe98cc96f015914655
5
5
  SHA512:
6
- metadata.gz: 0a453586af4426200b85a14b9b35c9f4d612b99d8db0cecc0203438591e02b9a22824b3b2d812c78b6f5a8c99b6e540e5c40df1a0d9cde357cbb3ee7e8d55511
7
- data.tar.gz: f049dd32391ab38e6b45a055298214b60d03b4e197c653b999b7b343867fdf61f82f50e01580ce2403c90fef286932b1866a03f2857a57a122c73317adb6ab70
6
+ metadata.gz: 77cb1a1695d9f3d1e61ef508fba5ca4c435a9194a538595a4fc995c35a8593ac634d56efb2bad6c673658448a4aac9a1c65eb4d9036100a209a9b2a711b75505
7
+ data.tar.gz: 14b00a3904376be51d2d7a8702c9a84ca7ea07d9360d9a7b130547475dc7e3514966ba946fd803b9dcaa749be633ece6eee7a0475b9bfb4e059eaa12939cb891
data/lib/event_store.rb CHANGED
@@ -60,6 +60,21 @@ module EventStore
60
60
  @schema ||= raw_db_config[@environment][@adapter]['schema']
61
61
  end
62
62
 
63
+ def self.insert_table_name(date)
64
+ return fully_qualified_table unless partitioning?
65
+
66
+ partition_name = date.strftime("#{table_name}#{partition_name_suffix}")
67
+ qualified_table_name(partition_name)
68
+ end
69
+
70
+ def self.partitioning?
71
+ @db_config["partitioning"]
72
+ end
73
+
74
+ def self.partition_name_suffix
75
+ @db_config["partition_name_suffix"]
76
+ end
77
+
63
78
  def self.table_name
64
79
  @table_name ||= raw_db_config['table_name']
65
80
  end
@@ -69,7 +84,11 @@ module EventStore
69
84
  end
70
85
 
71
86
  def self.fully_qualified_table
72
- @fully_qualified_table ||= Sequel.lit "#{schema}.#{table_name}"
87
+ @fully_qualified_table ||= qualified_table_name
88
+ end
89
+
90
+ def self.qualified_table_name(name = table_name)
91
+ Sequel.lit "#{schema}.#{name}"
73
92
  end
74
93
 
75
94
  def self.fully_qualified_names_table
@@ -21,9 +21,9 @@ module EventStore
21
21
  event
22
22
  end
23
23
 
24
- event_table = EventStore.db.from(@event_table)
25
24
  prepared_events.each do |event|
26
25
  event_hash = event.dup.reject! { |k,v| k == :fully_qualified_name }
26
+ event_table = insert_table(event_hash[:occurred_at])
27
27
 
28
28
  begin
29
29
  id = event_table.insert(event_hash)
@@ -40,6 +40,14 @@ module EventStore
40
40
  yield(prepared_events) if block_given?
41
41
  end
42
42
 
43
+ def insert_table(occurred_at)
44
+ EventStore.db.from(insert_table_name(occurred_at))
45
+ end
46
+
47
+ def insert_table_name(date)
48
+ EventStore.insert_table_name(date)
49
+ end
50
+
43
51
  def fully_qualified_names
44
52
  @fully_qualified_name_query ||= EventStore.db.from(@names_table)
45
53
  end
@@ -1,3 +1,3 @@
1
1
  module EventStore
2
- VERSION = '0.7.5'
2
+ VERSION = '0.8.0'
3
3
  end
@@ -267,21 +267,21 @@ describe EventStore::Client do
267
267
  client.append([old_event])
268
268
  end
269
269
 
270
- it "should append a single event of a new type without raising an error" do
270
+ it "appends a single event of a new type without raising an error" do
271
271
  initial_count = client.count
272
272
  events = [new_event]
273
273
  client.append(events)
274
274
  expect(client.count).to eq(initial_count + events.length)
275
275
  end
276
276
 
277
- it "should append multiple events of a new type without raising and error" do
277
+ it "appends multiple events of a new type without raising and error" do
278
278
  initial_count = client.count
279
279
  events = [new_event, new_event]
280
280
  client.append(events)
281
281
  expect(client.count).to eq(initial_count + events.length)
282
282
  end
283
283
 
284
- it "should change the event id number" do
284
+ it "changes the event id number" do
285
285
  events = [new_event, really_new_event]
286
286
  expect{ client.append(events) }.to change(client, :event_id)
287
287
  end
@@ -293,7 +293,7 @@ describe EventStore::Client do
293
293
  expect(client.snapshot.event_id).to eq(client.raw_event_stream.last[:id])
294
294
  end
295
295
 
296
- it "should write-through-cache the event in a snapshot without duplicating events" do
296
+ it "writes through cache the event in a snapshot without duplicating events" do
297
297
  client.destroy!
298
298
  client.append([old_event, new_event, new_event])
299
299
  expected = []
@@ -302,7 +302,7 @@ describe EventStore::Client do
302
302
  expect(client.snapshot.to_a).to eq(expected)
303
303
  end
304
304
 
305
- it "should raise a meaningful exception when a nil event given to it to append" do
305
+ it "raises a meaningful exception when a nil event given to it to append" do
306
306
  expect {client.append([nil])}.to raise_exception(ArgumentError)
307
307
  end
308
308
  end
@@ -312,12 +312,12 @@ describe EventStore::Client do
312
312
  client.append([old_event])
313
313
  end
314
314
 
315
- it "should not raise an error when two events of the same type are appended" do
315
+ it "does not raise an error when two events of the same type are appended" do
316
316
  client.append([duplicate_event])
317
317
  client.append([duplicate_event]) #will fail automatically if it throws an error, no need for assertions (which now print warning for some reason)
318
318
  end
319
319
 
320
- it "should write-through-cache the event in a snapshot without duplicating events" do
320
+ it "writes-through-cache the event in a snapshot without duplicating events" do
321
321
  client.destroy!
322
322
  client.append([old_event, new_event, new_event])
323
323
  expected = []
@@ -341,7 +341,7 @@ describe EventStore::Client do
341
341
  @bad_event.fully_qualified_name = nil
342
342
  end
343
343
 
344
- it "should revert all append events if one fails" do
344
+ it "reverts all append events if one fails" do
345
345
  starting_count = client.count
346
346
  expect { client.append([new_event, @bad_event]) }.to raise_error(EventStore::AttributeMissingError)
347
347
  expect(client.count).to eq(starting_count)
@@ -353,13 +353,13 @@ describe EventStore::Client do
353
353
  expect(x).to eq(0)
354
354
  end
355
355
 
356
- it "yield to the block after event creation" do
356
+ it "yields to the block after event creation" do
357
357
  x = 0
358
358
  client.append([]) { x += 1 }
359
359
  expect(x).to eq(1)
360
360
  end
361
361
 
362
- it "should pass the raw event_data to the block" do
362
+ it "passes the raw event_data to the block" do
363
363
  client.append([new_event]) do |raw_event_data|
364
364
  expect(raw_event_data).to eq([new_event])
365
365
  end
@@ -0,0 +1,27 @@
1
+ require "spec_helper"
2
+
3
+ describe EventStore do
4
+ describe ".insert_table_name" do
5
+ let(:date) { Date.parse("1955-01-31") }
6
+
7
+ context "without partitioning defined" do
8
+ let(:expected) { "es_test.test_events" }
9
+
10
+ it "returns a properly formatted default table name" do
11
+ expect(subject.insert_table_name(date)).to eq(expected)
12
+ end
13
+ end
14
+
15
+ context "with partitioning defined" do
16
+ let(:expected) { "es_test.test_events_1955_01_31" }
17
+ let(:partition_config) { { "schema" => "es_test", "partition_name_suffix" => "_%Y_%m_%d", "partitioning" => true } }
18
+
19
+ before { subject.custom_config(partition_config, subject.local_redis_config, "test_events", "test") }
20
+ after { subject.custom_config(subject.raw_db_config["test"]["postgres"], subject.local_redis_config, "test_events", "test") }
21
+
22
+ it "returns a properly formatted table name" do
23
+ expect(subject.insert_table_name(date)).to eq(expected)
24
+ end
25
+ end
26
+ end
27
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nexia_event_store
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.5
4
+ version: 0.8.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Paul Saieg, John Colvin
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2015-07-01 00:00:00.000000000 Z
12
+ date: 2015-07-16 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler
@@ -207,6 +207,7 @@ files:
207
207
  - spec/event_store/binary_string_term_with_null_byte.txt
208
208
  - spec/event_store/client_spec.rb
209
209
  - spec/event_store/config_spec.rb
210
+ - spec/event_store/event_store_spec.rb
210
211
  - spec/event_store/serialized_binary_event_data.txt
211
212
  - spec/event_store/snapshot_spec.rb
212
213
  - spec/event_store/vertica guy notes.txt
@@ -244,6 +245,7 @@ test_files:
244
245
  - spec/event_store/binary_string_term_with_null_byte.txt
245
246
  - spec/event_store/client_spec.rb
246
247
  - spec/event_store/config_spec.rb
248
+ - spec/event_store/event_store_spec.rb
247
249
  - spec/event_store/serialized_binary_event_data.txt
248
250
  - spec/event_store/snapshot_spec.rb
249
251
  - spec/event_store/vertica guy notes.txt