active_record_shards 3.22.0 → 4.0.0.beta1

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.
@@ -1,23 +1,16 @@
1
- # show which connection was picked to debug primary/replica slowness when both servers are the same
1
+ # show which connection was picked to debug master/slave slowness when both servers are the same
2
2
  module ActiveRecordShards
3
3
  module SqlComments
4
4
  module Methods
5
5
  def execute(query, name = nil)
6
- shard = ActiveRecord::Base.current_shard_selection.shard
7
- shard_text = shard ? "shard #{shard}" : 'unsharded'
8
- replica = ActiveRecord::Base.current_shard_selection.on_replica?
9
- replica_text = replica ? 'replica' : 'primary'
10
- query = "/* #{shard_text} #{replica_text} */ " + query
6
+ slave = ActiveRecord::Base.current_shard_selection.on_slave?
7
+ query += " /* #{slave ? 'slave' : 'master'} */"
11
8
  super(query, name)
12
9
  end
13
10
  end
14
11
 
15
12
  def self.enable
16
- ActiveRecord::Base.on_replica do
17
- ActiveRecord::Base.on_shard(nil) do
18
- ActiveRecord::Base.connection.class.prepend(Methods)
19
- end
20
- end
13
+ ActiveRecord::Base.connection.class.prepend(Methods)
21
14
  end
22
15
  end
23
16
  end
@@ -1,5 +1,4 @@
1
1
  # frozen_string_literal: true
2
-
3
2
  require 'active_record_shards'
4
3
 
5
4
  %w[db:drop db:create db:abort_if_pending_migrations db:reset db:test:purge].each do |name|
@@ -9,16 +8,15 @@ end
9
8
  namespace :db do
10
9
  desc 'Drops the database for the current RAILS_ENV including shards'
11
10
  task drop: :load_config do
12
- ActiveRecord::Base.configurations.to_h.each do |key, conf|
13
- next if !key.start_with?(ActiveRecordShards.app_env) || key.end_with?("_replica", "_slave")
14
-
11
+ ActiveRecord::Base.configurations.each do |key, conf|
12
+ next if !key.starts_with?(ActiveRecordShards.rails_env) || key.ends_with?("_slave")
15
13
  begin
16
14
  ActiveRecordShards::Tasks.root_connection(conf).drop_database(conf['database'])
17
15
  # rescue ActiveRecord::NoDatabaseError # TODO: exists in AR but never is raised here ...
18
16
  # $stderr.puts "Database '#{conf['database']}' does not exist"
19
- rescue StandardError => e
20
- warn e, *e.backtrace
21
- warn "Couldn't drop #{conf['database']}"
17
+ rescue StandardError => error
18
+ $stderr.puts error, *error.backtrace
19
+ $stderr.puts "Couldn't drop #{conf['database']}"
22
20
  end
23
21
  end
24
22
  end
@@ -30,45 +28,36 @@ namespace :db do
30
28
 
31
29
  desc "Create the database defined in config/database.yml for the current RAILS_ENV including shards"
32
30
  task create: :load_config do
33
- ActiveRecord::Base.configurations.to_h.each do |key, conf|
34
- next if !key.start_with?(ActiveRecordShards.app_env) || key.end_with?("_replica", "_slave")
35
-
31
+ ActiveRecord::Base.configurations.each do |key, conf|
32
+ next if !key.starts_with?(ActiveRecordShards.rails_env) || key.ends_with?("_slave")
36
33
  begin
37
- # MysqlAdapter takes charset instead of encoding in Rails 4.2 or greater
38
- # https://github.com/rails/rails/blob/4-2-stable/activerecord/lib/active_record/tasks/mysql_database_tasks.rb#L85-L96
34
+ # MysqlAdapter takes charset instead of encoding in Rails 4
35
+ # https://github.com/rails/rails/commit/78b30fed9336336694fb2cb5d2825f95800b541c
39
36
  symbolized_configuration = conf.symbolize_keys
40
37
  symbolized_configuration[:charset] = symbolized_configuration[:encoding]
41
38
 
42
39
  ActiveRecordShards::Tasks.root_connection(conf).create_database(conf['database'], symbolized_configuration)
43
- rescue ActiveRecord::StatementInvalid => e
44
- if e.message.include?('database exists')
40
+ rescue ActiveRecord::StatementInvalid => ex
41
+ if ex.message.include?('database exists')
45
42
  puts "#{conf['database']} already exists"
46
43
  else
47
- raise e
44
+ raise ex
48
45
  end
49
46
  end
50
47
  end
51
- ActiveRecord::Base.establish_connection(ActiveRecordShards.app_env.to_sym)
48
+ ActiveRecord::Base.establish_connection(ActiveRecordShards.rails_env.to_sym)
52
49
  end
53
50
 
54
51
  desc "Raises an error if there are pending migrations"
55
52
  task abort_if_pending_migrations: :environment do
56
53
  if defined? ActiveRecord
57
54
  pending_migrations =
58
- if ActiveRecord::VERSION::MAJOR >= 6
59
- migrations = ActiveRecord::MigrationContext.new(ActiveRecord::Migrator.migrations_paths, ActiveRecord::SchemaMigration).migrations
60
- ActiveRecord::Migrator.new(:up, migrations, ActiveRecord::SchemaMigration).pending_migrations
61
- elsif ActiveRecord::VERSION::STRING >= "5.2.0"
62
- migrations = ActiveRecord::MigrationContext.new(ActiveRecord::Migrator.migrations_paths).migrations
63
- ActiveRecord::Migrator.new(:up, migrations).pending_migrations
64
- else
65
- ActiveRecord::Base.on_shard(nil) { ActiveRecord::Migrator.open(ActiveRecord::Migrator.migrations_paths).pending_migrations }
66
- end
55
+ ActiveRecord::Base.on_shard(nil) { ActiveRecord::Migrator.open(ActiveRecord::Migrator.migrations_paths).pending_migrations }
67
56
 
68
57
  if pending_migrations.any?
69
- warn "You have #{pending_migrations.size} pending migrations:"
58
+ puts "You have #{pending_migrations.size} pending migrations:"
70
59
  pending_migrations.each do |pending_migration|
71
- warn ' %4d %s' % [pending_migration.version, pending_migration.name]
60
+ puts ' %4d %s' % [pending_migration.version, pending_migration.name]
72
61
  end
73
62
  abort %(Run "rake db:migrate" to update your database then try again.)
74
63
  end
@@ -92,20 +81,12 @@ end
92
81
 
93
82
  module ActiveRecordShards
94
83
  module Tasks
95
- class << self
96
- def root_connection(conf)
97
- conf = conf.merge('database' => nil)
98
- spec = spec_for(conf)
99
-
100
- ActiveRecord::Base.send("#{conf['adapter']}_connection", spec.config)
101
- end
102
-
103
- private
104
-
105
- def spec_for(conf)
106
- resolver = ActiveRecord::ConnectionAdapters::ConnectionSpecification::Resolver.new(ActiveRecord::Base.configurations)
107
- resolver.spec(conf)
108
- end
84
+ def self.root_connection(conf)
85
+ # this will trigger rails to load the adapter
86
+ conf = conf.merge('database' => nil)
87
+ resolver = ActiveRecord::ConnectionAdapters::ConnectionSpecification::Resolver.new(ActiveRecord::Base.configurations)
88
+ resolver.spec(conf)
89
+ ActiveRecord::Base.send("#{conf['adapter']}_connection", conf)
109
90
  end
110
91
  end
111
92
  end
@@ -1,27 +1,19 @@
1
1
  # frozen_string_literal: true
2
-
3
2
  require 'active_record'
4
3
  require 'active_record/base'
5
4
  require 'active_record_shards/configuration_parser'
6
5
  require 'active_record_shards/model'
6
+ require 'active_record_shards/sharded_model'
7
7
  require 'active_record_shards/shard_selection'
8
8
  require 'active_record_shards/connection_switcher'
9
9
  require 'active_record_shards/association_collection_connection_selection'
10
- require 'active_record_shards/migration'
11
- require 'active_record_shards/default_replica_patches'
12
- require 'active_record_shards/schema_dumper_extension'
10
+ require 'active_record_shards/default_slave_patches'
13
11
 
14
12
  module ActiveRecordShards
15
- class << self
16
- attr_accessor :disable_replica_readonly_records
17
- end
18
-
19
- def self.app_env
13
+ def self.rails_env
20
14
  env = Rails.env if defined?(Rails.env)
21
15
  env ||= RAILS_ENV if Object.const_defined?(:RAILS_ENV)
22
16
  env ||= ENV['RAILS_ENV']
23
- env ||= APP_ENV if Object.const_defined?(:APP_ENV)
24
- env ||= ENV['APP_ENV']
25
17
  env || 'development'
26
18
  end
27
19
  end
@@ -29,119 +21,7 @@ end
29
21
  ActiveRecord::Base.extend(ActiveRecordShards::ConfigurationParser)
30
22
  ActiveRecord::Base.extend(ActiveRecordShards::Model)
31
23
  ActiveRecord::Base.extend(ActiveRecordShards::ConnectionSwitcher)
32
- ActiveRecord::Base.extend(ActiveRecordShards::DefaultReplicaPatches)
33
- ActiveRecord::Relation.include(ActiveRecordShards::DefaultReplicaPatches::ActiveRelationPatches)
24
+ ActiveRecord::Base.extend(ActiveRecordShards::DefaultSlavePatches)
25
+ ActiveRecord::Relation.include(ActiveRecordShards::DefaultSlavePatches::ActiveRelationPatches)
34
26
  ActiveRecord::Associations::CollectionProxy.include(ActiveRecordShards::AssociationCollectionConnectionSelection)
35
- ActiveRecord::Associations::Builder::HasAndBelongsToMany.include(ActiveRecordShards::DefaultReplicaPatches::Rails41HasAndBelongsToManyBuilderExtension)
36
- ActiveRecord::SchemaDumper.prepend(ActiveRecordShards::SchemaDumperExtension)
37
-
38
- case "#{ActiveRecord::VERSION::MAJOR}.#{ActiveRecord::VERSION::MINOR}"
39
- when '4.2'
40
- require 'active_record_shards/patches-4-2'
41
-
42
- # https://github.com/rails/rails/blob/v4.2.11.3/activerecord/lib/active_record/associations/association.rb#L97
43
- ActiveRecord::Associations::Association.prepend(ActiveRecordShards::DefaultReplicaPatches::AssociationsAssociationAssociationScopePatch)
44
-
45
- # https://github.com/rails/rails/blob/v4.2.11.3/activerecord/lib/active_record/associations/singular_association.rb#L44-L53
46
- ActiveRecord::Associations::SingularAssociation.prepend(ActiveRecordShards::DefaultReplicaPatches::AssociationsAssociationGetRecordsPatch)
47
-
48
- # https://github.com/rails/rails/blob/v4.2.11.3/activerecord/lib/active_record/associations/collection_association.rb#L447-L456
49
- ActiveRecord::Associations::CollectionAssociation.prepend(ActiveRecordShards::DefaultReplicaPatches::AssociationsAssociationGetRecordsPatch)
50
-
51
- # https://github.com/rails/rails/blob/v4.2.11.3/activerecord/lib/active_record/associations/preloader/association.rb#L89
52
- ActiveRecord::Associations::Preloader::Association.prepend(ActiveRecordShards::DefaultReplicaPatches::AssociationsPreloaderAssociationAssociatedRecordsByOwnerPatch)
53
- when '5.0'
54
- # https://github.com/rails/rails/blob/v5.0.7/activerecord/lib/active_record/associations/association.rb#L97
55
- ActiveRecord::Associations::Association.prepend(ActiveRecordShards::DefaultReplicaPatches::AssociationsAssociationAssociationScopePatch)
56
-
57
- # https://github.com/rails/rails/blob/v5.0.7/activerecord/lib/active_record/associations/singular_association.rb#L56-L65
58
- ActiveRecord::Associations::SingularAssociation.prepend(ActiveRecordShards::DefaultReplicaPatches::AssociationsAssociationGetRecordsPatch)
59
-
60
- # https://github.com/rails/rails/blob/v5.0.7/activerecord/lib/active_record/associations/collection_association.rb#L442-L451
61
- ActiveRecord::Associations::CollectionAssociation.prepend(ActiveRecordShards::DefaultReplicaPatches::AssociationsAssociationGetRecordsPatch)
62
-
63
- # https://github.com/rails/rails/blob/v5.0.7/activerecord/lib/active_record/associations/preloader/association.rb#L120
64
- ActiveRecord::Associations::Preloader::Association.prepend(ActiveRecordShards::DefaultReplicaPatches::AssociationsPreloaderAssociationLoadRecordsPatch)
65
- when '5.1'
66
- # https://github.com/rails/rails/blob/v5.1.7/activerecord/lib/active_record/associations/association.rb#L97
67
- ActiveRecord::Associations::Association.prepend(ActiveRecordShards::DefaultReplicaPatches::AssociationsAssociationAssociationScopePatch)
68
-
69
- # https://github.com/rails/rails/blob/v5.1.7/activerecord/lib/active_record/associations/singular_association.rb#L41
70
- ActiveRecord::Associations::SingularAssociation.prepend(ActiveRecordShards::DefaultReplicaPatches::AssociationsAssociationFindTargetPatch)
71
-
72
- # https://github.com/rails/rails/blob/v5.1.7/activerecord/lib/active_record/associations/collection_association.rb#L305
73
- ActiveRecord::Associations::CollectionAssociation.prepend(ActiveRecordShards::DefaultReplicaPatches::AssociationsAssociationFindTargetPatch)
74
-
75
- # https://github.com/rails/rails/blob/v5.1.7/activerecord/lib/active_record/associations/preloader/association.rb#L120
76
- ActiveRecord::Associations::Preloader::Association.prepend(ActiveRecordShards::DefaultReplicaPatches::AssociationsPreloaderAssociationLoadRecordsPatch)
77
- when '5.2'
78
- # https://github.com/rails/rails/blob/v5.2.6/activerecord/lib/active_record/relation.rb#L530
79
- # But the #exec_queries method also calls #connection, and I don't know if we should patch that one, too...
80
- ActiveRecord::Relation.prepend(ActiveRecordShards::DefaultReplicaPatches::Rails52RelationPatches)
81
-
82
- # https://github.com/rails/rails/blob/v5.2.6/activerecord/lib/active_record/associations/singular_association.rb#L42
83
- ActiveRecord::Associations::SingularAssociation.prepend(ActiveRecordShards::DefaultReplicaPatches::AssociationsAssociationFindTargetPatch)
84
-
85
- # https://github.com/rails/rails/blob/v5.2.6/activerecord/lib/active_record/associations/collection_association.rb#L308
86
- ActiveRecord::Associations::CollectionAssociation.prepend(ActiveRecordShards::DefaultReplicaPatches::AssociationsAssociationFindTargetPatch)
87
-
88
- # https://github.com/rails/rails/blob/v5.2.6/activerecord/lib/active_record/associations/preloader/association.rb#L96
89
- ActiveRecord::Associations::Preloader::Association.prepend(ActiveRecordShards::DefaultReplicaPatches::AssociationsPreloaderAssociationLoadRecordsPatch)
90
- when '6.0'
91
- # https://github.com/rails/rails/blob/v6.0.4/activerecord/lib/active_record/type_caster/connection.rb#L28
92
- ActiveRecord::TypeCaster::Connection.prepend(ActiveRecordShards::DefaultReplicaPatches::TypeCasterConnectionConnectionPatch)
93
-
94
- # https://github.com/rails/rails/blob/v6.0.4/activerecord/lib/active_record/schema.rb#L53-L54
95
- ActiveRecord::Schema.prepend(ActiveRecordShards::DefaultReplicaPatches::SchemaDefinePatch)
96
-
97
- # https://github.com/rails/rails/blob/v6.0.4/activerecord/lib/active_record/relation.rb#L739
98
- # But the #exec_queries and #compute_cache_version methods also call #connection, and I don't know if we should patch those, too...
99
- ActiveRecord::Relation.prepend(ActiveRecordShards::DefaultReplicaPatches::Rails52RelationPatches)
100
-
101
- # https://github.com/rails/rails/blob/v6.0.4/activerecord/lib/active_record/associations/association.rb#L213
102
- ActiveRecord::Associations::Association.prepend(ActiveRecordShards::DefaultReplicaPatches::AssociationsAssociationFindTargetPatch)
103
- else
104
- raise "ActiveRecordShards is not compatible with #{ActiveRecord::VERSION::STRING}"
105
- end
106
-
107
- require 'active_record_shards/deprecation'
108
-
109
- ActiveRecordShards::Deprecation.deprecate_methods(
110
- ActiveRecordShards::AssociationCollectionConnectionSelection,
111
- on_slave_if: :on_replica_if,
112
- on_slave_unless: :on_replica_unless,
113
- on_slave: :on_replica,
114
- on_master: :on_primary,
115
- on_master_if: :on_primary_if,
116
- on_master_unless: :on_primary_unless
117
- )
118
-
119
- ActiveRecordShards::Deprecation.deprecate_methods(
120
- ActiveRecordShards::ConnectionSwitcher,
121
- on_slave_if: :on_replica_if,
122
- on_slave_unless: :on_replica_unless,
123
- on_master_or_slave: :on_primary_or_replica,
124
- on_slave: :on_replica,
125
- on_master: :on_primary,
126
- on_master_if: :on_primary_if,
127
- on_master_unless: :on_primary_unless,
128
- on_slave?: :on_replica?
129
- )
130
-
131
- ActiveRecordShards::Deprecation.deprecate_methods(
132
- ActiveRecordShards::DefaultReplicaPatches,
133
- transaction_with_slave_off: :transaction_with_replica_off,
134
- on_slave_unless_tx: :on_replica_unless_tx
135
- )
136
-
137
- ActiveRecordShards::Deprecation.deprecate_methods(
138
- ActiveRecordShards::Model,
139
- on_slave_by_default?: :on_replica_by_default?,
140
- :on_slave_by_default= => :on_replica_by_default=
141
- )
142
-
143
- ActiveRecordShards::Deprecation.deprecate_methods(
144
- ActiveRecordShards::ShardSelection,
145
- on_slave?: :on_replica?,
146
- :on_slave= => :on_replica=
147
- )
27
+ ActiveRecord::Associations::Builder::HasAndBelongsToMany.include(ActiveRecordShards::DefaultSlavePatches::HasAndBelongsToManyBuilderExtension)
metadata CHANGED
@@ -1,62 +1,47 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: active_record_shards
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.22.0
4
+ version: 4.0.0.beta1
5
5
  platform: ruby
6
6
  authors:
7
- - Benjamin Quorning
8
- - Gabe Martin-Dempesy
9
- - Pierre Schambacher
10
7
  - Mick Staugaard
11
8
  - Eric Chapweske
12
9
  - Ben Osheroff
13
10
  autorequire:
14
11
  bindir: bin
15
12
  cert_chain: []
16
- date: 2023-08-28 00:00:00.000000000 Z
13
+ date: 2017-10-26 00:00:00.000000000 Z
17
14
  dependencies:
18
15
  - !ruby/object:Gem::Dependency
19
16
  name: activerecord
20
17
  requirement: !ruby/object:Gem::Requirement
21
18
  requirements:
22
- - - ">="
23
- - !ruby/object:Gem::Version
24
- version: '4.2'
25
- - - "<"
19
+ - - "~>"
26
20
  - !ruby/object:Gem::Version
27
- version: '6.1'
21
+ version: '5.0'
28
22
  type: :runtime
29
23
  prerelease: false
30
24
  version_requirements: !ruby/object:Gem::Requirement
31
25
  requirements:
32
- - - ">="
33
- - !ruby/object:Gem::Version
34
- version: '4.2'
35
- - - "<"
26
+ - - "~>"
36
27
  - !ruby/object:Gem::Version
37
- version: '6.1'
28
+ version: '5.0'
38
29
  - !ruby/object:Gem::Dependency
39
30
  name: activesupport
40
31
  requirement: !ruby/object:Gem::Requirement
41
32
  requirements:
42
- - - ">="
43
- - !ruby/object:Gem::Version
44
- version: '4.2'
45
- - - "<"
33
+ - - "~>"
46
34
  - !ruby/object:Gem::Version
47
- version: '6.1'
35
+ version: '5.0'
48
36
  type: :runtime
49
37
  prerelease: false
50
38
  version_requirements: !ruby/object:Gem::Requirement
51
39
  requirements:
52
- - - ">="
53
- - !ruby/object:Gem::Version
54
- version: '4.2'
55
- - - "<"
40
+ - - "~>"
56
41
  - !ruby/object:Gem::Version
57
- version: '6.1'
42
+ version: '5.0'
58
43
  - !ruby/object:Gem::Dependency
59
- name: bump
44
+ name: wwtd
60
45
  requirement: !ruby/object:Gem::Requirement
61
46
  requirements:
62
47
  - - ">="
@@ -70,35 +55,35 @@ dependencies:
70
55
  - !ruby/object:Gem::Version
71
56
  version: '0'
72
57
  - !ruby/object:Gem::Dependency
73
- name: minitest
58
+ name: rake
74
59
  requirement: !ruby/object:Gem::Requirement
75
60
  requirements:
76
- - - ">="
61
+ - - "~>"
77
62
  - !ruby/object:Gem::Version
78
- version: 5.10.0
63
+ version: '12.0'
79
64
  type: :development
80
65
  prerelease: false
81
66
  version_requirements: !ruby/object:Gem::Requirement
82
67
  requirements:
83
- - - ">="
68
+ - - "~>"
84
69
  - !ruby/object:Gem::Version
85
- version: 5.10.0
70
+ version: '12.0'
86
71
  - !ruby/object:Gem::Dependency
87
- name: mocha
72
+ name: mysql2
88
73
  requirement: !ruby/object:Gem::Requirement
89
74
  requirements:
90
75
  - - ">="
91
76
  - !ruby/object:Gem::Version
92
- version: 1.4.0
77
+ version: '0'
93
78
  type: :development
94
79
  prerelease: false
95
80
  version_requirements: !ruby/object:Gem::Requirement
96
81
  requirements:
97
82
  - - ">="
98
83
  - !ruby/object:Gem::Version
99
- version: 1.4.0
84
+ version: '0'
100
85
  - !ruby/object:Gem::Dependency
101
- name: mysql2
86
+ name: bump
102
87
  requirement: !ruby/object:Gem::Requirement
103
88
  requirements:
104
89
  - - ">="
@@ -112,67 +97,80 @@ dependencies:
112
97
  - !ruby/object:Gem::Version
113
98
  version: '0'
114
99
  - !ruby/object:Gem::Dependency
115
- name: rake
100
+ name: rubocop
116
101
  requirement: !ruby/object:Gem::Requirement
117
102
  requirements:
118
- - - "~>"
103
+ - - '='
119
104
  - !ruby/object:Gem::Version
120
- version: '12.0'
105
+ version: 0.50.0
121
106
  type: :development
122
107
  prerelease: false
123
108
  version_requirements: !ruby/object:Gem::Requirement
124
109
  requirements:
125
- - - "~>"
110
+ - - '='
126
111
  - !ruby/object:Gem::Version
127
- version: '12.0'
112
+ version: 0.50.0
128
113
  - !ruby/object:Gem::Dependency
129
- name: rubocop
114
+ name: minitest
130
115
  requirement: !ruby/object:Gem::Requirement
131
116
  requirements:
132
- - - "~>"
117
+ - - ">="
133
118
  - !ruby/object:Gem::Version
134
- version: 0.77.0
119
+ version: '0'
135
120
  type: :development
136
121
  prerelease: false
137
122
  version_requirements: !ruby/object:Gem::Requirement
138
123
  requirements:
139
- - - "~>"
124
+ - - ">="
140
125
  - !ruby/object:Gem::Version
141
- version: 0.77.0
126
+ version: '0'
142
127
  - !ruby/object:Gem::Dependency
143
- name: rubocop-minitest
128
+ name: minitest-rg
144
129
  requirement: !ruby/object:Gem::Requirement
145
130
  requirements:
146
- - - "~>"
131
+ - - ">="
147
132
  - !ruby/object:Gem::Version
148
- version: 0.5.0
133
+ version: '0'
149
134
  type: :development
150
135
  prerelease: false
151
136
  version_requirements: !ruby/object:Gem::Requirement
152
137
  requirements:
153
- - - "~>"
138
+ - - ">="
154
139
  - !ruby/object:Gem::Version
155
- version: 0.5.0
140
+ version: '0'
156
141
  - !ruby/object:Gem::Dependency
157
- name: rubocop-performance
142
+ name: mocha
158
143
  requirement: !ruby/object:Gem::Requirement
159
144
  requirements:
160
- - - "~>"
145
+ - - ">="
161
146
  - !ruby/object:Gem::Version
162
- version: 1.5.1
147
+ version: '0'
163
148
  type: :development
164
149
  prerelease: false
165
150
  version_requirements: !ruby/object:Gem::Requirement
166
151
  requirements:
167
- - - "~>"
152
+ - - ">="
153
+ - !ruby/object:Gem::Version
154
+ version: '0'
155
+ - !ruby/object:Gem::Dependency
156
+ name: phenix
157
+ requirement: !ruby/object:Gem::Requirement
158
+ requirements:
159
+ - - ">="
160
+ - !ruby/object:Gem::Version
161
+ version: 0.2.0
162
+ type: :development
163
+ prerelease: false
164
+ version_requirements: !ruby/object:Gem::Requirement
165
+ requirements:
166
+ - - ">="
168
167
  - !ruby/object:Gem::Version
169
- version: 1.5.1
170
- description: Easily run queries on shard and replica databases.
168
+ version: 0.2.0
169
+ description: Easily run queries on shard and slave databases.
171
170
  email:
172
- - bquorning@zendesk.com
173
- - gabe@zendesk.com
174
- - pschambacher@zendesk.com
175
171
  - mick@staugaard.com
172
+ - eac@zendesk.com
173
+ - ben@gimbo.net
176
174
  executables: []
177
175
  extensions: []
178
176
  extra_rdoc_files: []
@@ -181,23 +179,14 @@ files:
181
179
  - lib/active_record_shards.rb
182
180
  - lib/active_record_shards/association_collection_connection_selection.rb
183
181
  - lib/active_record_shards/configuration_parser.rb
184
- - lib/active_record_shards/connection_handler.rb
185
- - lib/active_record_shards/connection_pool.rb
186
- - lib/active_record_shards/connection_specification.rb
187
- - lib/active_record_shards/connection_switcher-4-2.rb
188
182
  - lib/active_record_shards/connection_switcher-5-0.rb
189
183
  - lib/active_record_shards/connection_switcher-5-1.rb
190
- - lib/active_record_shards/connection_switcher-6-0.rb
191
184
  - lib/active_record_shards/connection_switcher.rb
192
- - lib/active_record_shards/default_replica_patches.rb
193
185
  - lib/active_record_shards/default_slave_patches.rb
194
- - lib/active_record_shards/deprecation.rb
195
- - lib/active_record_shards/migration.rb
196
186
  - lib/active_record_shards/model.rb
197
- - lib/active_record_shards/patches-4-2.rb
198
- - lib/active_record_shards/schema_dumper_extension.rb
199
187
  - lib/active_record_shards/shard_selection.rb
200
188
  - lib/active_record_shards/shard_support.rb
189
+ - lib/active_record_shards/sharded_model.rb
201
190
  - lib/active_record_shards/sql_comments.rb
202
191
  - lib/active_record_shards/tasks.rb
203
192
  homepage: https://github.com/zendesk/active_record_shards
@@ -210,16 +199,17 @@ require_paths:
210
199
  - lib
211
200
  required_ruby_version: !ruby/object:Gem::Requirement
212
201
  requirements:
213
- - - ">="
202
+ - - "~>"
214
203
  - !ruby/object:Gem::Version
215
- version: '2.3'
204
+ version: '2.0'
216
205
  required_rubygems_version: !ruby/object:Gem::Requirement
217
206
  requirements:
218
- - - ">="
207
+ - - ">"
219
208
  - !ruby/object:Gem::Version
220
- version: '0'
209
+ version: 1.3.1
221
210
  requirements: []
222
- rubygems_version: 3.0.3.1
211
+ rubyforge_project:
212
+ rubygems_version: 2.6.13
223
213
  signing_key:
224
214
  specification_version: 4
225
215
  summary: Simple database switching for ActiveRecord.
@@ -1,8 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- ActiveRecord::ConnectionAdapters::ConnectionHandler.class_eval do
4
- remove_method :retrieve_connection_pool
5
- def retrieve_connection_pool(klass)
6
- class_to_pool[klass.connection_pool_name] ||= pool_for(klass)
7
- end
8
- end
@@ -1,36 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module ActiveRecordShards
4
- ConnectionPoolNameDecorator = Struct.new(:name)
5
-
6
- # It overrides given connection handler methods (they differ depend on
7
- # Rails version).
8
- #
9
- # It takes the first argument, ActiveRecord::Base object or
10
- # String (connection_pool_name), converts it in Struct object and
11
- # passes to the original method.
12
- #
13
- # Example:
14
- # methods_to_override = [:establish_connection, :remove_connection]
15
- # ActiveRecordShards.override_connection_handler_methods(methods_to_override)
16
- #
17
- def self.override_connection_handler_methods(method_names)
18
- method_names.each do |method_name|
19
- ActiveRecord::ConnectionAdapters::ConnectionHandler.class_eval do
20
- define_method("#{method_name}_with_connection_pool_name") do |*args|
21
- unless args[0].is_a? ConnectionPoolNameDecorator
22
- name = if args[0].is_a? String
23
- args[0]
24
- else
25
- args[0].connection_pool_name
26
- end
27
- args[0] = ConnectionPoolNameDecorator.new(name)
28
- end
29
- send("#{method_name}_without_connection_pool_name", *args)
30
- end
31
- alias_method :"#{method_name}_without_connection_pool_name", method_name
32
- alias_method method_name, :"#{method_name}_with_connection_pool_name"
33
- end
34
- end
35
- end
36
- end
@@ -1,19 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- class << ActiveRecord::Base
4
- remove_method :establish_connection if ActiveRecord::VERSION::MAJOR >= 5
5
- def establish_connection(spec = ENV["DATABASE_URL"])
6
- spec ||= ActiveRecord::ConnectionHandling::DEFAULT_ENV.call
7
- spec = spec.to_sym if spec.is_a?(String)
8
- resolver = ActiveRecordShards::ConnectionSpecification::Resolver.new configurations
9
- spec = resolver.spec(spec)
10
-
11
- unless respond_to?(spec.adapter_method)
12
- raise AdapterNotFound, "database configuration specifies nonexistent #{spec.config[:adapter]} adapter"
13
- end
14
-
15
- remove_connection
16
- specification_cache[connection_pool_name] = spec
17
- connection_handler.establish_connection self, spec
18
- end
19
- end