switchman 1.5.7 → 1.5.8

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9a061d43139c6beef4a69af819d1797a7d14650d
4
- data.tar.gz: 4efbe1614848d2d2ba0e23d8bc8b993ff44a9fc9
3
+ metadata.gz: 6d7676d7b016d87da297714bb0ac6c4e6b2d2114
4
+ data.tar.gz: 67746d37c000d95e9f59a8be237a3a602b8d2e89
5
5
  SHA512:
6
- metadata.gz: 423e156b64348617b371ff59e042db181a69eda6a64bae54c5823b4e8e6e4f35b0ed748c4ee2f6e4d462bd17501f6bd417c881d3edb6c21266f7421650716d15
7
- data.tar.gz: 8ced56c4ab5bf0327b98d8fa4d25b228b02badb181866f722d79cce44eece0148f1b0dd328ec93a91181d7802a65123cd1c3e33d2811a35115bdae95a18eb83b
6
+ metadata.gz: 3dfceefb5d04a739ac608d547f502133d0f3fa0185b17092087c9b2b2526c2bf947f8aa1657448341302cf4ce706b1b95cbc8110f738e62d752a0be409ea6f30
7
+ data.tar.gz: d1a2c684c4e720ed9e3e1777ac7c343ff83a9d8871e458b4644f8d1280ebec0bbfd52cd147d35ae9fec790599093623657209268efe43995e2ab01542e2bb12d
@@ -27,6 +27,10 @@ module Switchman
27
27
  quote_table_name(name)
28
28
  end
29
29
 
30
+ def use_qualified_names?
31
+ false
32
+ end
33
+
30
34
  protected
31
35
 
32
36
  def log(*args, &block)
@@ -180,6 +180,40 @@ module Switchman
180
180
  name.quoted
181
181
  end
182
182
  end
183
+
184
+ if ::Rails.version >= '4.2'
185
+ def foreign_keys(table_name)
186
+ schema = shard.name if use_qualified_names?
187
+
188
+ # mostly copy-pasted from AR - only change is to the nspname condition for qualified names support
189
+ fk_info = select_all <<-SQL.strip_heredoc
190
+ SELECT t2.oid::regclass::text AS to_table, a1.attname AS column, a2.attname AS primary_key, c.conname AS name, c.confupdtype AS on_update, c.confdeltype AS on_delete
191
+ FROM pg_constraint c
192
+ JOIN pg_class t1 ON c.conrelid = t1.oid
193
+ JOIN pg_class t2 ON c.confrelid = t2.oid
194
+ JOIN pg_attribute a1 ON a1.attnum = c.conkey[1] AND a1.attrelid = t1.oid
195
+ JOIN pg_attribute a2 ON a2.attnum = c.confkey[1] AND a2.attrelid = t2.oid
196
+ JOIN pg_namespace t3 ON c.connamespace = t3.oid
197
+ WHERE c.contype = 'f'
198
+ AND t1.relname = #{quote(table_name)}
199
+ AND t3.nspname = #{schema ? "'#{schema}'" : 'ANY (current_schemas(false))'}
200
+ ORDER BY c.conname
201
+ SQL
202
+
203
+ fk_info.map do |row|
204
+ options = {
205
+ column: row['column'],
206
+ name: row['name'],
207
+ primary_key: row['primary_key']
208
+ }
209
+
210
+ options[:on_delete] = extract_foreign_key_action(row['on_delete'])
211
+ options[:on_update] = extract_foreign_key_action(row['on_update'])
212
+
213
+ ::ActiveRecord::ConnectionAdapters::ForeignKeyDefinition.new(table_name, row['to_table'], options)
214
+ end
215
+ end
216
+ end
183
217
  end
184
218
  end
185
219
  end
@@ -91,6 +91,19 @@ module Switchman
91
91
  end
92
92
  end
93
93
 
94
+ if ::Rails.version >= '4.2' && ::Rails.version < '5'
95
+ # fixes an issue in Rails 4.2 with `reverse_sql_order` and qualified names
96
+ # where quoted_table_name is called before shard(s) have been activated
97
+ # if there's no ordering
98
+ def reverse_order!
99
+ orders = order_values.uniq
100
+ orders.reject!(&:blank?)
101
+ orders = [arel_table[primary_key].desc] if orders.empty?
102
+
103
+ self.order_values = reverse_sql_order(orders)
104
+ self
105
+ end
106
+ end
94
107
 
95
108
  private
96
109
 
@@ -1,3 +1,3 @@
1
1
  module Switchman
2
- VERSION = "1.5.7"
2
+ VERSION = "1.5.8"
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.5.7
4
+ version: 1.5.8
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: 2016-06-09 00:00:00.000000000 Z
13
+ date: 2016-06-10 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: railties