sequel-schema-sharding 0.4.1 → 0.5.0

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: f7c70c9f4005f27bb6c64ab8f666d8d6238aee84
4
- data.tar.gz: 9c867fc8fdf0e585579c184aeb6c77ce85b90b07
3
+ metadata.gz: d2dce85ba1914970e81126721a1bfd51d6b9208d
4
+ data.tar.gz: 0376b7682b6ae4b35a91146bab97332eb208962e
5
5
  SHA512:
6
- metadata.gz: 257e3ea91ff1851bad52e02b57c546a9897ea7d8a6ba46d5d865a638aa796a26e90be4e207270dcac16291727218e85a27916ba24bc2b1b62d9e5ab9cad334b3
7
- data.tar.gz: 39efe5f19987104abac8f8688306c38821a0d751e2bc04df65b7f8f74f1db8971d74dcb882daf94f77f554c102be173852efa7d4a8c16c8f14f0a3facc9d3d03
6
+ metadata.gz: f799c6bd555910a534954d137aac874f94ba9b57315c988066b696a09c381b6b81db75cfb6965d040e9a2ad26ccdd04f0bb1b562a5acfe7245658a315b1d19b2
7
+ data.tar.gz: a7cf6e434056d0cd54d693f9ffb09668e3e5bddebbe42fce825f5c36830ce0323173fdf6c8b039da16703f31f1df19478be2aa696be567c18cd183f81b7919ca
data/README.md CHANGED
@@ -91,6 +91,44 @@ See Sequel documentation for more info:
91
91
 
92
92
  TODO: rake tasks for running migrations
93
93
 
94
+ ### Read/write splitting
95
+
96
+ Sequel supports read/write splitting, but sequel-schema-sharding needs a
97
+ few modifications in order to work with horizontal sharding. In order to
98
+ use read/write splitting across shards, the following configuration can
99
+ be used in your `sharding.yml`:
100
+
101
+ ```yml
102
+ <env>:
103
+ tables:
104
+ <table_name>:
105
+ schema_name: "schema_%04d"
106
+ logical_shards:
107
+ <shard_name>: <1..n>
108
+ <shard_name>:<n+1..m>
109
+ physical_shards:
110
+ <shard_name>:
111
+ host: <hostname>
112
+ database: <database>
113
+ replicas:
114
+ <replica_name>:
115
+ host: <hostname>
116
+ database: <database>
117
+ ...
118
+ common:
119
+ username: <pg_username>
120
+ password: <pg_password>
121
+ port: <pg_port>
122
+ ```
123
+
124
+ Replica configuration is merged into common attributes, so are redundant
125
+ if they are not different from the master. Replica attributes take priority,
126
+ however, so if you use a proxy such as PGBouncer, you can specify a different
127
+ local database name.
128
+
129
+ See http://sequel.rubyforge.org/rdoc/files/doc/sharding_rdoc.html for more
130
+ information.
131
+
94
132
  ### Models
95
133
 
96
134
  Models declare their table in the class definition. This allows Sequel
@@ -12,7 +12,15 @@ module Sequel
12
12
 
13
13
  def physical_shard_configs
14
14
  @physical_shard_configs ||= config['physical_shards'].inject({}) do |hash, value|
15
- hash[value[0]] = config['common'].merge(value[1])
15
+ shard_config = config['common'].merge(value[1])
16
+
17
+ if shard_config['replicas']
18
+ shard_config['replicas'] = shard_config['replicas'].map do |name, replica|
19
+ config['common'].merge(replica)
20
+ end
21
+ end
22
+
23
+ hash[value[0]] = shard_config
16
24
  hash
17
25
  end
18
26
  end
@@ -55,7 +55,7 @@ module Sequel
55
55
  return {} if config['replicas'].nil?
56
56
  {
57
57
  :servers => {
58
- :read_only => ->(db) { {:host => config['replicas'].sample} }
58
+ :read_only => ->(db) { config['replicas'].sample }
59
59
  }
60
60
  }
61
61
  end
@@ -1,5 +1,5 @@
1
1
  module Sequel
2
2
  module SchemaSharding
3
- VERSION = "0.4.1"
3
+ VERSION = "0.5.0"
4
4
  end
5
5
  end
@@ -20,7 +20,9 @@ test:
20
20
  host: 127.0.0.1
21
21
  database: sequel_test_shard2
22
22
  replicas:
23
- - 127.0.0.1
23
+ replica_1:
24
+ host: 127.0.0.1
25
+ database: sequel_test_shard2
24
26
  common:
25
27
  username: postgres
26
28
  password: boomboomkaboom
@@ -46,7 +48,9 @@ boom:
46
48
  host: 127.0.0.1
47
49
  database: sequel_boom_shard2
48
50
  replicas:
49
- - 127.0.0.1
51
+ replica_1:
52
+ host: 127.0.0.1
53
+ database: sequel_boom_shard2
50
54
  common:
51
55
  username: postgres
52
56
  password: boomboomkaboom
@@ -43,7 +43,11 @@ describe Sequel::SchemaSharding::Configuration do
43
43
  expect(value['username']).to eq('postgres')
44
44
  expect(value['password']).to eq('boomboomkaboom')
45
45
  expect(value['port']).to eq(5432)
46
- expect(value['replicas']).to eq(['127.0.0.1']) if key == 'shard2'
46
+ expect(value['replicas']).to eq([{'host' => '127.0.0.1',
47
+ 'database' => 'sequel_boom_shard2',
48
+ 'port' => 5432,
49
+ 'username' => 'postgres',
50
+ 'password' => 'boomboomkaboom'}]) if key == 'shard2'
47
51
 
48
52
  i += 1
49
53
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sequel-schema-sharding
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.1
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Paul Henry
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2013-10-10 00:00:00.000000000 Z
13
+ date: 2013-10-15 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: sequel