switchman 3.0.0 → 3.0.7

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.
@@ -111,28 +111,12 @@ module Switchman
111
111
  Shard.default(reload: true)
112
112
  @shard1 = Shard.find(@shard1.id)
113
113
  @shard2 = Shard.find(@shard2.id)
114
- shards = [@shard2]
115
- shards << @shard1 unless @shard1.database_server == Shard.default.database_server
116
- shards.each do |shard|
117
- shard.activate do
118
- ::ActiveRecord::Base.connection.begin_transaction joinable: false
119
- end
120
- end
121
114
  end
122
115
  end
123
116
 
124
117
  klass.after do
125
118
  next if @@sharding_failed
126
119
 
127
- if use_transactional_tests
128
- shards = [@shard2]
129
- shards << @shard1 unless @shard1.database_server == Shard.default.database_server
130
- shards.each do |shard|
131
- shard.activate do
132
- ::ActiveRecord::Base.connection.rollback_transaction if ::ActiveRecord::Base.connection.transaction_open?
133
- end
134
- end
135
- end
136
120
  # clean up after specs
137
121
  DatabaseServer.all.each do |ds|
138
122
  if ds.fake? && ds != @shard2.database_server
@@ -143,7 +127,8 @@ module Switchman
143
127
  end
144
128
 
145
129
  klass.after(:all) do
146
- Shard.connection.update("TRUNCATE #{Shard.quoted_table_name} CASCADE")
130
+ # Don't truncate because that can create some fun cross-connection lock contention
131
+ Shard.delete_all
147
132
  Switchman.cache.delete('default_shard')
148
133
  Shard.default(reload: true)
149
134
  end
@@ -10,10 +10,10 @@ module Switchman
10
10
  return
11
11
  end
12
12
 
13
- if defined?(Shard)
14
- @active_shards = Shard.sharded_models.map do |klass|
15
- [klass, Shard.current(klass)]
16
- end.compact.to_h
13
+ begin
14
+ @active_shards = Shard.active_shards if defined?(Shard)
15
+ rescue ::ActiveRecord::ConnectionNotEstablished
16
+ # If we hit an error really early in boot, activerecord may not be initialized yet
17
17
  end
18
18
 
19
19
  super
@@ -19,7 +19,7 @@ module Switchman
19
19
  end
20
20
 
21
21
  server1 = Shard.default.database_server
22
- server2 = DatabaseServer.create(Shard.default.database_server.config)
22
+ server2 = DatabaseServer.create(Shard.default.database_server.config.merge(server2: true))
23
23
 
24
24
  if server1 == Shard.default.database_server && server1.config[:shard1] && server1.config[:shard2]
25
25
  # look for the shards in the db already
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Switchman
4
- VERSION = '3.0.0'
4
+ VERSION = '3.0.7'
5
5
  end
data/lib/switchman.rb CHANGED
@@ -17,4 +17,6 @@ module Switchman
17
17
  def self.cache=(cache)
18
18
  @cache = cache
19
19
  end
20
+
21
+ class OrderOnMultiShardQuery < RuntimeError; end
20
22
  end
@@ -46,7 +46,7 @@ module Switchman
46
46
  end
47
47
 
48
48
  def self.options
49
- { parallel: ENV['PARALLEL'].to_i, max_procs: ENV['MAX_PARALLEL_PROCS'] }
49
+ { parallel: ENV['PARALLEL'].to_i }
50
50
  end
51
51
 
52
52
  # classes - an array or proc, to activate as the current shard during the
@@ -80,14 +80,14 @@ module Switchman
80
80
  puts "Exception from #{e.current_shard.id}: #{e.current_shard.description}" if options[:parallel] != 0
81
81
  raise
82
82
 
83
- #::ActiveRecord::Base.configurations = old_configurations
83
+ # ::ActiveRecord::Base.configurations = old_configurations
84
84
  end
85
85
  end
86
86
  end
87
87
  end
88
88
 
89
89
  %w[db:migrate db:migrate:up db:migrate:down db:rollback].each do |task_name|
90
- shardify_task(task_name, classes: -> { Shard.sharded_models })
90
+ shardify_task(task_name)
91
91
  end
92
92
 
93
93
  def self.shard_scope(scope, raw_shard_ids)
@@ -201,14 +201,18 @@ module Switchman
201
201
  module PostgreSQLDatabaseTasks
202
202
  def structure_dump(filename, extra_flags = nil)
203
203
  set_psql_env
204
- args = ['-s', '-x', '-O', '-f', filename]
204
+ args = ['--schema-only', '--no-privileges', '--no-owner', '--file', filename]
205
205
  args.concat(Array(extra_flags)) if extra_flags
206
206
  shard = Shard.current.name
207
207
  serialized_search_path = shard
208
208
  args << "--schema=#{Shellwords.escape(shard)}"
209
209
 
210
- args << configuration['database']
210
+ ignore_tables = ::ActiveRecord::SchemaDumper.ignore_tables
211
+ args += ignore_tables.flat_map { |table| ['-T', table] } if ignore_tables.any?
212
+
213
+ args << db_config.database
211
214
  run_cmd('pg_dump', args, 'dumping')
215
+ remove_sql_header_comments(filename)
212
216
  File.open(filename, 'a') { |f| f << "SET search_path TO #{serialized_search_path};\n\n" }
213
217
  end
214
218
  end
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: 3.0.0
4
+ version: 3.0.7
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: 2021-03-17 00:00:00.000000000 Z
13
+ date: 2022-02-23 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: activerecord
@@ -18,7 +18,7 @@ dependencies:
18
18
  requirements:
19
19
  - - ">="
20
20
  - !ruby/object:Gem::Version
21
- version: '6.1'
21
+ version: 6.1.4
22
22
  - - "<"
23
23
  - !ruby/object:Gem::Version
24
24
  version: '6.2'
@@ -28,7 +28,7 @@ dependencies:
28
28
  requirements:
29
29
  - - ">="
30
30
  - !ruby/object:Gem::Version
31
- version: '6.1'
31
+ version: 6.1.4
32
32
  - - "<"
33
33
  - !ruby/object:Gem::Version
34
34
  version: '6.2'
@@ -86,14 +86,14 @@ dependencies:
86
86
  requirements:
87
87
  - - "~>"
88
88
  - !ruby/object:Gem::Version
89
- version: '2.1'
89
+ version: 2.3.0
90
90
  type: :development
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
94
  - - "~>"
95
95
  - !ruby/object:Gem::Version
96
- version: '2.1'
96
+ version: 2.3.0
97
97
  - !ruby/object:Gem::Dependency
98
98
  name: byebug
99
99
  requirement: !ruby/object:Gem::Requirement
@@ -275,6 +275,7 @@ files:
275
275
  - lib/switchman/active_record/statement_cache.rb
276
276
  - lib/switchman/active_record/table_definition.rb
277
277
  - lib/switchman/active_record/tasks/database_tasks.rb
278
+ - lib/switchman/active_record/test_fixtures.rb
278
279
  - lib/switchman/active_record/type_caster.rb
279
280
  - lib/switchman/active_support/cache.rb
280
281
  - lib/switchman/arel.rb
@@ -289,7 +290,6 @@ files:
289
290
  - lib/switchman/open4.rb
290
291
  - lib/switchman/r_spec_helper.rb
291
292
  - lib/switchman/rails.rb
292
- - lib/switchman/schema_cache.rb
293
293
  - lib/switchman/sharded_instrumenter.rb
294
294
  - lib/switchman/standard_error.rb
295
295
  - lib/switchman/test_helper.rb
@@ -298,7 +298,8 @@ files:
298
298
  homepage: http://www.instructure.com/
299
299
  licenses:
300
300
  - MIT
301
- metadata: {}
301
+ metadata:
302
+ rubygems_mfa_required: 'true'
302
303
  post_install_message:
303
304
  rdoc_options: []
304
305
  require_paths:
@@ -1,20 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Switchman
4
- class SchemaCache < ::ActiveRecord::ConnectionAdapters::SchemaCache
5
- delegate :connection, to: :pool
6
- attr_reader :pool
7
-
8
- def initialize(pool)
9
- @pool = pool
10
- super(nil)
11
- end
12
-
13
- def copy_values(other_cache)
14
- # use the same cached values but still fall back to the correct pool
15
- %i[@columns @columns_hash @primary_keys @data_sources].each do |iv|
16
- instance_variable_set(iv, other_cache.instance_variable_get(iv))
17
- end
18
- end
19
- end
20
- end