sequel-schema-sharding 0.5.0 → 0.5.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +1 -0
- data/Guardfile +9 -0
- data/lib/sequel/schema-sharding/connection_manager.rb +23 -4
- data/lib/sequel/schema-sharding/version.rb +1 -1
- data/sequel-schema-sharding.gemspec +11 -10
- data/spec/schema-sharding/connection_manager_spec.rb +6 -6
- metadata +17 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e8da54e7c94ed8f3eda67c2be550c95aa722bfd3
|
4
|
+
data.tar.gz: 047620efbb7536b0a187b50e3d276d46539012e9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 21e6938c04438c694bd04173cf53a0b7bd9d3c6677b4477909908e750e279e3b97b39984992d94feff45f7969775b1b5224ff8d2cb17aaa2e1ae41c276eb6b88
|
7
|
+
data.tar.gz: 8b67577bcdf9dd92391d78a6bafca000724560e96fa11b2ceec025cbc22ceb2d0fb15a585d365d0e1bc39cc5ed5eaadf2edebbda67dddc6da4e5f60d5df40cc1
|
data/Gemfile
CHANGED
data/Guardfile
ADDED
@@ -2,6 +2,9 @@ require 'singleton'
|
|
2
2
|
|
3
3
|
module Sequel
|
4
4
|
module SchemaSharding
|
5
|
+
##
|
6
|
+
# Used to manage database connections separately from database shards
|
7
|
+
|
5
8
|
class ConnectionManager
|
6
9
|
attr_reader :connections
|
7
10
|
|
@@ -11,11 +14,15 @@ module Sequel
|
|
11
14
|
|
12
15
|
def [](name)
|
13
16
|
config = db_config_for(name)
|
14
|
-
@connections[name.to_s] ||= Sequel.postgres(
|
17
|
+
@connections[name.to_s] ||= Sequel.postgres(sequel_connection_config_for(config).merge!(replica_hash_for(config)))
|
15
18
|
end
|
16
19
|
|
20
|
+
##
|
21
|
+
# Used by rake tasks that need to deterministically work against a master
|
22
|
+
# database even when read/write splitting is configured.
|
23
|
+
|
17
24
|
def master(name)
|
18
|
-
@connections["master_#{name}"] ||= Sequel.postgres(
|
25
|
+
@connections["master_#{name}"] ||= Sequel.postgres(sequel_connection_config_for(db_config_for(name)))
|
19
26
|
end
|
20
27
|
|
21
28
|
def disconnect
|
@@ -25,12 +32,24 @@ module Sequel
|
|
25
32
|
@connections = {}
|
26
33
|
end
|
27
34
|
|
35
|
+
##
|
36
|
+
# Given +table_name+ and +shard_number+, returns the name of the
|
37
|
+
# PostgreSQL schema based on a +schema_name+ pattern defined in sharding.yml.
|
38
|
+
# +shard_number+ is interpolated into +schema_name+ via sprintf, so
|
39
|
+
# +schema_name+ should include a format specifier with which to interpolate
|
40
|
+
# it (ex. %s, %02d).
|
41
|
+
|
28
42
|
def schema_for(table_name, shard_number)
|
29
43
|
number_of_shards = config.number_of_shards(table_name)
|
30
44
|
pattern = config.schema_name(table_name)
|
31
45
|
sprintf pattern, shard_number
|
32
46
|
end
|
33
47
|
|
48
|
+
##
|
49
|
+
# Given +table_name+, return a functional dataset. This is used when models
|
50
|
+
# are loaded to read table columns and allow for data typecasting.
|
51
|
+
# In most cases it should not be used directly in application code.
|
52
|
+
|
34
53
|
def default_dataset_for(table_name)
|
35
54
|
shard_number = config.logical_shard_configs(table_name).keys.first
|
36
55
|
shard_name = config.logical_shard_configs(table_name)[shard_number]
|
@@ -39,7 +58,7 @@ module Sequel
|
|
39
58
|
|
40
59
|
private
|
41
60
|
|
42
|
-
def
|
61
|
+
def sequel_connection_config_for(config)
|
43
62
|
{
|
44
63
|
:user => config['username'],
|
45
64
|
:password => config['password'],
|
@@ -55,7 +74,7 @@ module Sequel
|
|
55
74
|
return {} if config['replicas'].nil?
|
56
75
|
{
|
57
76
|
:servers => {
|
58
|
-
:read_only => ->(db) { config['replicas'].sample }
|
77
|
+
:read_only => ->(db) { sequel_connection_config_for(config['replicas'].sample) }
|
59
78
|
}
|
60
79
|
}
|
61
80
|
end
|
@@ -4,23 +4,24 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
4
4
|
require 'sequel/schema-sharding/version'
|
5
5
|
|
6
6
|
Gem::Specification.new do |spec|
|
7
|
-
spec.name =
|
7
|
+
spec.name = 'sequel-schema-sharding'
|
8
8
|
spec.version = Sequel::SchemaSharding::VERSION
|
9
|
-
spec.authors = [
|
10
|
-
spec.email =
|
9
|
+
spec.authors = ['Paul Henry', 'James Hart', 'Eric Saxby']
|
10
|
+
spec.email = %w(dev@wanelo.com)
|
11
11
|
spec.description = %q{}
|
12
12
|
spec.summary = %q{Create horizontally sharded Sequel models with Postgres}
|
13
|
-
spec.homepage =
|
14
|
-
spec.license =
|
13
|
+
spec.homepage = 'https://github.com/wanelo/sequel-schema-sharding'
|
14
|
+
spec.license = 'MIT'
|
15
15
|
|
16
16
|
spec.files = `git ls-files`.split($/)
|
17
17
|
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
18
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
-
spec.require_paths =
|
19
|
+
spec.require_paths = %w(lib)
|
20
20
|
|
21
|
-
spec.add_dependency
|
22
|
-
spec.add_dependency
|
21
|
+
spec.add_dependency 'sequel'
|
22
|
+
spec.add_dependency 'pg'
|
23
|
+
spec.add_dependency 'ruby-usdt'
|
23
24
|
|
24
|
-
spec.add_development_dependency
|
25
|
-
spec.add_development_dependency
|
25
|
+
spec.add_development_dependency 'bundler', '~> 1.3'
|
26
|
+
spec.add_development_dependency 'rake'
|
26
27
|
end
|
@@ -24,12 +24,12 @@ describe Sequel::SchemaSharding::ConnectionManager do
|
|
24
24
|
expect(subject['shard1'].servers).to_not include(:read_only)
|
25
25
|
end
|
26
26
|
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
27
|
+
it 'executes a select against a replica' do
|
28
|
+
shard = subject['shard2']
|
29
|
+
ds = shard[:"sequel_explosions_boof_pickles_3__artists"]
|
30
|
+
shard.expects(:execute).once.with(anything, server: :read_only)
|
31
|
+
ds.first
|
32
|
+
end
|
33
33
|
end
|
34
34
|
end
|
35
35
|
|
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.5.
|
4
|
+
version: 0.5.1
|
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-
|
13
|
+
date: 2013-10-16 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: sequel
|
@@ -40,6 +40,20 @@ dependencies:
|
|
40
40
|
- - '>='
|
41
41
|
- !ruby/object:Gem::Version
|
42
42
|
version: '0'
|
43
|
+
- !ruby/object:Gem::Dependency
|
44
|
+
name: ruby-usdt
|
45
|
+
requirement: !ruby/object:Gem::Requirement
|
46
|
+
requirements:
|
47
|
+
- - '>='
|
48
|
+
- !ruby/object:Gem::Version
|
49
|
+
version: '0'
|
50
|
+
type: :runtime
|
51
|
+
prerelease: false
|
52
|
+
version_requirements: !ruby/object:Gem::Requirement
|
53
|
+
requirements:
|
54
|
+
- - '>='
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
version: '0'
|
43
57
|
- !ruby/object:Gem::Dependency
|
44
58
|
name: bundler
|
45
59
|
requirement: !ruby/object:Gem::Requirement
|
@@ -80,6 +94,7 @@ files:
|
|
80
94
|
- .travis.yml
|
81
95
|
- CONTRIBUTORS.md
|
82
96
|
- Gemfile
|
97
|
+
- Guardfile
|
83
98
|
- LICENSE.txt
|
84
99
|
- README.md
|
85
100
|
- Rakefile
|