rails-sharding 0.1.0 → 0.1.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a47a8619575fe9128b549698d4afd396c0e66264
4
- data.tar.gz: 62d25bc10fbfacfe86ca63a64fc715f65ec7f550
3
+ metadata.gz: 05fd12669243e14c2d6f1b1748acf461b8316dbb
4
+ data.tar.gz: d1508fddee17b0a5c7eb0203b8dd1c9b52b74c66
5
5
  SHA512:
6
- metadata.gz: 6f7ba9c5adb59586c7c706d4d97ac3ac0eb95d6c449bd439787a6d4baa4f406c9eee338fdcb7926402f8451252b20d49dafa5371e08fa319eb170ee9d273cd8a
7
- data.tar.gz: c9296adfc294e4395f1430e21e3cca83db9ba7de374c04e2da3ec48846fa5664249adb247410676774566847838a210b1ae950b2dd01adf99642336121af0315
6
+ metadata.gz: 5ea75e62463c090f6806baedfd648768007c192d4e3a9e162c162083eb015cacb8eb6dfbc8ed0ce739bb9cc17c9a3889abc6b0bd02bb24f3f76470478996e85c
7
+ data.tar.gz: 524dfe1e8c7ea123209746accfdb726ea0a6011f43c460cbcf2cff3c11531b2ee7afa99c26091d54ad8792dd05dca62aff2badaee5290babb1f72631ed0e94d0
data/.gitignore CHANGED
@@ -10,3 +10,4 @@
10
10
  /spec/fixtures/schemas
11
11
  /tmp/
12
12
  .byebug_history
13
+ rails-sharding-*.*.*.gem
data/README.md CHANGED
@@ -2,7 +2,8 @@
2
2
 
3
3
  [![Build Status](https://travis-ci.org/hsgubert/rails-sharding.svg?branch=master)](https://travis-ci.org/hsgubert/rails-sharding)
4
4
  [![Code Climate](https://codeclimate.com/github/hsgubert/rails-sharding/badges/gpa.svg)](https://codeclimate.com/github/hsgubert/rails-sharding)
5
-
5
+ [![Test Coverage](https://codeclimate.com/github/hsgubert/rails-sharding/badges/coverage.svg)](https://codeclimate.com/github/hsgubert/rails-sharding/coverage)
6
+ [![Gem Version](https://badge.fury.io/rb/rails-sharding.svg)](https://badge.fury.io/rb/rails-sharding)
6
7
 
7
8
  Simple and robust sharding for Rails, including Migrations and ActiveRecord extensions
8
9
 
@@ -1,5 +1,5 @@
1
1
  module Rails
2
2
  module Sharding
3
- VERSION = "0.1.0"
3
+ VERSION = "0.1.1"
4
4
  end
5
5
  end
@@ -81,15 +81,11 @@ shards_namespace = namespace :shards do
81
81
  Rails::Sharding.configurations.each do |shard_group, shards_configurations|
82
82
  next if ENV["SHARD_GROUP"] && ENV["SHARD_GROUP"] != shard_group.to_s
83
83
 
84
- # configures path for schemas of this shard group and creates dir if necessary
85
- shard_group_schemas_dir = File.join(Rails::Sharding::Config.shards_schemas_dir, shard_group.to_s)
86
- FileUtils.mkdir_p(shard_group_schemas_dir)
87
-
88
84
  shards_configurations.each do |shard, configuration|
89
85
  next if ENV["SHARD"] && ENV["SHARD"] != shard.to_s
90
86
  puts "== Dumping schema of #{shard_group}:#{shard}"
91
87
 
92
- schema_filename = File.join(shard_group_schemas_dir, shard + "_schema.rb")
88
+ schema_filename = shard_schema_path(shard_group, shard)
93
89
  File.open(schema_filename, "w:utf-8") do |file|
94
90
  Rails::Sharding.using_shard(shard_group, shard) do
95
91
  ActiveRecord::SchemaDumper.dump(Rails::Sharding::ConnectionHandler.retrieve_connection(shard_group, shard), file)
@@ -108,16 +104,13 @@ shards_namespace = namespace :shards do
108
104
  Rails::Sharding.configurations.each do |shard_group, shards_configurations|
109
105
  next if ENV["SHARD_GROUP"] && ENV["SHARD_GROUP"] != shard_group.to_s
110
106
 
111
- # configures path for schemas of this shard group
112
- shard_group_schemas_path = 'db/shards_schemas/' + shard_group.to_s
113
- Rails.application.paths.add shard_group_schemas_path
114
- shard_group_schemas_dir = Rails.application.paths[shard_group_schemas_path].to_a.first
107
+ setup_migrations_path(shard_group)
115
108
 
116
109
  shards_configurations.each do |shard, configuration|
117
110
  next if ENV["SHARD"] && ENV["SHARD"] != shard.to_s
118
111
  puts "== Loading schema of #{shard_group}:#{shard}"
119
112
 
120
- schema_filename = File.join(shard_group_schemas_dir, shard + "_schema.rb")
113
+ schema_filename = shard_schema_path(shard_group, shard)
121
114
  ActiveRecord::Tasks::DatabaseTasks.check_schema_file(schema_filename)
122
115
  Rails::Sharding.using_shard(shard_group, shard) do
123
116
  load(schema_filename)
@@ -154,10 +147,7 @@ shards_namespace = namespace :shards do
154
147
  Rails::Sharding.configurations.each do |shard_group, shards_configurations|
155
148
  next if ENV["SHARD_GROUP"] && ENV["SHARD_GROUP"] != shard_group.to_s
156
149
 
157
- # configures path for migrations of this shard group
158
- shard_group_migrations_path = 'db/shards_migrations/' + shard_group.to_s
159
- Rails.application.paths.add shard_group_migrations_path
160
- ActiveRecord::Tasks::DatabaseTasks.migrations_paths = Rails.application.paths[shard_group_migrations_path].to_a
150
+ setup_migrations_path(shard_group)
161
151
 
162
152
  shards_configurations.each do |shard, configuration|
163
153
  next if ENV["SHARD"] && ENV["SHARD"] != shard.to_s
@@ -179,10 +169,7 @@ shards_namespace = namespace :shards do
179
169
  Rails::Sharding.configurations.each do |shard_group, shards_configurations|
180
170
  next if ENV["SHARD_GROUP"] && ENV["SHARD_GROUP"] != shard_group.to_s
181
171
 
182
- # configures path for migrations of this shard group
183
- shard_group_migrations_path = 'db/shards_migrations/' + shard_group.to_s
184
- Rails.application.paths.add shard_group_migrations_path
185
- ActiveRecord::Tasks::DatabaseTasks.migrations_paths = Rails.application.paths[shard_group_migrations_path].to_a
172
+ setup_migrations_path(shard_group)
186
173
 
187
174
  shards_configurations.each do |shard, configuration|
188
175
  next if ENV["SHARD"] && ENV["SHARD"] != shard.to_s
@@ -203,10 +190,7 @@ shards_namespace = namespace :shards do
203
190
  Rails::Sharding.configurations.each do |shard_group, shards_configurations|
204
191
  next if ENV["SHARD_GROUP"] && ENV["SHARD_GROUP"] != shard_group.to_s
205
192
 
206
- # configures path for migrations of this shard group
207
- shard_group_migrations_path = 'db/shards_migrations/' + shard_group.to_s
208
- Rails.application.paths.add shard_group_migrations_path
209
- ActiveRecord::Tasks::DatabaseTasks.migrations_paths = Rails.application.paths[shard_group_migrations_path].to_a
193
+ setup_migrations_path(shard_group)
210
194
 
211
195
  shards_configurations.each do |shard, configuration|
212
196
  next if ENV["SHARD"] && ENV["SHARD"] != shard.to_s
@@ -242,10 +226,7 @@ shards_namespace = namespace :shards do
242
226
  Rails::Sharding.test_configurations.each do |shard_group, shards_configurations|
243
227
  next if ENV["SHARD_GROUP"] && ENV["SHARD_GROUP"] != shard_group.to_s
244
228
 
245
- # configures path for schemas of this shard group
246
- shard_group_schemas_path = 'db/shards_schemas/' + shard_group.to_s
247
- Rails.application.paths.add shard_group_schemas_path
248
- shard_group_schemas_dir = Rails.application.paths[shard_group_schemas_path].to_a.first
229
+ setup_migrations_path(shard_group)
249
230
 
250
231
  shards_configurations.each do |shard, configuration|
251
232
  next if ENV["SHARD"] && ENV["SHARD"] != shard.to_s
@@ -256,7 +237,7 @@ shards_namespace = namespace :shards do
256
237
  should_reconnect = Rails::Sharding::ConnectionHandler.connection_pool(shard_group, shard).active_connection?
257
238
  Rails::Sharding::ConnectionHandler.establish_connection(shard_group, shard, 'test')
258
239
 
259
- schema_filename = File.join(shard_group_schemas_dir, shard + "_schema.rb")
240
+ schema_filename = shard_schema_path(shard_group, shard)
260
241
  ActiveRecord::Tasks::DatabaseTasks.check_schema_file(schema_filename)
261
242
  Rails::Sharding.using_shard(shard_group, shard) do
262
243
  ActiveRecord::Schema.verbose = false
@@ -306,4 +287,21 @@ shards_namespace = namespace :shards do
306
287
  end
307
288
  end
308
289
  end
290
+
291
+ # Configures path for migrations of this shard group and creates dir if necessary
292
+ # We need this to run migrations (so we can find them)
293
+ # We need this load schemas (se we can build the schema_migrations table)
294
+ def setup_migrations_path(shard_group)
295
+ shard_group_migrations_dir = File.join(Rails::Sharding::Config.shards_migrations_dir, shard_group.to_s)
296
+ ActiveRecord::Tasks::DatabaseTasks.migrations_paths = [shard_group_migrations_dir]
297
+ ActiveRecord::Migrator.migrations_paths = [shard_group_migrations_dir]
298
+ FileUtils.mkdir_p(shard_group_migrations_dir)
299
+ end
300
+
301
+ # configures path for schemas of this shard group and creates dir if necessary
302
+ def shard_schema_path(shard_group, shard_name)
303
+ shard_group_schemas_dir = File.join(Rails::Sharding::Config.shards_schemas_dir, shard_group.to_s)
304
+ FileUtils.mkdir_p(shard_group_schemas_dir)
305
+ File.join(shard_group_schemas_dir, shard_name + "_schema.rb")
306
+ end
309
307
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rails-sharding
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Henrique Gubert