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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d2dce85ba1914970e81126721a1bfd51d6b9208d
4
- data.tar.gz: 0376b7682b6ae4b35a91146bab97332eb208962e
3
+ metadata.gz: e8da54e7c94ed8f3eda67c2be550c95aa722bfd3
4
+ data.tar.gz: 047620efbb7536b0a187b50e3d276d46539012e9
5
5
  SHA512:
6
- metadata.gz: f799c6bd555910a534954d137aac874f94ba9b57315c988066b696a09c381b6b81db75cfb6965d040e9a2ad26ccdd04f0bb1b562a5acfe7245658a315b1d19b2
7
- data.tar.gz: a7cf6e434056d0cd54d693f9ffb09668e3e5bddebbe42fce825f5c36830ce0323173fdf6c8b039da16703f31f1df19478be2aa696be567c18cd183f81b7919ca
6
+ metadata.gz: 21e6938c04438c694bd04173cf53a0b7bd9d3c6677b4477909908e750e279e3b97b39984992d94feff45f7969775b1b5224ff8d2cb17aaa2e1ae41c276eb6b88
7
+ data.tar.gz: 8b67577bcdf9dd92391d78a6bafca000724560e96fa11b2ceec025cbc22ceb2d0fb15a585d365d0e1bc39cc5ed5eaadf2edebbda67dddc6da4e5f60d5df40cc1
data/Gemfile CHANGED
@@ -7,4 +7,5 @@ group :test do
7
7
  gem 'rspec'
8
8
  gem 'mocha', require: false
9
9
  gem 'pry-nav'
10
+ gem 'guard-rspec'
10
11
  end
data/Guardfile ADDED
@@ -0,0 +1,9 @@
1
+ #!/usr/bin/env ruby
2
+ #^syntax detection
3
+
4
+ guard :rspec do
5
+ watch(%r{^spec/.+_spec\.rb$})
6
+ watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
7
+ watch('spec/spec_helper.rb') { "spec" }
8
+ end
9
+
@@ -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(master_config_for(config).merge!(replica_hash_for(config)))
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(master_config_for(db_config_for(name)))
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 master_config_for(config)
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
@@ -1,5 +1,5 @@
1
1
  module Sequel
2
2
  module SchemaSharding
3
- VERSION = "0.5.0"
3
+ VERSION = "0.5.1"
4
4
  end
5
5
  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 = "sequel-schema-sharding"
7
+ spec.name = 'sequel-schema-sharding'
8
8
  spec.version = Sequel::SchemaSharding::VERSION
9
- spec.authors = ["Paul Henry", "James Hart", "Eric Saxby"]
10
- spec.email = ["dev@wanelo.com"]
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 = "https://github.com/wanelo/sequel-schema-sharding"
14
- spec.license = "MIT"
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 = ["lib"]
19
+ spec.require_paths = %w(lib)
20
20
 
21
- spec.add_dependency "sequel"
22
- spec.add_dependency "pg"
21
+ spec.add_dependency 'sequel'
22
+ spec.add_dependency 'pg'
23
+ spec.add_dependency 'ruby-usdt'
23
24
 
24
- spec.add_development_dependency "bundler", "~> 1.3"
25
- spec.add_development_dependency "rake"
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
- #it 'executes a select against a replica' do
28
- # shard = subject['shard2']
29
- # Sequel::ShardedThreadedConnectionPool.any_instance.expects(:hold).with(:read_only).at_least_once
30
- # Sequel::ShardedThreadedConnectionPool.any_instance.expects(:hold).with(:default).at_least_once
31
- # shard[:"sequel_explosions_boof_pickles_3__artists"].first
32
- #end
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.0
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-15 00:00:00.000000000 Z
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