switchman 1.13.3 → 1.15.0

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.
@@ -3,6 +3,7 @@ require 'switchman/database_server'
3
3
  module Switchman
4
4
  class DefaultShard
5
5
  def id; 'default'; end
6
+ alias cache_key id
6
7
  def activate(*categories); yield; end
7
8
  def activate!(*categories); end
8
9
  def default?; true; end
@@ -88,7 +88,7 @@ module Switchman
88
88
  require "switchman/call_super"
89
89
  require "switchman/rails"
90
90
  require "switchman/shackles/relation"
91
- require_dependency "switchman/shard_internal"
91
+ require_dependency "switchman/shard"
92
92
  require "switchman/standard_error"
93
93
 
94
94
  ::StandardError.include(StandardError)
@@ -118,11 +118,6 @@ module Switchman
118
118
  ::ActiveRecord::ConnectionAdapters::ConnectionHandler.prepend(ActiveRecord::ConnectionHandler)
119
119
  ::ActiveRecord::ConnectionAdapters::ConnectionPool.prepend(ActiveRecord::ConnectionPool)
120
120
  ::ActiveRecord::ConnectionAdapters::AbstractAdapter.prepend(ActiveRecord::QueryCache)
121
- # when we call super in Switchman::ActiveRecord::QueryCache#select_all,
122
- # we want it to find the definition from
123
- # ActiveRecord::ConnectionAdapters::DatabaseStatements, not
124
- # ActiveRecord::ConnectionAdapters::QueryCache
125
- ::ActiveRecord::ConnectionAdapters::QueryCache.send(:remove_method, :select_all) if ::Rails.version < '5.0.1'
126
121
 
127
122
  ::ActiveRecord::LogSubscriber.prepend(ActiveRecord::LogSubscriber)
128
123
  ::ActiveRecord::Migration.prepend(ActiveRecord::Migration)
@@ -173,6 +168,12 @@ module Switchman
173
168
  require "switchman/active_record/postgresql_adapter"
174
169
  ::ActiveRecord::ConnectionAdapters::PostgreSQLAdapter.prepend(ActiveRecord::PostgreSQLAdapter)
175
170
  end
171
+
172
+ # If Switchman::Shard wasn't loaded as of when ActiveRecord::Base initialized
173
+ # establish a connection here instead
174
+ if !Shard.instance_variable_get(:@default)
175
+ ::ActiveRecord::Base.establish_connection
176
+ end
176
177
  end
177
178
  end
178
179
 
@@ -121,7 +121,7 @@ module Switchman
121
121
  klass.before do
122
122
  raise "Sharding did not set up correctly" if @@sharding_failed
123
123
  Shard.clear_cache
124
- if ::Rails.version >= '5.1' ? use_transactional_tests : (use_transactional_tests || use_transactional_fixtures)
124
+ if use_transactional_tests
125
125
  Shard.default(true)
126
126
  @shard1 = Shard.find(@shard1.id)
127
127
  @shard2 = Shard.find(@shard2.id)
@@ -137,7 +137,7 @@ module Switchman
137
137
 
138
138
  klass.after do
139
139
  next if @@sharding_failed
140
- if ::Rails.version >= '5.1' ? use_transactional_tests : (use_transactional_tests || use_transactional_fixtures)
140
+ if use_transactional_tests
141
141
  shards = [@shard2]
142
142
  shards << @shard1 unless @shard1.database_server == Shard.default.database_server
143
143
  shards.each do |shard|
@@ -1,3 +1,3 @@
1
1
  module Switchman
2
- VERSION = "1.13.3"
2
+ VERSION = "1.15.0"
3
3
  end
@@ -20,7 +20,12 @@ module Switchman
20
20
  open = servers.delete('open')
21
21
 
22
22
  servers = servers.map { |server| DatabaseServer.find(server) }.compact
23
- servers.concat(DatabaseServer.all.select { |server| server.config[:open] }) if open
23
+ if open
24
+ open_servers = DatabaseServer.all.select { |server| server.config[:open] }
25
+ servers.concat(open_servers)
26
+ servers << DatabaseServer.find(nil) if open_servers.empty?
27
+ servers.uniq!
28
+ end
24
29
  servers = DatabaseServer.all - servers if negative
25
30
  end
26
31
 
@@ -67,7 +72,17 @@ module Switchman
67
72
  shard = Shard.current
68
73
  puts "#{shard.id}: #{shard.description}"
69
74
  ::ActiveRecord::Base.connection_pool.spec.config[:shard_name] = Shard.current.name
70
- ::ActiveRecord::Base.configurations[::Rails.env] = ::ActiveRecord::Base.connection_pool.spec.config.stringify_keys
75
+ if ::Rails.version < '6.0'
76
+ ::ActiveRecord::Base.configurations[::Rails.env] = ::ActiveRecord::Base.connection_pool.spec.config.stringify_keys
77
+ else
78
+ # Adopted from the deprecated code that currently lives in rails proper
79
+ remaining_configs = ::ActiveRecord::Base.configurations.configurations.reject { |db_config| db_config.env_name == ::Rails.env }
80
+ new_config = ::ActiveRecord::DatabaseConfigurations.new(::Rails.env =>
81
+ ::ActiveRecord::Base.connection_pool.spec.config.stringify_keys).configurations
82
+ new_configs = remaining_configs + new_config
83
+
84
+ ::ActiveRecord::Base.configurations = new_configs
85
+ end
71
86
  shard.database_server.unshackle do
72
87
  old_actions.each { |action| action.call(*task_args) }
73
88
  end
@@ -195,9 +210,7 @@ module Switchman
195
210
  @filter_database_servers_chain ||= ->(servers) { servers }
196
211
  end
197
212
  end
198
- end
199
213
 
200
- module Switchman
201
214
  module ActiveRecord
202
215
  module PostgreSQLDatabaseTasks
203
216
  def structure_dump(filename, extra_flags=nil)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: switchman
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.13.3
4
+ version: 1.15.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Cody Cutrer
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2019-05-14 00:00:00.000000000 Z
13
+ date: 2020-05-18 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: railties
@@ -18,54 +18,54 @@ dependencies:
18
18
  requirements:
19
19
  - - ">="
20
20
  - !ruby/object:Gem::Version
21
- version: '5.0'
21
+ version: '5.1'
22
22
  - - "<"
23
23
  - !ruby/object:Gem::Version
24
- version: '5.3'
24
+ version: '6.1'
25
25
  type: :runtime
26
26
  prerelease: false
27
27
  version_requirements: !ruby/object:Gem::Requirement
28
28
  requirements:
29
29
  - - ">="
30
30
  - !ruby/object:Gem::Version
31
- version: '5.0'
31
+ version: '5.1'
32
32
  - - "<"
33
33
  - !ruby/object:Gem::Version
34
- version: '5.3'
34
+ version: '6.1'
35
35
  - !ruby/object:Gem::Dependency
36
36
  name: activerecord
37
37
  requirement: !ruby/object:Gem::Requirement
38
38
  requirements:
39
39
  - - ">="
40
40
  - !ruby/object:Gem::Version
41
- version: '5.0'
41
+ version: '5.1'
42
42
  - - "<"
43
43
  - !ruby/object:Gem::Version
44
- version: '5.3'
44
+ version: '6.1'
45
45
  type: :runtime
46
46
  prerelease: false
47
47
  version_requirements: !ruby/object:Gem::Requirement
48
48
  requirements:
49
49
  - - ">="
50
50
  - !ruby/object:Gem::Version
51
- version: '5.0'
51
+ version: '5.1'
52
52
  - - "<"
53
53
  - !ruby/object:Gem::Version
54
- version: '5.3'
54
+ version: '6.1'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: shackles
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
59
  - - "~>"
60
60
  - !ruby/object:Gem::Version
61
- version: '1.3'
61
+ version: 1.4.2
62
62
  type: :runtime
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: '1.3'
68
+ version: 1.4.2
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: open4
71
71
  requirement: !ruby/object:Gem::Requirement
@@ -173,7 +173,6 @@ extra_rdoc_files: []
173
173
  files:
174
174
  - Rakefile
175
175
  - app/models/switchman/shard.rb
176
- - app/models/switchman/shard_internal.rb
177
176
  - db/migrate/20130328212039_create_switchman_shards.rb
178
177
  - db/migrate/20130328224244_create_default_shard.rb
179
178
  - db/migrate/20161206323434_add_back_default_string_limits_switchman.rb
@@ -238,7 +237,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
238
237
  requirements:
239
238
  - - ">="
240
239
  - !ruby/object:Gem::Version
241
- version: '2.3'
240
+ version: '2.4'
242
241
  required_rubygems_version: !ruby/object:Gem::Requirement
243
242
  requirements:
244
243
  - - ">="