active_record_shards 3.7.0 → 3.7.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
2
  SHA1:
3
- metadata.gz: 5542b744064c7c57d721c9bd315a17504c619d76
4
- data.tar.gz: 8af807dac50f2c674678e45f1241445e6959a76c
3
+ metadata.gz: 0e203b68170add3e662a225149760c94ddec6a25
4
+ data.tar.gz: 0cd9762ecefd6e9c0fa52a244a142573d45a299d
5
5
  SHA512:
6
- metadata.gz: 6193ca15cee5319d6c0be74a9121999e815724d836890038c06c09d5c45c9184467d52c76d33643169c7ecac14b0ec7d2da21b2a60801e58a9f3311d72a5e033
7
- data.tar.gz: df1d2c2e88989cac38a4b6f2c2830416911b57a2c1cfa02fa448c059c309c379dc5473e5c4e43b02492b19999f88c159cc5c1d347343ba9fbd31b0fc87c45470
6
+ metadata.gz: 91264360257099f210038dc7794b26a142a418e23cb66b24abd1b8e3ae8868266886d9de7a8ae529864e6dd0a5243afeafda29d269ef1fddc8cfe41a0e830455
7
+ data.tar.gz: a607aad5fc1d32f4df67f331e1a651731c2b1900e8c7d52ffdccd56bf5d760fe61da456495d196e5521bda5817b541b178beb112dbeab26b4bae94f8433d5352
data/README.md CHANGED
@@ -1,3 +1,5 @@
1
+ [![Build Status](https://secure.travis-ci.org/zendesk/active_record_shards.png)](http://travis-ci.org/zendesk/active_record_shards)
2
+
1
3
  # ActiveRecord Shards
2
4
 
3
5
  ActiveRecord Shards is an extension for ActiveRecord that provides support for sharded database and slaves. Basically it is just a nice way to
@@ -95,5 +97,3 @@ Copyright (c) 2011 Zendesk. See LICENSE for details.
95
97
 
96
98
  ## Authors
97
99
  Mick Staugaard, Eric Chapweske
98
-
99
- [![Build Status](https://secure.travis-ci.org/osheroff/active_record_shards.png)](http://travis-ci.org/osheroff/active_record_shards)
@@ -14,7 +14,7 @@ module ActiveRecordShards
14
14
  env = Rails.env if defined?(Rails.env)
15
15
  env ||= RAILS_ENV if Object.const_defined?(:RAILS_ENV)
16
16
  env ||= ENV['RAILS_ENV']
17
- env ||= 'development'
17
+ env || 'development'
18
18
  end
19
19
  end
20
20
 
@@ -1,6 +1,5 @@
1
1
  module ActiveRecordShards
2
2
  module ConnectionSwitcher
3
-
4
3
  # Name of the connection pool. Used by ConnectionHandler to retrieve the current connection pool.
5
4
  def connection_pool_name # :nodoc:
6
5
  name = current_shard_selection.shard_name(self)
@@ -22,7 +21,7 @@ module ActiveRecordShards
22
21
  name = connection_pool_name
23
22
  spec = configurations[name]
24
23
 
25
- raise ActiveRecord::AdapterNotSpecified.new("No database defined by #{name} in database.yml") if spec.nil?
24
+ raise(ActiveRecord::AdapterNotSpecified, "No database defined by #{name} in database.yml") if spec.nil?
26
25
 
27
26
  # in 3.2 rails is asking for a connection pool in a map of these ConnectionSpecifications. If we want to re-use connections,
28
27
  # we need to re-use specs.
@@ -61,7 +60,7 @@ module ActiveRecordShards
61
60
  specs_to_pools = connection_handler.connection_pools
62
61
  end
63
62
 
64
- specs_to_pools.has_key?(connection_pool_key)
63
+ specs_to_pools.key?(connection_pool_key)
65
64
  end
66
65
  end
67
66
  end
@@ -1,7 +1,7 @@
1
1
  module ActiveRecordShards
2
2
  module ConnectionSwitcher
3
3
  def connection_specification_name
4
- name = current_shard_selection.resolve_connection_name(sharded: is_sharded?, configurations: self.configurations)
4
+ name = current_shard_selection.resolve_connection_name(sharded: is_sharded?, configurations: configurations)
5
5
 
6
6
  raise "No configuration found for #{name}" unless configurations[name] || name == "primary"
7
7
  name
@@ -141,11 +141,11 @@ module ActiveRecordShards
141
141
 
142
142
  def switch_connection(options)
143
143
  if options.any?
144
- if options.has_key?(:slave)
144
+ if options.key?(:slave)
145
145
  current_shard_selection.on_slave = options[:slave]
146
146
  end
147
147
 
148
- if options.has_key?(:shard)
148
+ if options.key?(:shard)
149
149
  current_shard_selection.shard = options[:shard]
150
150
  end
151
151
 
@@ -11,7 +11,7 @@ module ActiveRecordShards
11
11
  return unless base_methods.include?(method)
12
12
  _, method, punctuation = method.to_s.match(/^(.*?)([\?\!]?)$/).to_a
13
13
  base.class_eval <<-RUBY, __FILE__, __LINE__ + 1
14
- #{class_method ? "class << self" : ""}
14
+ #{class_method ? 'class << self' : ''}
15
15
  def #{method}_with_default_slave#{punctuation}(*args, &block)
16
16
  on_slave_unless_tx do
17
17
  #{method}_without_default_slave#{punctuation}(*args, &block)
@@ -20,7 +20,7 @@ module ActiveRecordShards
20
20
 
21
21
  alias_method :#{method}_without_default_slave#{punctuation}, :#{method}#{punctuation}
22
22
  alias_method :#{method}#{punctuation}, :#{method}_with_default_slave#{punctuation}
23
- #{class_method ? "end" : ""}
23
+ #{class_method ? 'end' : ''}
24
24
  RUBY
25
25
  end
26
26
 
@@ -58,7 +58,7 @@ module ActiveRecordShards
58
58
  end
59
59
  end
60
60
 
61
- CLASS_SLAVE_METHODS = [ :find_by_sql, :count_by_sql, :calculate, :find_one, :find_some, :find_every, :exists?, :table_exists? ]
61
+ CLASS_SLAVE_METHODS = [:find_by_sql, :count_by_sql, :calculate, :find_one, :find_some, :find_every, :exists?, :table_exists?]
62
62
 
63
63
  def self.extended(base)
64
64
  CLASS_SLAVE_METHODS.each { |m| ActiveRecordShards::DefaultSlavePatches.wrap_method_in_on_slave(true, base, m) }
@@ -96,6 +96,13 @@ module ActiveRecordShards
96
96
  [:calculate, :exists?, :pluck, :find_with_associations].each do |m|
97
97
  ActiveRecordShards::DefaultSlavePatches.wrap_method_in_on_slave(false, base, m)
98
98
  end
99
+
100
+ # ActiveRecord::Explain in v3 will eagerly establish an on_master
101
+ # connection just to just the _static_ `supports_explain?` method on
102
+ # the Mysql2Adapter
103
+ if ActiveRecord::VERSION::MAJOR == 3
104
+ ActiveRecordShards::DefaultSlavePatches.wrap_method_in_on_slave(false, base, :logging_query_plan)
105
+ end
99
106
  end
100
107
 
101
108
  def on_slave_unless_tx
@@ -5,17 +5,17 @@ module ActiveRecord
5
5
  [:up, :down, :run].each do |m|
6
6
  define_method("#{m}_with_sharding") do |*args|
7
7
  ActiveRecord::Base.on_shard(nil) do
8
- self.send("#{m}_without_sharding", *args)
8
+ send("#{m}_without_sharding", *args)
9
9
  end
10
10
  ActiveRecord::Base.on_all_shards do
11
- self.send("#{m}_without_sharding", *args)
11
+ send("#{m}_without_sharding", *args)
12
12
  end
13
13
  end
14
14
  alias_method :"#{m}_without_sharding", m.to_sym
15
15
  alias_method m.to_sym, :"#{m}_with_sharding"
16
16
  end
17
17
 
18
- def bootstrap_migrations_from_nil_shard(migrations_path, this_migration=nil)
18
+ def bootstrap_migrations_from_nil_shard(migrations_path, this_migration = nil)
19
19
  migrations = nil
20
20
  ActiveRecord::Base.on_shard(nil) do
21
21
  migrations = ActiveRecord::Migrator.new(:up, migrations_path).migrated
@@ -78,7 +78,6 @@ module ActiveRecordShards
78
78
  def shard(arg = nil)
79
79
  self.migration_shard = arg
80
80
  end
81
-
82
81
  end
83
82
 
84
83
  # ok, so some 'splaining to do. Rails 3.1 puts the migrate() method on the instance of the
@@ -87,7 +86,7 @@ module ActiveRecordShards
87
86
  module ActualMigrationExtension
88
87
  def migrate_with_forced_shard(direction)
89
88
  if migration_shard.blank?
90
- raise RuntimeError, "#{self.name}: Can't run migrations without a shard spec: this may be :all, :none,
89
+ raise "#{name}: Can't run migrations without a shard spec: this may be :all, :none,
91
90
  or a specific shard (for data-fixups). please call shard(arg) in your migration."
92
91
  end
93
92
 
@@ -1,7 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
  module ActiveRecordShards
3
3
  module SchemaDumperExtension
4
-
5
4
  def dump(stream)
6
5
  stream = super(stream)
7
6
  original_connection = @connection
@@ -21,7 +20,6 @@ module ActiveRecordShards
21
20
  @connection = original_connection
22
21
  end
23
22
 
24
-
25
23
  def shard_header(stream)
26
24
  define_params = @version ? "version: #{@version}" : ""
27
25
 
@@ -34,11 +32,10 @@ ActiveRecord::Base.on_all_shards do
34
32
  ActiveRecord::Schema.define(#{define_params}) do
35
33
 
36
34
  HEADER
37
- end
35
+ end
38
36
 
39
37
  def shard_trailer(stream)
40
38
  stream.puts "end\nend"
41
39
  end
42
-
43
40
  end
44
41
  end
@@ -82,7 +82,7 @@ module ActiveRecordShards
82
82
  end
83
83
 
84
84
  def options
85
- {:shard => @shard, :slave => @on_slave}
85
+ { :shard => @shard, :slave => @on_slave }
86
86
  end
87
87
  end
88
88
  end
@@ -41,9 +41,9 @@ module ActiveRecordShards
41
41
  end
42
42
 
43
43
  private
44
+
44
45
  def ensure_concrete!
45
46
  raise "Please call this method on a concrete model, not an abstract class!" if @scope.abstract_class?
46
47
  end
47
48
  end
48
49
  end
49
-
@@ -15,7 +15,7 @@ namespace :db do
15
15
  # rescue ActiveRecord::NoDatabaseError # TODO: exists in AR but never is raised here ...
16
16
  # $stderr.puts "Database '#{conf['database']}' does not exist"
17
17
  rescue Exception => error
18
- $stderr.puts error, *(error.backtrace)
18
+ $stderr.puts error, *error.backtrace
19
19
  $stderr.puts "Couldn't drop #{conf['database']}"
20
20
  end
21
21
  end
@@ -68,7 +68,7 @@ namespace :db do
68
68
  pending_migrations.each do |pending_migration|
69
69
  puts ' %4d %s' % [pending_migration.version, pending_migration.name]
70
70
  end
71
- abort %{Run "rake db:migrate" to update your database then try again.}
71
+ abort %(Run "rake db:migrate" to update your database then try again.)
72
72
  end
73
73
  end
74
74
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: active_record_shards
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.7.0
4
+ version: 3.7.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mick Staugaard
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2016-08-16 00:00:00.000000000 Z
13
+ date: 2016-08-23 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: activerecord
@@ -108,6 +108,20 @@ dependencies:
108
108
  - - ">="
109
109
  - !ruby/object:Gem::Version
110
110
  version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: rubocop
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - '='
116
+ - !ruby/object:Gem::Version
117
+ version: 0.42.0
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - '='
123
+ - !ruby/object:Gem::Version
124
+ version: 0.42.0
111
125
  - !ruby/object:Gem::Dependency
112
126
  name: minitest
113
127
  requirement: !ruby/object:Gem::Requirement
@@ -214,7 +228,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
214
228
  version: '0'
215
229
  requirements: []
216
230
  rubyforge_project:
217
- rubygems_version: 2.6.6
231
+ rubygems_version: 2.5.1
218
232
  signing_key:
219
233
  specification_version: 4
220
234
  summary: Simple database switching for ActiveRecord.