entity_store_sequel 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: bc61c6ab95a1c52b5cee2cbcf9db6b18bec36fd1
4
- data.tar.gz: 77b5ed2a8b7ee5a37acd8be2f0ba4ba09d55188f
3
+ metadata.gz: 0feccb2b1600da42b28dc1af3ce9b12ab524f5d1
4
+ data.tar.gz: 0abc11734ddac5a20f95fae45aa149b4b99e6f56
5
5
  SHA512:
6
- metadata.gz: 9a715e231138d555f13304e8e74bdde4ea38ca8dedf593da9b6c68ca8821dd4d6ac652c20c07b50782789759b1c8053c5924ded288563352b6cc18fd2fa3a7ad
7
- data.tar.gz: 448b10ffd4cc9cf25e1020961cde77a8a4826530b6836b841e8b29040d7bc153c16c8904dc9f49d35acf7922aace8023f7c4cb55ff896aedc3030693a4b9590c
6
+ metadata.gz: e02bb1ea78b18e8179e0462421b829970b3f3456c76cef9bfeee6197d1e6c764cd07ac40fc196dcfe891827363c0e24f2fbef012a3e8365abeac2bc000be57c4
7
+ data.tar.gz: 371f759a2eded9956d604abbc7bf1baf8358a2b05829e844cbc46d86ed778d25ab9fbc5432f7b7f471492c358e4f27270706019099ca1f6b785dfb39a8e1e47a
@@ -10,6 +10,7 @@ module EntityStoreSequel
10
10
 
11
11
  Sequel.extension :pg_array_ops
12
12
  Sequel.extension :pg_json_ops
13
+ Sequel.extension :migration
13
14
 
14
15
  class << self
15
16
  attr_accessor :connection_string
@@ -18,7 +19,11 @@ module EntityStoreSequel
18
19
  def database
19
20
  return @_database if @_database
20
21
 
21
- @_database ||= Sequel.connect(connection_string)
22
+ self.database = Sequel.connect(connection_string)
23
+ end
24
+
25
+ def database=(db)
26
+ @_database = db
22
27
  @_database.extension :pg_array
23
28
  @_database.extension :pg_json
24
29
 
@@ -26,25 +31,8 @@ module EntityStoreSequel
26
31
  end
27
32
 
28
33
  def init
29
- unless database.table_exists?(:entities)
30
- database.create_table :entities do
31
- column :id, :char, primary_key: true, size: 24
32
- String :_type
33
- integer :snapshot_key
34
- integer :version
35
- column :snapshot, :jsonb
36
- end
37
- end
38
-
39
- unless database.table_exists?(:entity_events)
40
- database.create_table :entity_events do
41
- column :id, :char, primary_key: true, size: 24
42
- String :_type
43
- column :_entity_id, :char, size: 24
44
- integer :entity_version
45
- column :data, :jsonb
46
- end
47
- end
34
+ migration_path = File.expand_path("../../sequel/migrations", __FILE__)
35
+ Sequel::Migrator.run(self.database, migration_path, :table=>:entity_store_schema_migration)
48
36
  end
49
37
  end
50
38
 
@@ -1,3 +1,3 @@
1
1
  module EntityStoreSequel
2
- VERSION = "0.0.2".freeze
2
+ VERSION = "0.0.3".freeze
3
3
  end
@@ -0,0 +1,24 @@
1
+ Sequel.migration do
2
+ up do
3
+ create_table? :entities do
4
+ column :id, :char, primary_key: true, size: 24
5
+ String :_type
6
+ integer :snapshot_key
7
+ integer :version
8
+ column :snapshot, :jsonb
9
+ end
10
+
11
+ create_table? :entity_events do
12
+ column :id, :char, primary_key: true, size: 24
13
+ String :_type
14
+ column :_entity_id, :char, size: 24
15
+ integer :entity_version
16
+ column :data, :jsonb
17
+ end
18
+ end
19
+
20
+ down do
21
+ drop_table(:entities)
22
+ drop_table(:entity_events)
23
+ end
24
+ end
@@ -57,3 +57,31 @@ describe "end to end" do
57
57
  end
58
58
  end
59
59
  end
60
+
61
+ describe "setting connection from existing" do
62
+ before(:each) do
63
+ PostgresEntityStore.database = Sequel.connect('postgres://localhost/cronofy_test')
64
+ PostgresEntityStore.init
65
+
66
+ EntityStore::Config.setup do |config|
67
+ config.store = PostgresEntityStore.new
68
+ config.event_subscribers << DummyEntitySubscriber
69
+ end
70
+ end
71
+
72
+ context "when save entity" do
73
+ let(:name) { random_string }
74
+ before(:each) do
75
+ @entity = DummyEntity.new
76
+ @entity.set_name name
77
+ @id = Store.new.save @entity
78
+ end
79
+
80
+ it "publishes event to the subscriber" do
81
+ DummyEntitySubscriber.event_name.should eq(name)
82
+ end
83
+ it "is retrievable with the events applied" do
84
+ EntityStore::Store.new.get(@entity.id).name.should eq(name)
85
+ end
86
+ end
87
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: entity_store_sequel
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Stephen Binns
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-08-11 00:00:00.000000000 Z
11
+ date: 2016-08-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: sequel
@@ -118,6 +118,7 @@ files:
118
118
  - lib/entity_store_sequel/postgres_entity_store.rb
119
119
  - lib/entity_store_sequel/version.rb
120
120
  - lib/sequel/core_ext.rb
121
+ - lib/sequel/migrations/201608121657_create_entities_and_events.rb
121
122
  - lib/tasks/entity_store.rake
122
123
  - spec/entity_store_sequel/postgres_entity_store_spec.rb
123
124
  - spec/entity_store_spec.rb