ar-octopus 0.6.1 → 0.7.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 +15 -0
- data/.ruby-version +1 -0
- data/.travis.yml +0 -2
- data/Appraisals +0 -5
- data/ar-octopus.gemspec +4 -2
- data/lib/octopus.rb +1 -13
- data/lib/octopus/model.rb +6 -10
- data/lib/octopus/proxy.rb +29 -10
- data/lib/octopus/rails3/abstract_adapter.rb +11 -0
- data/lib/octopus/{rails3.1 → rails3}/singular_association.rb +0 -0
- data/lib/octopus/version.rb +1 -1
- data/spec/config/shards.yml +8 -0
- data/spec/octopus/proxy_spec.rb +1 -1
- data/spec/octopus/replication_spec.rb +29 -0
- data/spec/support/query_count.rb +19 -0
- data/spec/support/shared_contexts.rb +21 -0
- metadata +153 -182
- data/gemfiles/rails30.gemfile +0 -8
- data/lib/octopus/rails3.0/arel.rb +0 -13
- data/lib/octopus/rails3.0/association.rb +0 -86
checksums.yaml
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
---
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: !binary |-
|
4
|
+
NDBkZGI5ZDAzMjU4MzkxZjVlYWZjMGI5ODQ0NDhiYjI1NTM5NjNkOQ==
|
5
|
+
data.tar.gz: !binary |-
|
6
|
+
MGE2MWM1YWZiNDQzNGQ3ZDE2ZTU4ZDljMzA1Nzk5N2Q2YzNjZTBlMA==
|
7
|
+
!binary "U0hBNTEy":
|
8
|
+
metadata.gz: !binary |-
|
9
|
+
MDM1OTdhNGQwYjZkMjhiMTVmMDRmZmM2NmMyNzAwN2E3NTNhN2ZmM2ZmODZh
|
10
|
+
OGQ3ODUyZjU3ZTNjNzM0NDYzYmNiMjBjOGMxNmI4OTdkYTZjYTZhYzE1Mzgz
|
11
|
+
MmY5NTA1NGFmMTljNmIwNGUxNGY3NTU2ZWEzZTkyZmViNTBiYWY=
|
12
|
+
data.tar.gz: !binary |-
|
13
|
+
YWRmMDc0MjU5YzY1Y2MxNWJiZjRhMzhiMDk3MzAyMzc0NjhmZDk2NTUyNDli
|
14
|
+
MmQxODE2ZmNhM2EwYWQyZWNlZTYwOWYwOWRlMTlkMjlhYzQ5YzBmOWVmNjI1
|
15
|
+
OGM5YzBjOTMwODg0YjEyYzY3YWU1NDY4OWRhOGIwYTY3MjhmYWY=
|
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
1.9.3
|
data/.travis.yml
CHANGED
data/Appraisals
CHANGED
data/ar-octopus.gemspec
CHANGED
@@ -21,8 +21,8 @@ Gem::Specification.new do |s|
|
|
21
21
|
"Octopus now stores schema version information in each shard and migrations will not " \
|
22
22
|
"work properly unless this task is invoked."
|
23
23
|
|
24
|
-
s.add_dependency 'activerecord', '>= 3.
|
25
|
-
s.add_dependency 'activesupport', '>= 3.
|
24
|
+
s.add_dependency 'activerecord', '>= 3.1.0', '< 4.0'
|
25
|
+
s.add_dependency 'activesupport', '>= 3.1.0', '< 4.0'
|
26
26
|
s.add_development_dependency 'rake', '>= 0.8.7'
|
27
27
|
s.add_development_dependency 'rspec', '>= 2.0.0'
|
28
28
|
s.add_development_dependency 'mysql2', '> 0.3'
|
@@ -30,4 +30,6 @@ Gem::Specification.new do |s|
|
|
30
30
|
s.add_development_dependency 'sqlite3', '>= 1.3.4'
|
31
31
|
s.add_development_dependency 'pry'
|
32
32
|
s.add_development_dependency 'appraisal', '>= 0.3.8'
|
33
|
+
|
34
|
+
s.license = 'MIT'
|
33
35
|
end
|
data/lib/octopus.rb
CHANGED
@@ -64,10 +64,6 @@ module Octopus
|
|
64
64
|
@environments ||= config['environments'] || ['production']
|
65
65
|
end
|
66
66
|
|
67
|
-
def self.rails30?
|
68
|
-
ActiveRecord::VERSION::MAJOR == 3 && ActiveRecord::VERSION::MINOR == 0
|
69
|
-
end
|
70
|
-
|
71
67
|
def self.rails31?
|
72
68
|
ActiveRecord::VERSION::MAJOR == 3 && ActiveRecord::VERSION::MINOR == 1
|
73
69
|
end
|
@@ -105,20 +101,12 @@ require "octopus/association"
|
|
105
101
|
require "octopus/rails3/persistence"
|
106
102
|
require "octopus/rails3/log_subscriber"
|
107
103
|
require "octopus/rails3/abstract_adapter"
|
104
|
+
require "octopus/rails3/singular_association"
|
108
105
|
|
109
106
|
if defined?(::Rails)
|
110
107
|
require "octopus/railtie"
|
111
108
|
end
|
112
109
|
|
113
|
-
if Octopus.rails30?
|
114
|
-
require "octopus/rails3.0/arel"
|
115
|
-
require "octopus/rails3.0/association"
|
116
|
-
end
|
117
|
-
|
118
|
-
if Octopus.rails31? || Octopus.rails32?
|
119
|
-
require "octopus/rails3.1/singular_association"
|
120
|
-
end
|
121
|
-
|
122
110
|
if Octopus.rails32?
|
123
111
|
require "octopus/rails3.2/persistence"
|
124
112
|
end
|
data/lib/octopus/model.rb
CHANGED
@@ -86,9 +86,7 @@ module Octopus::Model
|
|
86
86
|
base.send(:alias_method, :equality_without_octopus, :==)
|
87
87
|
base.send(:alias_method, :==, :equality_with_octopus)
|
88
88
|
base.send(:alias_method, :eql?, :==)
|
89
|
-
|
90
|
-
base.send(:alias_method_chain, :perform_validations, :octopus)
|
91
|
-
end
|
89
|
+
base.send(:alias_method_chain, :perform_validations, :octopus)
|
92
90
|
end
|
93
91
|
|
94
92
|
def should_set_current_shard?
|
@@ -113,15 +111,13 @@ module Octopus::Model
|
|
113
111
|
equality_without_octopus(comparison_object) && comparison_object.current_shard == current_shard
|
114
112
|
end
|
115
113
|
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
Octopus.using(self.current_shard) do
|
120
|
-
perform_validations_without_octopus(*args)
|
121
|
-
end
|
122
|
-
else
|
114
|
+
def perform_validations_with_octopus(*args)
|
115
|
+
if Octopus.enabled? and should_set_current_shard?
|
116
|
+
Octopus.using(self.current_shard) do
|
123
117
|
perform_validations_without_octopus(*args)
|
124
118
|
end
|
119
|
+
else
|
120
|
+
perform_validations_without_octopus(*args)
|
125
121
|
end
|
126
122
|
end
|
127
123
|
end
|
data/lib/octopus/proxy.rb
CHANGED
@@ -60,6 +60,7 @@ class Octopus::Proxy
|
|
60
60
|
else
|
61
61
|
@fully_replicated = true
|
62
62
|
end
|
63
|
+
|
63
64
|
@slaves_list = @shards.keys.map {|sym| sym.to_s}.sort
|
64
65
|
@slaves_list.delete('master')
|
65
66
|
@slave_index = 0
|
@@ -139,18 +140,20 @@ class Octopus::Proxy
|
|
139
140
|
@groups.fetch(group.to_s, nil)
|
140
141
|
end
|
141
142
|
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
# reconnect, but in Rails 3.1 the flag prevents this.
|
143
|
+
# Rails 3.1 sets automatic_reconnect to false when it removes
|
144
|
+
# connection pool. Octopus can potentially retain a reference to a closed
|
145
|
+
# connection pool. Previously, that would work since the pool would just
|
146
|
+
# reconnect, but in Rails 3.1 the flag prevents this.
|
147
|
+
def safe_connection(connection_pool)
|
148
148
|
if Octopus.rails31? || Octopus.rails32?
|
149
|
-
|
150
|
-
@shards[shard_name].automatic_reconnect = true
|
151
|
-
end
|
149
|
+
connection_pool.automatic_reconnect ||= true
|
152
150
|
end
|
153
|
-
|
151
|
+
connection_pool.connection()
|
152
|
+
end
|
153
|
+
|
154
|
+
def select_connection
|
155
|
+
@shards[shard_name].verify_active_connections! if @verify_connection
|
156
|
+
safe_connection(@shards[shard_name])
|
154
157
|
end
|
155
158
|
|
156
159
|
def shard_name
|
@@ -224,6 +227,22 @@ class Octopus::Proxy
|
|
224
227
|
return @shards[current_shard]
|
225
228
|
end
|
226
229
|
|
230
|
+
def enable_query_cache!
|
231
|
+
@shards.each do |k, v|
|
232
|
+
c = safe_connection(v)
|
233
|
+
c.clear_query_cache_without_octopus
|
234
|
+
c.enable_query_cache!
|
235
|
+
end
|
236
|
+
end
|
237
|
+
|
238
|
+
def disable_query_cache!
|
239
|
+
@shards.each { |k, v| safe_connection(v).disable_query_cache! }
|
240
|
+
end
|
241
|
+
|
242
|
+
def clear_all_query_caches!
|
243
|
+
@shards.each { |k, v| safe_connection(v).clear_query_cache_without_octopus }
|
244
|
+
end
|
245
|
+
|
227
246
|
protected
|
228
247
|
def connection_pool_for(adapter, config)
|
229
248
|
ActiveRecord::ConnectionAdapters::ConnectionPool.new(ActiveRecord::Base::ConnectionSpecification.new(adapter.dup, config))
|
@@ -21,6 +21,7 @@ module Octopus
|
|
21
21
|
|
22
22
|
def self.included(base)
|
23
23
|
base.alias_method_chain :initialize, :octopus_shard
|
24
|
+
base.alias_method_chain :clear_query_cache, :octopus
|
24
25
|
end
|
25
26
|
|
26
27
|
def octopus_shard
|
@@ -32,6 +33,16 @@ module Octopus
|
|
32
33
|
@instrumenter = InstrumenterDecorator.new(self, @instrumenter)
|
33
34
|
end
|
34
35
|
|
36
|
+
# Intercept calls to clear_query_cache and make sure that all
|
37
|
+
# query caches on all shards are invalidated, just to be safe.
|
38
|
+
def clear_query_cache_with_octopus
|
39
|
+
if Octopus.enabled?
|
40
|
+
ActiveRecord::Base.connection_proxy.clear_all_query_caches!
|
41
|
+
else
|
42
|
+
clear_query_cache_without_octopus
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
35
46
|
end
|
36
47
|
end
|
37
48
|
end
|
File without changes
|
data/lib/octopus/version.rb
CHANGED
data/spec/config/shards.yml
CHANGED
data/spec/octopus/proxy_spec.rb
CHANGED
@@ -239,7 +239,7 @@ describe Octopus::Proxy do
|
|
239
239
|
end
|
240
240
|
end
|
241
241
|
|
242
|
-
if !Octopus.
|
242
|
+
if !Octopus.rails31?
|
243
243
|
describe "saving multiple sharded objects at once" do
|
244
244
|
before :each do
|
245
245
|
@p = MmorpgPlayer.using(:alone_shard).create!(:player_name => 'Thiago')
|
@@ -26,6 +26,28 @@ describe "when the database is replicated" do
|
|
26
26
|
end
|
27
27
|
end
|
28
28
|
|
29
|
+
describe "When enabling the query cache" do
|
30
|
+
include_context "with query cache enabled"
|
31
|
+
|
32
|
+
it "should do the queries with cache" do
|
33
|
+
OctopusHelper.using_environment :replicated_with_one_slave do
|
34
|
+
cat1 = Cat.using(:master).create!(:name => "Master Cat 1")
|
35
|
+
cat2 = Cat.using(:master).create!(:name => "Master Cat 2")
|
36
|
+
Cat.using(:master).find(cat1.id).should eq(cat1)
|
37
|
+
Cat.using(:master).find(cat1.id).should eq(cat1)
|
38
|
+
Cat.using(:master).find(cat1.id).should eq(cat1)
|
39
|
+
|
40
|
+
cat3 = Cat.using(:slave1).create!(:name => "Slave Cat 3")
|
41
|
+
cat4 = Cat.using(:slave1).create!(:name => "Slave Cat 4")
|
42
|
+
Cat.find(cat3.id).id.should eq(cat3.id)
|
43
|
+
Cat.find(cat3.id).id.should eq(cat3.id)
|
44
|
+
Cat.find(cat3.id).id.should eq(cat3.id)
|
45
|
+
|
46
|
+
counter.query_count.should eq(16)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
29
51
|
it "should allow #using syntax to send queries to master" do
|
30
52
|
Cat.create!(:name => "Master Cat")
|
31
53
|
|
@@ -40,6 +62,13 @@ describe "when the database is replicated" do
|
|
40
62
|
Cat.count.should == 0
|
41
63
|
end
|
42
64
|
end
|
65
|
+
|
66
|
+
def active_support_subscribed(callback, *args, &block)
|
67
|
+
subscriber = ActiveSupport::Notifications.subscribe(*args, &callback)
|
68
|
+
yield
|
69
|
+
ensure
|
70
|
+
ActiveSupport::Notifications.unsubscribe(subscriber)
|
71
|
+
end
|
43
72
|
end
|
44
73
|
|
45
74
|
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module ActiveRecord
|
2
|
+
class QueryCounter
|
3
|
+
|
4
|
+
attr_accessor :query_count
|
5
|
+
|
6
|
+
def initialize
|
7
|
+
@query_count = 0
|
8
|
+
end
|
9
|
+
|
10
|
+
def to_proc
|
11
|
+
lambda(&method(:callback))
|
12
|
+
end
|
13
|
+
|
14
|
+
def callback(name, start, finish, message_id, values)
|
15
|
+
@query_count += 1 unless %w(CACHE SCHEMA).include?(values[:name])
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
shared_context "with query cache enabled" do
|
2
|
+
let!(:counter) { ActiveRecord::QueryCounter.new }
|
3
|
+
|
4
|
+
before(:each) do
|
5
|
+
ActiveRecord::Base.connection.enable_query_cache!
|
6
|
+
counter.query_count = 0
|
7
|
+
end
|
8
|
+
|
9
|
+
after(:each) do
|
10
|
+
ActiveRecord::Base.connection.disable_query_cache!
|
11
|
+
end
|
12
|
+
|
13
|
+
around(:each) do |example|
|
14
|
+
# TODO - Support Rails 3.0
|
15
|
+
if Octopus.rails31? || Octopus.rails32?
|
16
|
+
active_support_subscribed(counter.to_proc, 'sql.active_record') do
|
17
|
+
example.run
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
metadata
CHANGED
@@ -1,193 +1,169 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: ar-octopus
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
5
|
-
prerelease:
|
6
|
-
segments:
|
7
|
-
- 0
|
8
|
-
- 6
|
9
|
-
- 1
|
10
|
-
version: 0.6.1
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.7.0
|
11
5
|
platform: ruby
|
12
|
-
authors:
|
6
|
+
authors:
|
13
7
|
- Thiago Pradi
|
14
8
|
- Mike Perham
|
15
9
|
- Gabriel Sobrinho
|
16
10
|
autorequire:
|
17
11
|
bindir: bin
|
18
12
|
cert_chain: []
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
- !ruby/object:Gem::Dependency
|
13
|
+
date: 2013-10-06 00:00:00.000000000 Z
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
23
16
|
name: activerecord
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
hash: 7
|
30
|
-
segments:
|
31
|
-
- 3
|
32
|
-
- 0
|
33
|
-
- 0
|
34
|
-
version: 3.0.0
|
17
|
+
requirement: !ruby/object:Gem::Requirement
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: 3.1.0
|
35
22
|
- - <
|
36
|
-
- !ruby/object:Gem::Version
|
37
|
-
|
38
|
-
segments:
|
39
|
-
- 4
|
40
|
-
- 0
|
41
|
-
version: "4.0"
|
42
|
-
prerelease: false
|
23
|
+
- !ruby/object:Gem::Version
|
24
|
+
version: '4.0'
|
43
25
|
type: :runtime
|
44
|
-
|
45
|
-
|
26
|
+
prerelease: false
|
27
|
+
version_requirements: !ruby/object:Gem::Requirement
|
28
|
+
requirements:
|
29
|
+
- - ! '>='
|
30
|
+
- !ruby/object:Gem::Version
|
31
|
+
version: 3.1.0
|
32
|
+
- - <
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: '4.0'
|
35
|
+
- !ruby/object:Gem::Dependency
|
46
36
|
name: activesupport
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
hash: 7
|
53
|
-
segments:
|
54
|
-
- 3
|
55
|
-
- 0
|
56
|
-
- 0
|
57
|
-
version: 3.0.0
|
37
|
+
requirement: !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - ! '>='
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: 3.1.0
|
58
42
|
- - <
|
59
|
-
- !ruby/object:Gem::Version
|
60
|
-
|
61
|
-
segments:
|
62
|
-
- 4
|
63
|
-
- 0
|
64
|
-
version: "4.0"
|
65
|
-
prerelease: false
|
43
|
+
- !ruby/object:Gem::Version
|
44
|
+
version: '4.0'
|
66
45
|
type: :runtime
|
67
|
-
|
68
|
-
|
46
|
+
prerelease: false
|
47
|
+
version_requirements: !ruby/object:Gem::Requirement
|
48
|
+
requirements:
|
49
|
+
- - ! '>='
|
50
|
+
- !ruby/object:Gem::Version
|
51
|
+
version: 3.1.0
|
52
|
+
- - <
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '4.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
69
56
|
name: rake
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
- !ruby/object:Gem::Version
|
75
|
-
hash: 49
|
76
|
-
segments:
|
77
|
-
- 0
|
78
|
-
- 8
|
79
|
-
- 7
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
80
61
|
version: 0.8.7
|
81
|
-
prerelease: false
|
82
62
|
type: :development
|
83
|
-
|
84
|
-
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ! '>='
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 0.8.7
|
69
|
+
- !ruby/object:Gem::Dependency
|
85
70
|
name: rspec
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
- !ruby/object:Gem::Version
|
91
|
-
hash: 15
|
92
|
-
segments:
|
93
|
-
- 2
|
94
|
-
- 0
|
95
|
-
- 0
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ! '>='
|
74
|
+
- !ruby/object:Gem::Version
|
96
75
|
version: 2.0.0
|
97
|
-
prerelease: false
|
98
76
|
type: :development
|
99
|
-
requirement: *id004
|
100
|
-
- !ruby/object:Gem::Dependency
|
101
|
-
name: mysql2
|
102
|
-
version_requirements: &id005 !ruby/object:Gem::Requirement
|
103
|
-
none: false
|
104
|
-
requirements:
|
105
|
-
- - ">"
|
106
|
-
- !ruby/object:Gem::Version
|
107
|
-
hash: 13
|
108
|
-
segments:
|
109
|
-
- 0
|
110
|
-
- 3
|
111
|
-
version: "0.3"
|
112
77
|
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ! '>='
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: 2.0.0
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: mysql2
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ! '>'
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0.3'
|
113
90
|
type: :development
|
114
|
-
|
115
|
-
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ! '>'
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0.3'
|
97
|
+
- !ruby/object:Gem::Dependency
|
116
98
|
name: pg
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
- !ruby/object:Gem::Version
|
122
|
-
hash: 51
|
123
|
-
segments:
|
124
|
-
- 0
|
125
|
-
- 11
|
126
|
-
- 0
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ! '>='
|
102
|
+
- !ruby/object:Gem::Version
|
127
103
|
version: 0.11.0
|
128
|
-
prerelease: false
|
129
104
|
type: :development
|
130
|
-
|
131
|
-
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ! '>='
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: 0.11.0
|
111
|
+
- !ruby/object:Gem::Dependency
|
132
112
|
name: sqlite3
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
- !ruby/object:Gem::Version
|
138
|
-
hash: 19
|
139
|
-
segments:
|
140
|
-
- 1
|
141
|
-
- 3
|
142
|
-
- 4
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - ! '>='
|
116
|
+
- !ruby/object:Gem::Version
|
143
117
|
version: 1.3.4
|
144
|
-
prerelease: false
|
145
118
|
type: :development
|
146
|
-
requirement: *id007
|
147
|
-
- !ruby/object:Gem::Dependency
|
148
|
-
name: pry
|
149
|
-
version_requirements: &id008 !ruby/object:Gem::Requirement
|
150
|
-
none: false
|
151
|
-
requirements:
|
152
|
-
- - ">="
|
153
|
-
- !ruby/object:Gem::Version
|
154
|
-
hash: 3
|
155
|
-
segments:
|
156
|
-
- 0
|
157
|
-
version: "0"
|
158
119
|
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - ! '>='
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: 1.3.4
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: pry
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - ! '>='
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: '0'
|
159
132
|
type: :development
|
160
|
-
|
161
|
-
|
133
|
+
prerelease: false
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - ! '>='
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: '0'
|
139
|
+
- !ruby/object:Gem::Dependency
|
162
140
|
name: appraisal
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
- !ruby/object:Gem::Version
|
168
|
-
hash: 3
|
169
|
-
segments:
|
170
|
-
- 0
|
171
|
-
- 3
|
172
|
-
- 8
|
141
|
+
requirement: !ruby/object:Gem::Requirement
|
142
|
+
requirements:
|
143
|
+
- - ! '>='
|
144
|
+
- !ruby/object:Gem::Version
|
173
145
|
version: 0.3.8
|
174
|
-
prerelease: false
|
175
146
|
type: :development
|
176
|
-
|
177
|
-
|
178
|
-
|
147
|
+
prerelease: false
|
148
|
+
version_requirements: !ruby/object:Gem::Requirement
|
149
|
+
requirements:
|
150
|
+
- - ! '>='
|
151
|
+
- !ruby/object:Gem::Version
|
152
|
+
version: 0.3.8
|
153
|
+
description: This gem allows you to use sharded databases with ActiveRecord. This
|
154
|
+
also provides a interface for replication and for running migrations with multiples
|
155
|
+
shards.
|
156
|
+
email:
|
179
157
|
- tchandy@gmail.com
|
180
158
|
- mperham@gmail.com
|
181
159
|
- gabriel.sobrinho@gmail.com
|
182
160
|
executables: []
|
183
|
-
|
184
161
|
extensions: []
|
185
|
-
|
186
162
|
extra_rdoc_files: []
|
187
|
-
|
188
|
-
files:
|
163
|
+
files:
|
189
164
|
- .gitignore
|
190
165
|
- .rspec
|
166
|
+
- .ruby-version
|
191
167
|
- .travis.yml
|
192
168
|
- Appraisals
|
193
169
|
- Gemfile
|
@@ -195,7 +171,6 @@ files:
|
|
195
171
|
- Rakefile
|
196
172
|
- TODO.txt
|
197
173
|
- ar-octopus.gemspec
|
198
|
-
- gemfiles/rails30.gemfile
|
199
174
|
- gemfiles/rails31.gemfile
|
200
175
|
- gemfiles/rails32.gemfile
|
201
176
|
- init.rb
|
@@ -207,13 +182,11 @@ files:
|
|
207
182
|
- lib/octopus/migration.rb
|
208
183
|
- lib/octopus/model.rb
|
209
184
|
- lib/octopus/proxy.rb
|
210
|
-
- lib/octopus/rails3.0/arel.rb
|
211
|
-
- lib/octopus/rails3.0/association.rb
|
212
|
-
- lib/octopus/rails3.1/singular_association.rb
|
213
185
|
- lib/octopus/rails3.2/persistence.rb
|
214
186
|
- lib/octopus/rails3/abstract_adapter.rb
|
215
187
|
- lib/octopus/rails3/log_subscriber.rb
|
216
188
|
- lib/octopus/rails3/persistence.rb
|
189
|
+
- lib/octopus/rails3/singular_association.rb
|
217
190
|
- lib/octopus/railtie.rb
|
218
191
|
- lib/octopus/scope_proxy.rb
|
219
192
|
- lib/octopus/version.rb
|
@@ -323,45 +296,41 @@ files:
|
|
323
296
|
- spec/support/database_connection.rb
|
324
297
|
- spec/support/database_models.rb
|
325
298
|
- spec/support/octopus_helper.rb
|
299
|
+
- spec/support/query_count.rb
|
300
|
+
- spec/support/shared_contexts.rb
|
326
301
|
- spec/tasks/octopus.rake_spec.rb
|
327
302
|
homepage: https://github.com/tchandy/octopus
|
328
|
-
licenses:
|
303
|
+
licenses:
|
304
|
+
- MIT
|
305
|
+
metadata: {}
|
306
|
+
post_install_message: ! 'Important: If you are upgrading from < Octopus 0.5.0 you
|
307
|
+
need to run:
|
329
308
|
|
330
|
-
post_install_message: |-
|
331
|
-
Important: If you are upgrading from < Octopus 0.5.0 you need to run:
|
332
309
|
$ rake octopus:copy_schema_versions
|
333
|
-
|
334
|
-
Octopus now stores schema version information in each shard and migrations will not work properly unless this task is invoked.
|
335
|
-
rdoc_options: []
|
336
310
|
|
337
|
-
|
311
|
+
|
312
|
+
Octopus now stores schema version information in each shard and migrations will
|
313
|
+
not work properly unless this task is invoked.'
|
314
|
+
rdoc_options: []
|
315
|
+
require_paths:
|
338
316
|
- lib
|
339
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
340
|
-
|
341
|
-
|
342
|
-
|
343
|
-
|
344
|
-
|
345
|
-
|
346
|
-
|
347
|
-
|
348
|
-
|
349
|
-
none: false
|
350
|
-
requirements:
|
351
|
-
- - ">="
|
352
|
-
- !ruby/object:Gem::Version
|
353
|
-
hash: 3
|
354
|
-
segments:
|
355
|
-
- 0
|
356
|
-
version: "0"
|
317
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
318
|
+
requirements:
|
319
|
+
- - ! '>='
|
320
|
+
- !ruby/object:Gem::Version
|
321
|
+
version: '0'
|
322
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
323
|
+
requirements:
|
324
|
+
- - ! '>='
|
325
|
+
- !ruby/object:Gem::Version
|
326
|
+
version: '0'
|
357
327
|
requirements: []
|
358
|
-
|
359
328
|
rubyforge_project:
|
360
|
-
rubygems_version:
|
329
|
+
rubygems_version: 2.0.10
|
361
330
|
signing_key:
|
362
|
-
specification_version:
|
331
|
+
specification_version: 4
|
363
332
|
summary: Easy Database Sharding for ActiveRecord
|
364
|
-
test_files:
|
333
|
+
test_files:
|
365
334
|
- spec/config/shards.yml
|
366
335
|
- spec/migrations/10_create_users_using_replication.rb
|
367
336
|
- spec/migrations/11_add_field_in_all_slaves.rb
|
@@ -391,4 +360,6 @@ test_files:
|
|
391
360
|
- spec/support/database_connection.rb
|
392
361
|
- spec/support/database_models.rb
|
393
362
|
- spec/support/octopus_helper.rb
|
363
|
+
- spec/support/query_count.rb
|
364
|
+
- spec/support/shared_contexts.rb
|
394
365
|
- spec/tasks/octopus.rake_spec.rb
|
data/gemfiles/rails30.gemfile
DELETED
@@ -1,13 +0,0 @@
|
|
1
|
-
class Arel::Visitors::ToSql
|
2
|
-
def quote value, column = nil
|
3
|
-
@connection.quote value, column
|
4
|
-
end
|
5
|
-
|
6
|
-
def quote_table_name name
|
7
|
-
@connection.quote_table_name(name)
|
8
|
-
end
|
9
|
-
|
10
|
-
def quote_column_name name
|
11
|
-
Arel::Nodes::SqlLiteral === name ? name : @connection.quote_column_name(name)
|
12
|
-
end
|
13
|
-
end
|
@@ -1,86 +0,0 @@
|
|
1
|
-
module Octopus
|
2
|
-
module Rails3
|
3
|
-
module Association
|
4
|
-
def association_accessor_methods(reflection, association_proxy_class)
|
5
|
-
super
|
6
|
-
|
7
|
-
define_method("#{reflection.name}_with_octopus") do |*params|
|
8
|
-
reload_connection
|
9
|
-
send("#{reflection.name}_without_octopus", *params)
|
10
|
-
end
|
11
|
-
|
12
|
-
define_method("loaded_#{reflection.name}_with_octopus?") do
|
13
|
-
reload_connection
|
14
|
-
send("loaded_#{reflection.name}_without_octopus?")
|
15
|
-
end
|
16
|
-
|
17
|
-
define_method("#{reflection.name}_with_octopus=") do |new_value|
|
18
|
-
reload_connection
|
19
|
-
send("#{reflection.name}_without_octopus=", new_value)
|
20
|
-
end
|
21
|
-
|
22
|
-
define_method("set_#{reflection.name}_target_with_octopus") do |target|
|
23
|
-
reload_connection
|
24
|
-
send("set_#{reflection.name}_target_without_octopus", target)
|
25
|
-
end
|
26
|
-
|
27
|
-
alias_method_chain reflection.name, "octopus"
|
28
|
-
alias_method_chain "loaded_#{reflection.name}?", "octopus"
|
29
|
-
alias_method_chain "#{reflection.name}=", "octopus"
|
30
|
-
alias_method_chain "set_#{reflection.name}_target", "octopus"
|
31
|
-
end
|
32
|
-
|
33
|
-
def collection_reader_method(reflection, association_proxy_class)
|
34
|
-
super
|
35
|
-
|
36
|
-
define_method("#{reflection.name}_with_octopus") do |*params|
|
37
|
-
reload_connection
|
38
|
-
send("#{reflection.name}_without_octopus", *params)
|
39
|
-
end
|
40
|
-
|
41
|
-
define_method("#{reflection.name.to_s.singularize}_ids_with_octopus") do
|
42
|
-
reload_connection
|
43
|
-
send("#{reflection.name.to_s.singularize}_ids_without_octopus")
|
44
|
-
end
|
45
|
-
|
46
|
-
alias_method_chain reflection.name, "octopus"
|
47
|
-
alias_method_chain "#{reflection.name.to_s.singularize}_ids", "octopus"
|
48
|
-
end
|
49
|
-
|
50
|
-
def collection_accessor_methods(reflection, association_proxy_class, writer = true)
|
51
|
-
super
|
52
|
-
|
53
|
-
if writer
|
54
|
-
define_method("#{reflection.name}_with_octopus=") do |new_value|
|
55
|
-
reload_connection
|
56
|
-
send("#{reflection.name}_without_octopus=", new_value)
|
57
|
-
end
|
58
|
-
|
59
|
-
define_method("#{reflection.name.to_s.singularize}_ids_with_octopus=") do |new_value|
|
60
|
-
reload_connection
|
61
|
-
send("#{reflection.name.to_s.singularize}_ids_without_octopus=", new_value)
|
62
|
-
end
|
63
|
-
|
64
|
-
alias_method_chain "#{reflection.name}=", "octopus"
|
65
|
-
alias_method_chain "#{reflection.name.to_s.singularize}_ids=", "octopus"
|
66
|
-
end
|
67
|
-
end
|
68
|
-
|
69
|
-
def association_constructor_method(constructor, reflection, association_proxy_class)
|
70
|
-
super
|
71
|
-
|
72
|
-
define_method("#{constructor}_#{reflection.name}_with_octopus") do |*params|
|
73
|
-
reload_connection
|
74
|
-
result = send("#{constructor}_#{reflection.name}_without_octopus", *params)
|
75
|
-
|
76
|
-
result.current_shard = current_shard if should_set_current_shard?
|
77
|
-
result
|
78
|
-
end
|
79
|
-
|
80
|
-
alias_method_chain "#{constructor}_#{reflection.name}", "octopus"
|
81
|
-
end
|
82
|
-
end
|
83
|
-
end
|
84
|
-
end
|
85
|
-
|
86
|
-
ActiveRecord::Base.extend(Octopus::Rails3::Association)
|