active_record_shards 2.7.1 → 2.7.2
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.
- data/README.md +2 -2
- data/lib/active_record_shards/default_slave_patches.rb +15 -1
- data/lib/active_record_shards.rb +4 -0
- data/test/connection_switching_test.rb +8 -0
- data/test/models.rb +5 -0
- data/test/schema.rb +4 -0
- metadata +2 -2
data/README.md
CHANGED
@@ -3,8 +3,8 @@
|
|
3
3
|
ActiveRecord Shards is an extension for ActiveRecord that provides support for sharded database and slaves. Basically it is just a nice way to
|
4
4
|
switch between database connection. We've made the implementation very small, and have tried not to reinvent any wheels already present in ActiveRecord.
|
5
5
|
|
6
|
-
ActiveRecord Shards has
|
7
|
-
more than a year
|
6
|
+
ActiveRecord Shards has used and tested on Rails 2.3.x, 3.0.x, and 3.2.x and has in some form or another been used on in production on a large rails app for
|
7
|
+
more than a year.
|
8
8
|
|
9
9
|
## Installation
|
10
10
|
|
@@ -1,6 +1,6 @@
|
|
1
1
|
module ActiveRecordShards
|
2
2
|
module DefaultSlavePatches
|
3
|
-
CLASS_SLAVE_METHODS = [ :find_by_sql, :count_by_sql,
|
3
|
+
CLASS_SLAVE_METHODS = [ :find_by_sql, :count_by_sql, :calculate, :find_one, :find_some, :find_every, :quote_value, :sanitize_sql_hash_for_conditions, :exists? ]
|
4
4
|
|
5
5
|
def self.extended(base)
|
6
6
|
base_methods = (base.methods | base.private_methods).map(&:to_sym)
|
@@ -94,5 +94,19 @@ module ActiveRecordShards
|
|
94
94
|
yield
|
95
95
|
end
|
96
96
|
end
|
97
|
+
|
98
|
+
module ActiveRelationPatches
|
99
|
+
def self.included(base)
|
100
|
+
base.send :alias_method_chain, :calculate, :default_slave
|
101
|
+
end
|
102
|
+
|
103
|
+
def on_slave_unless_tx
|
104
|
+
@klass.on_slave_unless_tx { yield }
|
105
|
+
end
|
106
|
+
|
107
|
+
def calculate_with_default_slave(*args, &block)
|
108
|
+
on_slave_unless_tx { calculate_without_default_slave(*args, &block) }
|
109
|
+
end
|
110
|
+
end
|
97
111
|
end
|
98
112
|
end
|
data/lib/active_record_shards.rb
CHANGED
@@ -18,6 +18,10 @@ ActiveRecord::Base.extend(ActiveRecordShards::Model)
|
|
18
18
|
ActiveRecord::Base.extend(ActiveRecordShards::ConnectionSwitcher)
|
19
19
|
ActiveRecord::Base.extend(ActiveRecordShards::DefaultSlavePatches)
|
20
20
|
|
21
|
+
if ActiveRecord.const_defined?(:Relation)
|
22
|
+
ActiveRecord::Relation.send(:include, ActiveRecordShards::DefaultSlavePatches::ActiveRelationPatches)
|
23
|
+
end
|
24
|
+
|
21
25
|
if ActiveRecord::VERSION::STRING >= "3.1.0"
|
22
26
|
ActiveRecord::Associations::CollectionProxy.send(:include, ActiveRecordShards::AssociationCollectionConnectionSelection)
|
23
27
|
else
|
@@ -402,6 +402,14 @@ class ConnectionSwitchingTest < ActiveSupport::TestCase
|
|
402
402
|
end
|
403
403
|
end
|
404
404
|
|
405
|
+
should "count associations on the slave" do
|
406
|
+
AccountThing.on_slave_by_default = true
|
407
|
+
Account.on_slave.connection.execute("INSERT INTO account_things (id, account_id) VALUES(123123, 1000)")
|
408
|
+
Account.on_slave.connection.execute("INSERT INTO account_things (id, account_id) VALUES(123124, 1000)")
|
409
|
+
assert_equal 2, Account.find(1000).account_things.size
|
410
|
+
AccountThing.on_slave_by_default = false
|
411
|
+
end
|
412
|
+
|
405
413
|
should "Allow override using on_master" do
|
406
414
|
model = Account.on_master.find(1000)
|
407
415
|
assert_equal "master_name", model.name
|
data/test/models.rb
CHANGED
data/test/schema.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: active_record_shards
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.7.
|
4
|
+
version: 2.7.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -11,7 +11,7 @@ authors:
|
|
11
11
|
autorequire:
|
12
12
|
bindir: bin
|
13
13
|
cert_chain: []
|
14
|
-
date: 2013-03-
|
14
|
+
date: 2013-03-14 00:00:00.000000000 Z
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
17
17
|
name: activerecord
|