rails-sharding 1.1.0 → 1.1.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
- SHA1:
3
- metadata.gz: 9f4f44b9e47e25d00cce1cd88897d85750be2465
4
- data.tar.gz: c84a17b9c9a59fd471e627c0784450cba5930451
2
+ SHA256:
3
+ metadata.gz: 0a9130c4b0e150421dfa3655dcb44f5638cbca380851ec171cd1a85fa24752d8
4
+ data.tar.gz: 78086e09183f55c0e7fd6524447894d7b81d3e846bded97a10beeae3fb23cc0a
5
5
  SHA512:
6
- metadata.gz: 113d4ba656d6ff072c81a116141cc4b7057d914fa64f9ccf00f64e4a0a08b062e4fde0b388216143ef5c5ba378c564b90fb2615b7d765683901d9d335b7ca28a
7
- data.tar.gz: edda93d0db35871a3dd1b2cc0a95838112dfa928da60e925ae98f7d4467e298112907a6d3b800fc7267a9d0d41d8ee5a3d68d5433f629748e6dbad1b7dacf049
6
+ metadata.gz: cfdf3372608f63b68a500ec4522191d30d378fb35c1d386ef525c9f74f5281f64f7c694719b85b20d7359101d11aa69640b6d5b6e2c90ad07ff7e18f5935035f
7
+ data.tar.gz: 27af314dc9d9475801688ca28aae49ad5ed691d8dec71bc1a96f783ad1c72ec23565c094a404931610521de61f21846d33fb7fa37932e2c86d5a954b8c62f6c0
@@ -1 +1 @@
1
- ruby-2.4.1
1
+ ruby-2.5.7
@@ -1,7 +1,7 @@
1
1
  sudo: false
2
2
  language: ruby
3
3
  rvm:
4
- - 2.4.1
4
+ - 2.5.7
5
5
  services:
6
6
  - mysql
7
7
  - postgresql
data/README.md CHANGED
@@ -8,28 +8,34 @@
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. It also provides rake tasks and migrations to help you manage the schema by shard groups.
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
- After you have setup your shards, accessing them is as simple as:
13
+ Accessing shards is as simple as:
14
14
  ```ruby
15
+ # creating a user to a specific shard
15
16
  new_user = User.using_shard(:shard_group1, :shard1).create(username: 'x')
17
+
18
+ # retrieving a user from a specific shard
16
19
  loaded_user = User.using_shard(:shard_group1, :shard1).where(username: 'x').first
17
20
  ```
18
21
 
19
- You can also use the block syntax, where all your queries inside will be directed to the correct shard:
22
+ You can also use the block syntax:
20
23
  ```ruby
21
24
  Rails::Sharding.using_shard(:shard_group1, :shard1) do
25
+ # All statements inside this block will go to the selected shard
26
+
27
+ # Do some queries
22
28
  new_user = User.create(username: 'x')
23
29
  loaded_user = User.where(username: 'x').first
24
30
  billing_infos = loaded_user.billing_infos.all
25
31
  end
26
32
  ```
27
33
 
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.
34
+ You can also pick and choose which models will be shardable. Non shardable models will be retrieved from the master database, even if inside a `using_shard` block.
29
35
 
30
36
  ## Compatibility
31
37
  Gem version 1.x.x:
32
- * Rails 5.0
38
+ * Rails 5.0 and 5.1
33
39
  * Databases: MySQL, MariaDB, Postgres
34
40
 
35
41
  Gem version 0.x.x:
@@ -51,7 +57,6 @@ bundle
51
57
  ```
52
58
 
53
59
  ## Creating Shards
54
- This gem helps you create shards that are additional and completely separate from your master database. The master database is the one that is created and managed through rails, and is the default storage for all your models.
55
60
 
56
61
  To start with the rails-sharding gem, run the command
57
62
  ```
@@ -80,7 +85,9 @@ development:
80
85
  ...
81
86
  ```
82
87
 
83
- 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`). A shard group is simply a set of shards that should have the same schema.
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
+
90
+ **A shard group is a set of shards that should have the same schema.**
84
91
 
85
92
  When you're ready to create the shards run
86
93
  ```
@@ -88,7 +95,13 @@ rake shards:create
88
95
  ```
89
96
 
90
97
  ## Migrating Shards
91
- 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. For example, add the following migration to your `db/shards_migrations/shard_group1`:
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
+
100
+
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.
102
+
103
+
104
+ For example, add the following migration to your `db/shards_migrations/shard_group1`:
92
105
  ```ruby
93
106
  # 20160808000000_create_users.rb
94
107
  class CreateClients < ActiveRecord::Migration[5.0]
@@ -175,6 +188,9 @@ Rails::Sharding.setup do |config|
175
188
  end
176
189
  ```
177
190
 
191
+ ## Wiki
192
+ Want to know more? How to integrate with RSpec, Capistrano, etc? Take a look at our [wiki](https://github.com/hsgubert/rails-sharding/wiki).
193
+
178
194
  ## Development and Contributing
179
195
 
180
196
  After checking out the repo:
@@ -78,7 +78,7 @@ module Rails::Sharding
78
78
  end
79
79
 
80
80
  def self.with_connection(shard_group, shard_name, &block)
81
- connection_pool(shard_group, shard_name).with_connection do |connection|
81
+ connection_pool(shard_group, shard_name).with_connection do |connection|
82
82
  if connection && Config.add_shard_tag_to_query_logs
83
83
  connection_name = connection_name(shard_group, shard_name)
84
84
  add_shard_tag_to_connection_log(connection, connection_name)
@@ -1,5 +1,5 @@
1
1
  module Rails
2
2
  module Sharding
3
- VERSION = "1.1.0"
3
+ VERSION = "1.1.1"
4
4
  end
5
5
  end
@@ -281,10 +281,17 @@ shards_namespace = namespace :shards do
281
281
  should_reconnect = Rails::Sharding::ConnectionHandler.connection_pool(shard_group, shard).active_connection?
282
282
  Rails::Sharding::ConnectionHandler.establish_connection(shard_group, shard, 'test')
283
283
 
284
+ # saves the current RAILS_ENV (we must change it so the environment is set correcly on the metadata table)
285
+ initial_rails_env = Rails.env
286
+ Rails.env = 'test'
287
+
284
288
  Rails::Sharding.using_shard(shard_group, shard) do
285
289
  ActiveRecord::Tasks::DatabaseTasks.purge(configuration)
286
290
  end
287
291
  ensure
292
+ # restores rails env
293
+ Rails.env = initial_rails_env
294
+
288
295
  if should_reconnect
289
296
  # reestablishes connection for RAILS_ENV environment (whatever that is)
290
297
  Rails::Sharding::ConnectionHandler.establish_connection(shard_group, shard)
@@ -25,10 +25,10 @@ Gem::Specification.new do |spec|
25
25
 
26
26
  spec.add_runtime_dependency 'rails', '~> 5.1.0'
27
27
 
28
- spec.add_development_dependency "bundler", "~> 1.15"
29
- spec.add_development_dependency "rake", "~> 12.0"
28
+ spec.add_development_dependency "bundler", "~> 1.17"
29
+ spec.add_development_dependency "rake", "~> 13.0"
30
30
  spec.add_development_dependency "rspec", "~> 3.0"
31
- spec.add_development_dependency "byebug", '~> 9'
31
+ spec.add_development_dependency "byebug", '~> 11'
32
32
  spec.add_development_dependency "mysql2", '~> 0'
33
33
  spec.add_development_dependency "pg", '~> 0' # postgres driver
34
34
  spec.add_development_dependency "codeclimate-test-reporter", '~> 1'
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.1.0
4
+ version: 1.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Henrique Gubert
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-09-13 00:00:00.000000000 Z
11
+ date: 2019-11-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -30,28 +30,28 @@ dependencies:
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '1.15'
33
+ version: '1.17'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: '1.15'
40
+ version: '1.17'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: rake
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: '12.0'
47
+ version: '13.0'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: '12.0'
54
+ version: '13.0'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: rspec
57
57
  requirement: !ruby/object:Gem::Requirement
@@ -72,14 +72,14 @@ dependencies:
72
72
  requirements:
73
73
  - - "~>"
74
74
  - !ruby/object:Gem::Version
75
- version: '9'
75
+ version: '11'
76
76
  type: :development
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
80
  - - "~>"
81
81
  - !ruby/object:Gem::Version
82
- version: '9'
82
+ version: '11'
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: mysql2
85
85
  requirement: !ruby/object:Gem::Requirement
@@ -193,8 +193,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
193
193
  - !ruby/object:Gem::Version
194
194
  version: '0'
195
195
  requirements: []
196
- rubyforge_project:
197
- rubygems_version: 2.6.11
196
+ rubygems_version: 3.0.6
198
197
  signing_key:
199
198
  specification_version: 4
200
199
  summary: Simple and robust sharding for Rails, including Migrations and ActiveRecord