switchman 1.14.0 → 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.
- checksums.yaml +4 -4
- data/app/models/switchman/shard.rb +718 -11
- data/lib/switchman/active_record/association.rb +19 -11
- data/lib/switchman/active_record/attribute_methods.rb +3 -0
- data/lib/switchman/active_record/base.rb +31 -2
- data/lib/switchman/active_record/calculations.rb +1 -2
- data/lib/switchman/active_record/connection_handler.rb +17 -6
- data/lib/switchman/active_record/connection_pool.rb +17 -3
- data/lib/switchman/active_record/log_subscriber.rb +8 -12
- data/lib/switchman/active_record/model_schema.rb +1 -1
- data/lib/switchman/active_record/postgresql_adapter.rb +13 -27
- data/lib/switchman/active_record/query_cache.rb +17 -107
- data/lib/switchman/active_record/statement_cache.rb +1 -9
- data/lib/switchman/active_support/cache.rb +16 -0
- data/lib/switchman/connection_pool_proxy.rb +27 -11
- data/lib/switchman/database_server.rb +8 -1
- data/lib/switchman/default_shard.rb +1 -0
- data/lib/switchman/engine.rb +7 -6
- data/lib/switchman/r_spec_helper.rb +2 -2
- data/lib/switchman/version.rb +1 -1
- data/lib/tasks/switchman.rake +17 -4
- metadata +6 -7
- data/app/models/switchman/shard_internal.rb +0 -714
|
@@ -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
|
|
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
|
|
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|
|
data/lib/switchman/version.rb
CHANGED
data/lib/tasks/switchman.rake
CHANGED
|
@@ -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
|
-
|
|
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
|
-
::
|
|
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.
|
|
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:
|
|
13
|
+
date: 2020-05-18 00:00:00.000000000 Z
|
|
14
14
|
dependencies:
|
|
15
15
|
- !ruby/object:Gem::Dependency
|
|
16
16
|
name: railties
|
|
@@ -18,7 +18,7 @@ dependencies:
|
|
|
18
18
|
requirements:
|
|
19
19
|
- - ">="
|
|
20
20
|
- !ruby/object:Gem::Version
|
|
21
|
-
version: '5.
|
|
21
|
+
version: '5.1'
|
|
22
22
|
- - "<"
|
|
23
23
|
- !ruby/object:Gem::Version
|
|
24
24
|
version: '6.1'
|
|
@@ -28,7 +28,7 @@ dependencies:
|
|
|
28
28
|
requirements:
|
|
29
29
|
- - ">="
|
|
30
30
|
- !ruby/object:Gem::Version
|
|
31
|
-
version: '5.
|
|
31
|
+
version: '5.1'
|
|
32
32
|
- - "<"
|
|
33
33
|
- !ruby/object:Gem::Version
|
|
34
34
|
version: '6.1'
|
|
@@ -38,7 +38,7 @@ dependencies:
|
|
|
38
38
|
requirements:
|
|
39
39
|
- - ">="
|
|
40
40
|
- !ruby/object:Gem::Version
|
|
41
|
-
version: '5.
|
|
41
|
+
version: '5.1'
|
|
42
42
|
- - "<"
|
|
43
43
|
- !ruby/object:Gem::Version
|
|
44
44
|
version: '6.1'
|
|
@@ -48,7 +48,7 @@ dependencies:
|
|
|
48
48
|
requirements:
|
|
49
49
|
- - ">="
|
|
50
50
|
- !ruby/object:Gem::Version
|
|
51
|
-
version: '5.
|
|
51
|
+
version: '5.1'
|
|
52
52
|
- - "<"
|
|
53
53
|
- !ruby/object:Gem::Version
|
|
54
54
|
version: '6.1'
|
|
@@ -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
|