rails-sharding 1.1.3 → 1.2.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 +4 -4
- data/README.md +8 -8
- data/lib/rails/sharding/active_record_extensions.rb +1 -1
- data/lib/rails/sharding/shardable_model.rb +10 -1
- data/lib/rails/sharding/version.rb +1 -1
- data/rails-sharding.gemspec +1 -1
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: '06952a8d4b285bc681adc59a8653eddc1222432d5b62cd4d97462fab6ff63770'
|
4
|
+
data.tar.gz: a3d9cf13268beaeda50dbb44961afce736ba5df0793ef0aafe20ba37fe2ab155
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 569ea9f4ae0fe748b696fa10aa1af66b2dca6b82231eeb523187f424ecbeec20d21783e8f200076672bf0389f46966bb55f6be3be4ae270071e532bb91f7e2a7
|
7
|
+
data.tar.gz: bd63818ba25d2d836c116aca83f1b2267a6288f76bce34d0ff93cdcae055e13bf7d20e51eee1d0c87005df6e187cf00da5a6d0bdefa1a761abfbfa9bede1f0e9
|
data/README.md
CHANGED
@@ -8,13 +8,13 @@
|
|
8
8
|
|
9
9
|
Simple and robust sharding gem for Rails, including Migrations and ActiveRecord extensions
|
10
10
|
|
11
|
-
This gems allows you to easily create extra databases to your rails application, and freely allocate ActiveRecord instances to any of the databases.
|
11
|
+
This gems allows you to easily create extra databases to your rails application, and freely allocate ActiveRecord instances to any of the databases.
|
12
12
|
|
13
13
|
Accessing shards is as simple as:
|
14
14
|
```ruby
|
15
15
|
# creating a user to a specific shard
|
16
16
|
new_user = User.using_shard(:shard_group1, :shard1).create(username: 'x')
|
17
|
-
|
17
|
+
|
18
18
|
# retrieving a user from a specific shard
|
19
19
|
loaded_user = User.using_shard(:shard_group1, :shard1).where(username: 'x').first
|
20
20
|
```
|
@@ -23,7 +23,7 @@ You can also use the block syntax:
|
|
23
23
|
```ruby
|
24
24
|
Rails::Sharding.using_shard(:shard_group1, :shard1) do
|
25
25
|
# All statements inside this block will go to the selected shard
|
26
|
-
|
26
|
+
|
27
27
|
# Do some queries
|
28
28
|
new_user = User.create(username: 'x')
|
29
29
|
loaded_user = User.where(username: 'x').first
|
@@ -35,7 +35,7 @@ You can also pick and choose which models will be shardable. Non shardable model
|
|
35
35
|
|
36
36
|
## Compatibility
|
37
37
|
Gem version 1.x.x:
|
38
|
-
* Rails 5.0 and 5.
|
38
|
+
* Rails 5.0, 5.1 and 5.2
|
39
39
|
* Databases: MySQL, MariaDB, Postgres
|
40
40
|
|
41
41
|
Gem version 0.x.x:
|
@@ -85,7 +85,7 @@ development:
|
|
85
85
|
...
|
86
86
|
```
|
87
87
|
|
88
|
-
Rename it to `config/shards.yml` and change it to your database configuration. This example file defines a single shard group (named `shard_group1`) containing two shards (`shard1` and `shard2`).
|
88
|
+
Rename it to `config/shards.yml` and change it to your database configuration. This example file defines a single shard group (named `shard_group1`) containing two shards (`shard1` and `shard2`).
|
89
89
|
|
90
90
|
**A shard group is a set of shards that should have the same schema.**
|
91
91
|
|
@@ -95,7 +95,7 @@ rake shards:create
|
|
95
95
|
```
|
96
96
|
|
97
97
|
## Migrating Shards
|
98
|
-
Go to the directory `db/shards_migrations/shard_group1` and add all migrations that you want to run on the shards of `shard_group1`. By design, all shards in a same group should always have the same schema.
|
98
|
+
Go to the directory `db/shards_migrations/shard_group1` and add all migrations that you want to run on the shards of `shard_group1`. By design, all shards in a same group should always have the same schema.
|
99
99
|
|
100
100
|
|
101
101
|
As of now, there is no generator for migrations. You can use the regular rails generator and move the migrations to the `shards_migration` folder.
|
@@ -195,11 +195,11 @@ Want to know more? How to integrate with RSpec, Capistrano, etc? Take a look at
|
|
195
195
|
|
196
196
|
After checking out the repo:
|
197
197
|
|
198
|
-
1. Run `bundle` to install gems
|
198
|
+
1. Run `bundle` to install gems
|
199
199
|
|
200
200
|
1. Create your `spec/fixtures/shards.yml` based on the example on this same folder (you need MySQL and Postgres)
|
201
201
|
|
202
|
-
1. Run `rake db:test:prepare` to create the test shards.
|
202
|
+
1. Run `rake db:test:prepare` to create the test shards.
|
203
203
|
|
204
204
|
1. Run `rspec` to run the tests.
|
205
205
|
|
@@ -78,7 +78,7 @@ module Rails::Sharding
|
|
78
78
|
alias_method :eql?, :==
|
79
79
|
end
|
80
80
|
|
81
|
-
# Fixes case
|
81
|
+
# Fixes case-when behavior when ScopeProxy is passed to case
|
82
82
|
# (otherwise classes don't match)
|
83
83
|
module CaseFixer
|
84
84
|
def ===(other)
|
@@ -52,7 +52,7 @@ module Rails::Sharding
|
|
52
52
|
end
|
53
53
|
end
|
54
54
|
|
55
|
-
# @overrides ActiveRecord::ConnectionHandling#
|
55
|
+
# @overrides ActiveRecord::ConnectionHandling#connected?
|
56
56
|
def sharded_connected?
|
57
57
|
if ShardThreadRegistry.connecting_to_master?
|
58
58
|
return original_connected?
|
@@ -107,6 +107,15 @@ module Rails::Sharding
|
|
107
107
|
return ConnectionHandler.connection_handler.clear_all_connections!
|
108
108
|
end
|
109
109
|
end
|
110
|
+
|
111
|
+
# @overrides ActiveRecord::ConnectionHandling#flush_idle_connections!
|
112
|
+
def sharded_flush_idle_connections!
|
113
|
+
if ShardThreadRegistry.connecting_to_master?
|
114
|
+
return original_flush_idle_connections!
|
115
|
+
else
|
116
|
+
return ConnectionHandler.connection_handler.flush_idle_connections!
|
117
|
+
end
|
118
|
+
end
|
110
119
|
end
|
111
120
|
|
112
121
|
end
|
data/rails-sharding.gemspec
CHANGED
@@ -23,7 +23,7 @@ Gem::Specification.new do |spec|
|
|
23
23
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
24
24
|
spec.require_paths = ["lib"]
|
25
25
|
|
26
|
-
spec.add_runtime_dependency 'rails', '~> 5.
|
26
|
+
spec.add_runtime_dependency 'rails', '~> 5.2.0'
|
27
27
|
|
28
28
|
spec.add_development_dependency "bundler", "~> 1.17"
|
29
29
|
spec.add_development_dependency "rake", "~> 13.0"
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rails-sharding
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Henrique Gubert
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-04-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: 5.
|
19
|
+
version: 5.2.0
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: 5.
|
26
|
+
version: 5.2.0
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: bundler
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|