switchman 1.12.16 → 1.13.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0b494eb251b67d98437463c5dac44cc3b179365103290a3858ca93925833666c
4
- data.tar.gz: 5d93b3b4142e542721960093e73057ccc8ad1105b67d05e1f7ecd2f4c817c7a6
3
+ metadata.gz: e2f68441314d99fc739f03cd1af70e938efa0d0803ff6f5c405aed15afea0798
4
+ data.tar.gz: 553846718daea03d833792d3ff079ee0ce2bddce63231f2e40262fe901c84949
5
5
  SHA512:
6
- metadata.gz: e447c0c2d8271cdd50dc69ebcc2da5df36089d32bfcd26ad220c61584f1d43679961ecbb3d017f8521742cae8d6780eee291e8e602b7a423ef935e795db6bf75
7
- data.tar.gz: '09051aac58f8bfe85c8f2ae9f645a999daf0f4ad25d24aa3ef095bdf691fba11956423de73b9629b9f39bfe0ebf66c437282e27b69f2907783caaa79b021689e'
6
+ metadata.gz: 4d05aea36873a2d809b414ad9cceeb8e1ee3c0966acd7e67e3f941e3b971c685a3a7ad666d19b5a74edc47ba59025782a486c70c596d918998ef01a01c5b9f40
7
+ data.tar.gz: 02bb3d231398cae6966ec6d8f1ca5ce4101f529d55dc119ebcbd512077ab3c5887c3eb9309fc5a8aba2df7fcd5eb21fae9911c1c2b4c29cfc328653a52fa3d1f
@@ -641,8 +641,6 @@ module Switchman
641
641
  end
642
642
  end
643
643
  end
644
- when 'sqlite3'
645
- File.delete(self.name) unless self.name == ':memory:'
646
644
  end
647
645
  rescue
648
646
  logger.info "Drop failed: #{$!}"
@@ -4,6 +4,11 @@ module Switchman
4
4
  module ClassMethods
5
5
  delegate :shard, to: :all
6
6
 
7
+ def find_ids_in_ranges(opts={}, &block)
8
+ opts.reverse_merge!(:loose => true)
9
+ all.find_ids_in_ranges(opts, &block)
10
+ end
11
+
7
12
  def shard_category
8
13
  connection_specification_name.to_sym
9
14
  end
@@ -67,6 +67,34 @@ module Switchman
67
67
  RUBY
68
68
  end
69
69
 
70
+ def find_ids_in_ranges(options = {})
71
+ is_integer = columns_hash[primary_key.to_s].type == :integer
72
+ loose_mode = options[:loose] && is_integer
73
+ # loose_mode: if we don't care about getting exactly batch_size ids in between
74
+ # don't get the max - just get the min and add batch_size so we get that many _at most_
75
+ values = loose_mode ? "MIN(id)" : "MIN(id), MAX(id)"
76
+
77
+ batch_size = options[:batch_size].try(:to_i) || 1000
78
+ quoted_primary_key = "#{klass.connection.quote_local_table_name(table_name)}.#{klass.connection.quote_column_name(primary_key)}"
79
+ as_id = " AS id" unless primary_key == 'id'
80
+ subquery_scope = except(:select).select("#{quoted_primary_key}#{as_id}").reorder(primary_key.to_sym).limit(loose_mode ? 1 : batch_size)
81
+ subquery_scope = subquery_scope.where("#{quoted_primary_key} <= ?", options[:end_at]) if options[:end_at]
82
+
83
+ first_subquery_scope = options[:start_at] ? subquery_scope.where("#{quoted_primary_key} >= ?", options[:start_at]) : subquery_scope
84
+
85
+ ids = connection.select_rows("SELECT #{values} FROM (#{first_subquery_scope.to_sql}) AS subquery").first
86
+
87
+ while ids.first.present?
88
+ ids.map!(&:to_i) if is_integer
89
+ ids << ids.first + batch_size if loose_mode
90
+
91
+ yield(*ids)
92
+ last_value = ids.last
93
+ next_subquery_scope = subquery_scope.where(["#{quoted_primary_key}>?", last_value])
94
+ ids = connection.select_rows("SELECT #{values} FROM (#{next_subquery_scope.to_sql}) AS subquery").first
95
+ end
96
+ end
97
+
70
98
  def activate(&block)
71
99
  shards = all_shards
72
100
  if (Array === shards && shards.length == 1)
@@ -116,7 +116,7 @@ module Switchman
116
116
  config = config.first if config.is_a?(Array)
117
117
  username = config[:username]
118
118
  end
119
- @shareable = self.config[:adapter] != 'sqlite3' && username !~ /%?\{[a-zA-Z0-9_]+\}/
119
+ @shareable = username !~ /%?\{[a-zA-Z0-9_]+\}/
120
120
  end
121
121
 
122
122
  def shards
@@ -143,8 +143,6 @@ module Switchman
143
143
  when 'postgresql'
144
144
  create_statement = lambda { "CREATE SCHEMA #{name}" }
145
145
  password = " PASSWORD #{::ActiveRecord::Base.connection.quote(config[:password])}" if config[:password]
146
- when 'sqlite3'
147
- # no create_statement
148
146
  else
149
147
  create_statement = lambda { "CREATE DATABASE #{name}" }
150
148
  end
@@ -172,14 +170,10 @@ module Switchman
172
170
 
173
171
  if name.nil?
174
172
  base_name = self.config[:database].to_s % self.config
175
- base_name = $1 if base_name =~ /(?:.*\/)(.+)_shard_\d+(?:\.sqlite3)?$/
176
173
  base_name = nil if base_name == ':memory:'
177
174
  base_name << '_' if base_name
178
175
  base_id = shard_id || SecureRandom.uuid
179
176
  name = "#{base_name}shard_#{base_id}"
180
- if config[:adapter] == 'sqlite3'
181
- name = File.join('db', "#{name}.sqlite3")
182
- end
183
177
  end
184
178
 
185
179
  shard = Shard.create!(:id => shard_id,
@@ -149,7 +149,7 @@ module Switchman
149
149
  end
150
150
 
151
151
  klass.after(:all) do
152
- Shard.delete_all
152
+ Shard.connection.update("TRUNCATE #{Shard.quoted_table_name} CASCADE")
153
153
  Switchman.cache.delete("default_shard")
154
154
  Shard.default(true)
155
155
  end
@@ -1,3 +1,3 @@
1
1
  module Switchman
2
- VERSION = "1.12.16"
2
+ VERSION = "1.13.0"
3
3
  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: 1.12.16
4
+ version: 1.13.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-01-15 00:00:00.000000000 Z
13
+ date: 2019-02-27 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: railties
@@ -150,20 +150,6 @@ dependencies:
150
150
  - - "~>"
151
151
  - !ruby/object:Gem::Version
152
152
  version: '0.15'
153
- - !ruby/object:Gem::Dependency
154
- name: sqlite3
155
- requirement: !ruby/object:Gem::Requirement
156
- requirements:
157
- - - "~>"
158
- - !ruby/object:Gem::Version
159
- version: '1.3'
160
- type: :development
161
- prerelease: false
162
- version_requirements: !ruby/object:Gem::Requirement
163
- requirements:
164
- - - "~>"
165
- - !ruby/object:Gem::Version
166
- version: '1.3'
167
153
  - !ruby/object:Gem::Dependency
168
154
  name: rake
169
155
  requirement: !ruby/object:Gem::Requirement