rails-sharding 1.2.1 → 1.2.2

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
2
  SHA256:
3
- metadata.gz: b567029d770be424e7c1141bd5f483fd5fee49a630ee31248d66af9d57976ab9
4
- data.tar.gz: 0aa3dd59efebe3aba5949784fcd342d3595dbe719057db9a68341480d3dae9bd
3
+ metadata.gz: 6b542040ae9301ac69b9ce91bd32321c41b25638257a76499171a8e2cc0f56c3
4
+ data.tar.gz: 01a21bafcf195bb8e63943f99a8044a905b10999d1800a98d2260b7e126e1d4f
5
5
  SHA512:
6
- metadata.gz: 88089653b9b9c99acb012872175d426d5b60aad54b7e65a2d98afb6b128c7b7a1e904cdc62d06db1d68bd4c3d2589d1ed5cc7e6537d9ced97bc2f9e0044ba35b
7
- data.tar.gz: 338d7f533b28c46625a0102cc861932a8819bde1084a02b37cf8a7ae1593b948bd35aefc6b0c5355967399453a70232f28bb465aaefdb86aaf2fe965c1d3b4c1
6
+ metadata.gz: 634c7ab62a151f7b07cb5f3faae84eec62b3a488dd7bd29c406effc8ac42085ef1470bc38c2fbeceec1cad8d42d50eb20269b0bbfa28d03c35855de5263286c6
7
+ data.tar.gz: ec85fb6f79150cfd31dea3a6767be50046c447bb908e9366fa6ba7484acd0004d50f40bac839449e2f6d72b5f2b5596fa3bb7b2b6c9752b2d20b1c7fbfbd7df5
data/.env.example ADDED
@@ -0,0 +1,4 @@
1
+ MYSQL_USERNAME=____
2
+ MYSQL_PASSWORD=____
3
+ POSTGRES_USERNAME=____
4
+ POSTGRES_PASSWORD=____
data/.gitignore CHANGED
@@ -11,3 +11,4 @@
11
11
  /tmp/
12
12
  .byebug_history
13
13
  rails-sharding-*.*.*.gem
14
+ .env
data/README.md CHANGED
@@ -11,6 +11,7 @@ Simple and robust sharding gem for Rails, including Migrations and ActiveRecord
11
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
15
  ```ruby
15
16
  # creating a user to a specific shard
16
17
  new_user = User.using_shard(:shard_group1, :shard1).create(username: 'x')
@@ -20,6 +21,7 @@ Accessing shards is as simple as:
20
21
  ```
21
22
 
22
23
  You can also use the block syntax:
24
+
23
25
  ```ruby
24
26
  Rails::Sharding.using_shard(:shard_group1, :shard1) do
25
27
  # All statements inside this block will go to the selected shard
@@ -34,14 +36,16 @@ You can also use the block syntax:
34
36
  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.
35
37
 
36
38
  ## Compatibility
39
+
37
40
  Gem version 1.x.x:
38
- * Rails 5.0, 5.1 and 5.2
39
- * Databases: MySQL, MariaDB, Postgres
41
+
42
+ - Rails 5.0, 5.1 and 5.2
43
+ - Databases: MySQL, MariaDB, Postgres
40
44
 
41
45
  Gem version 0.x.x:
42
- * Rails 4.2
43
- * Databases: MySQL, MariaDB
44
46
 
47
+ - Rails 4.2
48
+ - Databases: MySQL, MariaDB
45
49
 
46
50
  ## Installation
47
51
 
@@ -52,6 +56,7 @@ gem 'rails-sharding'
52
56
  ```
53
57
 
54
58
  And then execute:
59
+
55
60
  ```
56
61
  bundle
57
62
  ```
@@ -59,19 +64,21 @@ bundle
59
64
  ## Creating Shards
60
65
 
61
66
  To start with the rails-sharding gem, run the command
67
+
62
68
  ```
63
69
  rails g rails_sharding:scaffold
64
70
  ```
65
71
 
66
72
  This will generate a `config/shards.yml.example` like this:
73
+
67
74
  ```ruby
68
75
  default: &default
69
76
  adapter: mysql2
70
77
  encoding: utf8
71
78
  reconnect: false
72
79
  pool: 5
73
- username: ___
74
- password: ___
80
+ username: <%= ENV["MYSQL_USERNAME"] %>
81
+ password: <%= ENV["MYSQL_PASSWORD"] %>
75
82
  socket: /var/run/mysqld/mysqld.sock
76
83
 
77
84
  development:
@@ -90,18 +97,19 @@ Rename it to `config/shards.yml` and change it to your database configuration. T
90
97
  **A shard group is a set of shards that should have the same schema.**
91
98
 
92
99
  When you're ready to create the shards run
100
+
93
101
  ```
94
102
  rake shards:create
95
103
  ```
96
104
 
97
105
  ## 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.
99
106
 
107
+ 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.
100
108
 
101
109
  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
110
 
103
-
104
111
  For example, add the following migration to your `db/shards_migrations/shard_group1`:
112
+
105
113
  ```ruby
106
114
  # 20160808000000_create_users.rb
107
115
  class CreateClients < ActiveRecord::Migration[5.0]
@@ -119,11 +127,13 @@ end
119
127
  ```
120
128
 
121
129
  Then run:
130
+
122
131
  ```
123
132
  rake shards:migrate
124
133
  ```
125
134
 
126
135
  All the shards will be migrated, and one schema file will be dumped for each of the shards (just like rails would do for your master database). You can see the schema of the shards in `db/shards_schemas/shard_group1/`, and it will be something like:
136
+
127
137
  ```ruby
128
138
  ActiveRecord::Schema.define(version: 20160808000000) do
129
139
 
@@ -137,32 +147,37 @@ end
137
147
  ```
138
148
 
139
149
  ## Other rake tasks
150
+
140
151
  The rails-sharding gem offers several rake tasks analogous to the ones offered by ActiveRecord:
152
+
141
153
  ```
142
- rake shards:create
143
- rake shards:drop
144
- rake shards:migrate
145
- rake shards:migrate:down
146
- rake shards:migrate:redo
147
- rake shards:migrate:reset
148
- rake shards:migrate:up
149
- rake shards:rollback
150
- rake shards:schema:dump
151
- rake shards:schema:load
152
- rake shards:test:load_schema
153
- rake shards:test:prepare
154
- rake shards:test:purge
154
+ rake shards:create
155
+ rake shards:drop
156
+ rake shards:migrate
157
+ rake shards:migrate:down
158
+ rake shards:migrate:redo
159
+ rake shards:migrate:reset
160
+ rake shards:migrate:up
161
+ rake shards:rollback
162
+ rake shards:schema:dump
163
+ rake shards:schema:load
164
+ rake shards:test:load_schema
165
+ rake shards:test:prepare
166
+ rake shards:test:purge
155
167
  rake shards:version
156
168
  ```
157
169
 
158
170
  They work just the same as the tasks `rake:db:...` but they operate on all shards of all shard groups. If you want to run a rake task just to a specific shard group or shard you can use the `SHARD_GROUP` and `SHARD` options:
171
+
159
172
  ```
160
173
  rake shards:migrate SHARD_GROUP=shard_group_1
161
174
  rake shards:migrate SHARD_GROUP=shard_group_1 SHARD=shard1
162
175
  ```
163
176
 
164
177
  ## Gem Options
178
+
165
179
  Running the `rails g rails_sharding:scaffold` will create an initializer at `config/initializers/rails-sharding.rb`. You can pass additional configurations on this initializer to control the gem behavior. You can see below all available options and their default values:
180
+
166
181
  ```ruby
167
182
  # config/initializers/rails-sharding.rb
168
183
 
@@ -189,6 +204,7 @@ end
189
204
  ```
190
205
 
191
206
  ## Wiki
207
+
192
208
  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
209
 
194
210
  ## Development and Contributing
@@ -199,13 +215,14 @@ After checking out the repo:
199
215
 
200
216
  1. Create your `spec/fixtures/shards.yml` based on the example on this same folder (you need MySQL and Postgres)
201
217
 
218
+ 1. Create your `.env` based on the example on this same folder.
219
+
202
220
  1. Run `rake db:test:prepare` to create the test shards.
203
221
 
204
222
  1. Run `rspec` to run the tests.
205
223
 
206
224
  Bug reports and pull requests are welcome on GitHub at https://github.com/hsgubert/rails-sharding.
207
225
 
208
-
209
226
  ## License
210
227
 
211
228
  The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
@@ -8,11 +8,9 @@ require 'rails/sharding/railtie' if defined?(Rails::Railtie)
8
8
 
9
9
  module Rails
10
10
  module Sharding
11
-
12
11
  # delegates all methods to Core, to shorten method calls
13
12
  def self.method_missing(method_sym, *arguments, &block)
14
13
  Core.send(method_sym, *arguments, &block)
15
14
  end
16
-
17
15
  end
18
16
  end
@@ -29,7 +29,7 @@ module Rails::Sharding
29
29
  end
30
30
 
31
31
  def self.configurations(environment=Rails.env)
32
- @@db_configs ||= YAML.load_file(Config.shards_config_file)
32
+ @@db_configs ||= YAML.load(ERB.new(File.read(Config.shards_config_file)).result)
33
33
  environment_config = @@db_configs[environment]
34
34
  return environment_config if environment_config
35
35
 
@@ -1,3 +1,4 @@
1
+ require 'active_support/core_ext/module'
1
2
 
2
3
  module Rails::Sharding
3
4
  class ShardThreadRegistry
@@ -1,5 +1,5 @@
1
1
  module Rails
2
2
  module Sharding
3
- VERSION = "1.2.1"
3
+ VERSION = "1.2.2"
4
4
  end
5
5
  end
@@ -1,36 +1,35 @@
1
- # coding: utf-8
2
- lib = File.expand_path('../lib', __FILE__)
1
+ lib = File.expand_path('lib', __dir__)
3
2
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
3
  require 'rails/sharding/version'
5
4
 
6
5
  Gem::Specification.new do |spec|
7
- spec.name = "rails-sharding"
6
+ spec.name = 'rails-sharding'
8
7
  spec.version = Rails::Sharding::VERSION
9
- spec.authors = ["Henrique Gubert"]
10
- spec.email = ["guberthenrique@hotmail.com"]
8
+ spec.authors = ['Henrique Gubert']
9
+ spec.email = ['guberthenrique@hotmail.com']
11
10
 
12
- spec.summary = %q{Simple and robust sharding for Rails, including
13
- Migrations and ActiveRecord extensions}
14
- spec.description = %q{This gems allows you to easily create extra databases
11
+ spec.summary = 'Simple and robust sharding for Rails, including
12
+ Migrations and ActiveRecord extensions'
13
+ spec.description = 'This gems allows you to easily create extra databases
15
14
  to your rails application, and freely allocate ActiveRecord instances to
16
15
  any of the databases. It also provides rake tasks and migrations to help
17
- you manage the schema by shard groups.}
18
- spec.homepage = "https://github.com/hsgubert/rails-sharding"
19
- spec.license = "MIT"
16
+ you manage the schema by shard groups.'
17
+ spec.homepage = 'https://github.com/hsgubert/rails-sharding'
18
+ spec.license = 'MIT'
20
19
 
21
20
  spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
22
- spec.bindir = "exe"
21
+ spec.bindir = 'exe'
23
22
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
24
- spec.require_paths = ["lib"]
23
+ spec.require_paths = ['lib']
25
24
 
26
25
  spec.add_runtime_dependency 'rails', '~> 5.2.0'
27
26
 
28
- spec.add_development_dependency "bundler", "~> 1.17"
29
- spec.add_development_dependency "rake", "~> 13.0"
30
- spec.add_development_dependency "rspec", "~> 3.0"
31
- spec.add_development_dependency "byebug", '~> 11'
32
- spec.add_development_dependency "mysql2", '~> 0'
33
- spec.add_development_dependency "pg", '~> 0' # postgres driver
34
- spec.add_development_dependency "codeclimate-test-reporter", '~> 1'
35
- spec.add_development_dependency "simplecov", '~> 0'
27
+ spec.add_development_dependency 'bundler', '~> 1.17'
28
+ spec.add_development_dependency 'byebug', '~> 11'
29
+ spec.add_development_dependency 'codeclimate-test-reporter', '~> 1'
30
+ spec.add_development_dependency 'mysql2', '~> 0'
31
+ spec.add_development_dependency 'pg', '~> 0' # postgres driver
32
+ spec.add_development_dependency 'rake', '~> 13.0'
33
+ spec.add_development_dependency 'rspec', '~> 3.0'
34
+ spec.add_development_dependency 'simplecov', '~> 0'
36
35
  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.2.1
4
+ version: 1.2.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: 2020-06-10 00:00:00.000000000 Z
11
+ date: 2021-07-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -39,49 +39,49 @@ dependencies:
39
39
  - !ruby/object:Gem::Version
40
40
  version: '1.17'
41
41
  - !ruby/object:Gem::Dependency
42
- name: rake
42
+ name: byebug
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: '13.0'
47
+ version: '11'
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: '13.0'
54
+ version: '11'
55
55
  - !ruby/object:Gem::Dependency
56
- name: rspec
56
+ name: codeclimate-test-reporter
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
59
  - - "~>"
60
60
  - !ruby/object:Gem::Version
61
- version: '3.0'
61
+ version: '1'
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
- version: '3.0'
68
+ version: '1'
69
69
  - !ruby/object:Gem::Dependency
70
- name: byebug
70
+ name: mysql2
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
73
  - - "~>"
74
74
  - !ruby/object:Gem::Version
75
- version: '11'
75
+ version: '0'
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: '11'
82
+ version: '0'
83
83
  - !ruby/object:Gem::Dependency
84
- name: mysql2
84
+ name: pg
85
85
  requirement: !ruby/object:Gem::Requirement
86
86
  requirements:
87
87
  - - "~>"
@@ -95,33 +95,33 @@ dependencies:
95
95
  - !ruby/object:Gem::Version
96
96
  version: '0'
97
97
  - !ruby/object:Gem::Dependency
98
- name: pg
98
+ name: rake
99
99
  requirement: !ruby/object:Gem::Requirement
100
100
  requirements:
101
101
  - - "~>"
102
102
  - !ruby/object:Gem::Version
103
- version: '0'
103
+ version: '13.0'
104
104
  type: :development
105
105
  prerelease: false
106
106
  version_requirements: !ruby/object:Gem::Requirement
107
107
  requirements:
108
108
  - - "~>"
109
109
  - !ruby/object:Gem::Version
110
- version: '0'
110
+ version: '13.0'
111
111
  - !ruby/object:Gem::Dependency
112
- name: codeclimate-test-reporter
112
+ name: rspec
113
113
  requirement: !ruby/object:Gem::Requirement
114
114
  requirements:
115
115
  - - "~>"
116
116
  - !ruby/object:Gem::Version
117
- version: '1'
117
+ version: '3.0'
118
118
  type: :development
119
119
  prerelease: false
120
120
  version_requirements: !ruby/object:Gem::Requirement
121
121
  requirements:
122
122
  - - "~>"
123
123
  - !ruby/object:Gem::Version
124
- version: '1'
124
+ version: '3.0'
125
125
  - !ruby/object:Gem::Dependency
126
126
  name: simplecov
127
127
  requirement: !ruby/object:Gem::Requirement
@@ -148,6 +148,7 @@ extensions: []
148
148
  extra_rdoc_files: []
149
149
  files:
150
150
  - ".codeclimate.yml"
151
+ - ".env.example"
151
152
  - ".gitignore"
152
153
  - ".rspec"
153
154
  - ".ruby-gemset"
@@ -193,7 +194,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
193
194
  - !ruby/object:Gem::Version
194
195
  version: '0'
195
196
  requirements: []
196
- rubygems_version: 3.0.6
197
+ rubygems_version: 3.0.3
197
198
  signing_key:
198
199
  specification_version: 4
199
200
  summary: Simple and robust sharding for Rails, including Migrations and ActiveRecord