rails-sharding 1.0.1 → 1.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +1 -0
- data/README.md +21 -6
- data/lib/rails/sharding/config.rb +1 -1
- data/lib/rails/sharding/connection_handler.rb +5 -8
- data/lib/rails/sharding/version.rb +1 -1
- data/lib/tasks/rails-sharding.rake +8 -0
- data/rails-sharding.gemspec +3 -1
- metadata +32 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 69312525d71ec25b0fa2776aba790c0a0d5e415d
|
4
|
+
data.tar.gz: b3525a64662f70f979fc240068f59c32b7a4e8dc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a6082f3cbebd5f0d3929377e0c0ef8b9420883be249ab1e5b82291b90a3e6212711c85332aae1f0e6b310e8cc60da768aee66d499caa1db1d902e0c54ae95858
|
7
|
+
data.tar.gz: c458509a03e3f32e0dc3f3e213056629d708e236474525726dbd22ee7fa5cad58a304ebc7e6dc59c68d26b7787141913709f002cfb2035fa298296dca7ba2bee
|
data/.travis.yml
CHANGED
data/README.md
CHANGED
@@ -28,9 +28,13 @@ You can also use the block syntax, where all your queries inside will be directe
|
|
28
28
|
You can also pick and choose which models will be shardable, so that all the models that are not shardable will still be retrieved from the master database, even if inside a using_shard block.
|
29
29
|
|
30
30
|
## Compatibility
|
31
|
-
Gem version 1.x.x
|
31
|
+
Gem version 1.x.x:
|
32
|
+
* Rails 5.0
|
33
|
+
* Databases: MySQL, MariaDB, Postgres
|
32
34
|
|
33
|
-
Gem version 0.
|
35
|
+
Gem version 0.x.x:
|
36
|
+
* Rails 4.2
|
37
|
+
* Databases: MySQL, MariaDB
|
34
38
|
|
35
39
|
|
36
40
|
## Installation
|
@@ -155,13 +159,16 @@ Rails::Sharding.setup do |config|
|
|
155
159
|
config.establish_all_connections_on_setup = true
|
156
160
|
|
157
161
|
# If true the method #using_shard will be mixed in ActiveRecord scopes. Put this to false if you don't want the gem to modify ActiveRecord
|
158
|
-
config.extend_active_record_scope = true
|
162
|
+
config.extend_active_record_scope = true
|
163
|
+
|
164
|
+
# If true the query logs of ActiveRecord will be tagged with the corresponding shard you're querying
|
165
|
+
config.add_shard_tag_to_query_logs = true
|
159
166
|
|
160
167
|
# Specifies where to find the definition of the shards configurations
|
161
|
-
config.shards_config_file = 'config/shards.yml'
|
168
|
+
config.shards_config_file = 'config/shards.yml'
|
162
169
|
|
163
170
|
# Specifies where to find the migrations for each shard group
|
164
|
-
config.shards_migrations_dir = 'db/shards_migrations'
|
171
|
+
config.shards_migrations_dir = 'db/shards_migrations'
|
165
172
|
|
166
173
|
# Specifies where to find the schemas for each shard group
|
167
174
|
config.shards_schemas_dir = 'db/shards_schemas'
|
@@ -170,7 +177,15 @@ end
|
|
170
177
|
|
171
178
|
## Development and Contributing
|
172
179
|
|
173
|
-
After checking out the repo
|
180
|
+
After checking out the repo:
|
181
|
+
|
182
|
+
1. Run `bundle` to install gems
|
183
|
+
|
184
|
+
1. Create your `spec/fixtures/shards.yml` based on the example on this same folder (you need MySQL and Postgres)
|
185
|
+
|
186
|
+
1. Run `rake db:test:prepare` to create the test shards.
|
187
|
+
|
188
|
+
1. Run `rspec` to run the tests.
|
174
189
|
|
175
190
|
Bug reports and pull requests are welcome on GitHub at https://github.com/hsgubert/rails-sharding.
|
176
191
|
|
@@ -18,9 +18,6 @@ module Rails::Sharding
|
|
18
18
|
self.setup unless defined? @@connection_handler
|
19
19
|
|
20
20
|
configurations = (environment.nil? ? Core.configurations : Core.configurations(environment))
|
21
|
-
if configurations.nil?
|
22
|
-
raise Errors::ConfigNotFoundError, "Cannot find configuration for environment '#{environment}' in #{Config.shards_config_file}"
|
23
|
-
end
|
24
21
|
|
25
22
|
shard_group_configurations = configurations[shard_group.to_s]
|
26
23
|
if shard_group_configurations.nil?
|
@@ -105,14 +102,14 @@ module Rails::Sharding
|
|
105
102
|
connection.singleton_class.send(:attr_accessor, :shard_tag)
|
106
103
|
connection.shard_tag = shard_tag
|
107
104
|
|
108
|
-
# create an alias #
|
109
|
-
connection.singleton_class.send(:alias_method, :
|
105
|
+
# create an alias #original_log, as a copy of the #log for this connection
|
106
|
+
connection.singleton_class.send(:alias_method, :original_log, :log)
|
110
107
|
|
111
|
-
# defines a new #
|
108
|
+
# defines a new #log that adds a tag to the log
|
112
109
|
class << connection
|
113
|
-
def
|
110
|
+
def log(sql, name="SQL", binds=[], statement_name=nil, &block)
|
114
111
|
name = (name.to_s + " (#{shard_tag})").strip
|
115
|
-
self.
|
112
|
+
self.original_log(sql, name, binds, statement_name, &block)
|
116
113
|
end
|
117
114
|
end
|
118
115
|
|
@@ -37,7 +37,15 @@ shards_namespace = namespace :shards do
|
|
37
37
|
task drop: [:environment, :check_protected_environments] do
|
38
38
|
Rails::Sharding.for_each_shard(ENV["SHARD_GROUP"], ENV["SHARD"]) do |shard_group, shard, configuration|
|
39
39
|
puts "== Dropping shard #{shard_group}:#{shard}"
|
40
|
+
|
41
|
+
# closes connections with shard before dropping (postgres requires this, mysql does not but there is no harm)
|
42
|
+
Rails::Sharding::ConnectionHandler.remove_connection(shard_group, shard)
|
43
|
+
|
40
44
|
ActiveRecord::Tasks::DatabaseTasks.drop(configuration)
|
45
|
+
|
46
|
+
# reestablishes connection (because we removed before). You can do this even if the database does not exist yet,
|
47
|
+
# you just cannot retrieve the connection yet.
|
48
|
+
Rails::Sharding::ConnectionHandler.establish_connection(shard_group, shard)
|
41
49
|
end
|
42
50
|
end
|
43
51
|
|
data/rails-sharding.gemspec
CHANGED
@@ -30,5 +30,7 @@ Gem::Specification.new do |spec|
|
|
30
30
|
spec.add_development_dependency "rspec", "~> 3.0"
|
31
31
|
spec.add_development_dependency "byebug", '~> 9'
|
32
32
|
spec.add_development_dependency "mysql2", '~> 0'
|
33
|
-
spec.add_development_dependency "
|
33
|
+
spec.add_development_dependency "pg" # postgres driver
|
34
|
+
spec.add_development_dependency "codeclimate-test-reporter", '~> 1'
|
35
|
+
spec.add_development_dependency "simplecov"
|
34
36
|
end
|
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.0.
|
4
|
+
version: 1.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Henrique Gubert
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-11-
|
11
|
+
date: 2016-11-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -94,18 +94,46 @@ dependencies:
|
|
94
94
|
- - "~>"
|
95
95
|
- !ruby/object:Gem::Version
|
96
96
|
version: '0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: pg
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
97
111
|
- !ruby/object:Gem::Dependency
|
98
112
|
name: codeclimate-test-reporter
|
99
113
|
requirement: !ruby/object:Gem::Requirement
|
100
114
|
requirements:
|
101
115
|
- - "~>"
|
102
116
|
- !ruby/object:Gem::Version
|
103
|
-
version: '
|
117
|
+
version: '1'
|
104
118
|
type: :development
|
105
119
|
prerelease: false
|
106
120
|
version_requirements: !ruby/object:Gem::Requirement
|
107
121
|
requirements:
|
108
122
|
- - "~>"
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '1'
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: simplecov
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - ">="
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: '0'
|
132
|
+
type: :development
|
133
|
+
prerelease: false
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - ">="
|
109
137
|
- !ruby/object:Gem::Version
|
110
138
|
version: '0'
|
111
139
|
description: |-
|
@@ -166,7 +194,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
166
194
|
version: '0'
|
167
195
|
requirements: []
|
168
196
|
rubyforge_project:
|
169
|
-
rubygems_version: 2.
|
197
|
+
rubygems_version: 2.6.8
|
170
198
|
signing_key:
|
171
199
|
specification_version: 4
|
172
200
|
summary: Simple and robust sharding for Rails, including Migrations and ActiveRecord
|