switchman 1.7.4 → 1.8.0

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: 2287cafb5c656fc9033e4549edec54e5497977b5
4
- data.tar.gz: 0a5c7fb962a37016087842675dfc37f90ccd697b
3
+ metadata.gz: e86d6e07988c45f8c70c42c92ece5263797af099
4
+ data.tar.gz: 624f54c1a3735b12050b977177076fc3fc870027
5
5
  SHA512:
6
- metadata.gz: 9c6200530e3662721b2eb0f66dee5107f9d8200fbd90229974d3be29d875d8328c71b9971b5d1e6a39d69e02e74fe2c7491c81630a4fa0c9e01ea58dff6b3067
7
- data.tar.gz: 9044787290f4ce2bca81c26cba8c83c6ee4284fbea4afcf17223a8586d333e4bd119fd2472cbaadaee77701b58dc5ab839d367f070e257db1d2be6285f682914
6
+ metadata.gz: f30d8b5ee490486c13a4f800a09c2bc29ba266e98e839980242562b46f0e0e080e68d7039019d5a69e7944d232829bd592521e86f7206e5bd35cf42cf360a208
7
+ data.tar.gz: 9e3b24c5493efce7a36e5da23a0dc471dc878a034125e8304dccb05c7beabef5daa009c87360f5e1c5bc9293f5b3892a5a624a86fffcbdea40fca44bb7878f8c
@@ -115,13 +115,7 @@ module Switchman
115
115
  attributes = Switchman.cache.fetch(['shard', id].join('/')) do
116
116
  shard = find_by_id(id)
117
117
  if shard
118
- attributes = shard.attributes
119
- if ::Rails.version < '4.2'
120
- attributes.each_key do |key|
121
- attributes[key] = attributes[key].unserialize if attributes[key].is_a?(::ActiveRecord::AttributeMethods::Serialization::Attribute)
122
- end
123
- end
124
- attributes
118
+ shard.attributes
125
119
  else
126
120
  :nil
127
121
  end
@@ -435,7 +429,7 @@ module Switchman
435
429
  # converts an AR object, integral id, string id, or string short-global-id to a
436
430
  # integral id. nil if it can't be interpreted
437
431
  def integral_id_for(any_id)
438
- if ::Rails.version >= '4.2' && any_id.is_a?(::Arel::Nodes::Casted)
432
+ if any_id.is_a?(::Arel::Nodes::Casted)
439
433
  any_id = any_id.val
440
434
  end
441
435
 
@@ -137,9 +137,7 @@ module Switchman
137
137
  records.flatten!
138
138
  end
139
139
 
140
- if ::Rails.version >= '4.1'
141
- @preloaded_records = records
142
- end
140
+ @preloaded_records = records
143
141
 
144
142
  # Each record may have multiple owners, and vice-versa
145
143
  records_by_owner = owners.each_with_object({}) do |owner,h|
@@ -61,12 +61,12 @@ module Switchman
61
61
  initial_results = relation.activate{ |rel| klass.connection.select_all(rel) }
62
62
  if initial_results.is_a?(Array)
63
63
  initial_results.each do |r|
64
- r["average"] = type_cast_calculated_value(r["average"], column_or_type_for(column_name), "average")
65
- r["count"] = type_cast_calculated_value(r["count"], column_or_type_for(column_name), "count")
64
+ r["average"] = type_cast_calculated_value(r["average"], type_for(column_name), "average")
65
+ r["count"] = type_cast_calculated_value(r["count"], type_for(column_name), "count")
66
66
  end
67
67
  result = initial_results.map{|r| r["average"] * r["count"]}.sum / initial_results.map{|r| r["count"]}.sum
68
68
  else
69
- result = type_cast_calculated_value(initial_results.first["average"], column_or_type_for(column_name), "average")
69
+ result = type_cast_calculated_value(initial_results.first["average"], type_for(column_name), "average")
70
70
  end
71
71
  result
72
72
  end
@@ -89,14 +89,14 @@ module Switchman
89
89
 
90
90
  calculated_data.map do |row|
91
91
  row[opts[:aggregate_alias]] = type_cast_calculated_value(
92
- row[opts[:aggregate_alias]], column_or_type_for(opts[:column_name]), opts[:operation])
92
+ row[opts[:aggregate_alias]], type_for(opts[:column_name]), opts[:operation])
93
93
  row['count'] = row['count'].to_i if opts[:operation] == 'average'
94
94
 
95
- opts[:group_columns].each do |aliaz, column_or_type, column_name|
95
+ opts[:group_columns].each do |aliaz, type, column_name|
96
96
  if opts[:associated] && (aliaz == opts[:group_aliases].first)
97
97
  row[aliaz] = key_records[Shard.relative_id_for(row[aliaz], shard, target_shard)]
98
98
  elsif column_name && @klass.sharded_column?(column_name)
99
- row[aliaz] = Shard.relative_id_for(type_cast_calculated_value(row[aliaz], column_or_type), shard, target_shard)
99
+ row[aliaz] = Shard.relative_id_for(type_cast_calculated_value(row[aliaz], type), shard, target_shard)
100
100
  end
101
101
  end
102
102
  row
@@ -112,10 +112,6 @@ module Switchman
112
112
  field.respond_to?(:name) ? field.name.to_s : field.to_s.split('.').last
113
113
  end
114
114
 
115
- def column_or_type_for(field)
116
- ::Rails.version < '4.2' ? column_for(field) : type_for(field)
117
- end
118
-
119
115
  def grouped_calculation_options(operation, column_name, distinct)
120
116
  opts = {:operation => operation, :column_name => column_name, :distinct => distinct}
121
117
 
@@ -131,7 +127,7 @@ module Switchman
131
127
 
132
128
  group_aliases = group_fields.map { |field| column_alias_for(field) }
133
129
  group_columns = group_aliases.zip(group_fields).map { |aliaz, field|
134
- [aliaz, column_or_type_for(field), column_name_for(field)]
130
+ [aliaz, type_for(field), column_name_for(field)]
135
131
  }
136
132
  opts.merge!(:association => association, :associated => associated,
137
133
  :group_aliases => group_aliases, :group_columns => group_columns,
@@ -26,19 +26,7 @@ module Switchman
26
26
 
27
27
  local_id, shard = Shard.local_id_for(id)
28
28
  if shard
29
- if ::Rails.version < '4.2'
30
- # find_one uses binds, so we can't depend on QueryMethods
31
- # catching it
32
- begin
33
- old_shard_value = shard_value
34
- self.shard_value = shard
35
- super(local_id)
36
- ensure
37
- self.shard_value = old_shard_value
38
- end
39
- else
40
- shard.activate { super(local_id) }
41
- end
29
+ shard.activate { super(local_id) }
42
30
  else
43
31
  super(id)
44
32
  end
@@ -52,13 +40,8 @@ module Switchman
52
40
  conditions = conditions.id if ::ActiveRecord::Base === conditions
53
41
  return false if !conditions
54
42
 
55
- if ::Rails.version >= '4.1'
56
- relation = apply_join_dependency(self, construct_join_dependency)
57
- return false if ::ActiveRecord::NullRelation === relation
58
- else
59
- join_dependency = construct_join_dependency_for_association_find
60
- relation = construct_relation_for_association_find(join_dependency)
61
- end
43
+ relation = apply_join_dependency(self, construct_join_dependency)
44
+ return false if ::ActiveRecord::NullRelation === relation
62
45
 
63
46
  relation = relation.except(:select, :order).select("1 AS one").limit(1)
64
47
 
@@ -70,12 +53,9 @@ module Switchman
70
53
  end
71
54
 
72
55
  args = [relation, "#{name} Exists"]
73
- args << relation.bind_values if ::Rails.version >= '4.1'
56
+ args << relation.bind_values
74
57
  relation.activate { return true if connection.select_value(*args) }
75
58
  false
76
- rescue
77
- raise if ::Rails.version >= '4.1' || !(::ActiveRecord::ThrowResult === $!)
78
- false
79
59
  end
80
60
  end
81
61
  end
@@ -57,38 +57,20 @@ module Switchman
57
57
  end
58
58
 
59
59
  def table_exists?(name)
60
- if ::Rails.version < '4.2'
61
- schema, table = ::ActiveRecord::ConnectionAdapters::PostgreSQLAdapter::Utils.extract_schema_and_table(name.to_s)
62
- return false unless table
63
- schema ||= shard.name if use_qualified_names?
64
-
65
- binds = [[nil, table]]
66
- binds << [nil, schema] if schema
67
-
68
- exec_query(<<-SQL, 'SCHEMA').rows.first[0].to_i > 0
69
- SELECT COUNT(*)
70
- FROM pg_class c
71
- LEFT JOIN pg_namespace n ON n.oid = c.relnamespace
72
- WHERE c.relkind in ('v','r')
73
- AND c.relname = '#{table.gsub(/(^"|"$)/,'')}'
74
- AND n.nspname = #{schema ? "'#{schema}'" : 'ANY (current_schemas(false))'}
75
- SQL
76
- else
77
- name = ::ActiveRecord::ConnectionAdapters::PostgreSQL::Utils.extract_schema_qualified_name(name.to_s)
78
- return false unless name.identifier
79
- if !name.schema && use_qualified_names?
80
- name.instance_variable_set(:@schema, shard.name)
81
- end
82
-
83
- exec_query(<<-SQL, 'SCHEMA').rows.first[0].to_i > 0
84
- SELECT COUNT(*)
85
- FROM pg_class c
86
- LEFT JOIN pg_namespace n ON n.oid = c.relnamespace
87
- WHERE c.relkind IN ('r','v','m') -- (r)elation/table, (v)iew, (m)aterialized view
88
- AND c.relname = '#{name.identifier}'
89
- AND n.nspname = #{name.schema ? "'#{name.schema}'" : 'ANY (current_schemas(false))'}
90
- SQL
60
+ name = ::ActiveRecord::ConnectionAdapters::PostgreSQL::Utils.extract_schema_qualified_name(name.to_s)
61
+ return false unless name.identifier
62
+ if !name.schema && use_qualified_names?
63
+ name.instance_variable_set(:@schema, shard.name)
91
64
  end
65
+
66
+ exec_query(<<-SQL, 'SCHEMA').rows.first[0].to_i > 0
67
+ SELECT COUNT(*)
68
+ FROM pg_class c
69
+ LEFT JOIN pg_namespace n ON n.oid = c.relnamespace
70
+ WHERE c.relkind IN ('r','v','m') -- (r)elation/table, (v)iew, (m)aterialized view
71
+ AND c.relname = '#{name.identifier}'
72
+ AND n.nspname = #{name.schema ? "'#{name.schema}'" : 'ANY (current_schemas(false))'}
73
+ SQL
92
74
  end
93
75
 
94
76
  def indexes(table_name)
@@ -158,60 +140,42 @@ module Switchman
158
140
  end
159
141
 
160
142
  def quote_table_name name
161
- if ::Rails.version < '4.2'.freeze
162
- schema, name_part = extract_pg_identifier_from_name(name.to_s)
163
-
164
- if !name_part && use_qualified_names? && shard.name
165
- schema, name_part = shard.name, schema
166
- end
167
-
168
- unless name_part
169
- quote_column_name(schema)
170
- else
171
- table_name, name_part = extract_pg_identifier_from_name(name_part)
172
- "#{quote_column_name(schema)}.#{quote_column_name(table_name)}"
173
- end
174
- else
175
-
176
- name = ::ActiveRecord::ConnectionAdapters::PostgreSQL::Utils.extract_schema_qualified_name(name.to_s)
177
- if !name.schema && use_qualified_names?
178
- name.instance_variable_set(:@schema, shard.name)
179
- end
180
- name.quoted
143
+ name = ::ActiveRecord::ConnectionAdapters::PostgreSQL::Utils.extract_schema_qualified_name(name.to_s)
144
+ if !name.schema && use_qualified_names?
145
+ name.instance_variable_set(:@schema, shard.name)
181
146
  end
147
+ name.quoted
182
148
  end
183
149
 
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
150
+ def foreign_keys(table_name)
151
+ schema = shard.name if use_qualified_names?
152
+
153
+ # mostly copy-pasted from AR - only change is to the nspname condition for qualified names support
154
+ fk_info = select_all <<-SQL.strip_heredoc
155
+ 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
156
+ FROM pg_constraint c
157
+ JOIN pg_class t1 ON c.conrelid = t1.oid
158
+ JOIN pg_class t2 ON c.confrelid = t2.oid
159
+ JOIN pg_attribute a1 ON a1.attnum = c.conkey[1] AND a1.attrelid = t1.oid
160
+ JOIN pg_attribute a2 ON a2.attnum = c.confkey[1] AND a2.attrelid = t2.oid
161
+ JOIN pg_namespace t3 ON c.connamespace = t3.oid
162
+ WHERE c.contype = 'f'
163
+ AND t1.relname = #{quote(table_name)}
164
+ AND t3.nspname = #{schema ? "'#{schema}'" : 'ANY (current_schemas(false))'}
165
+ ORDER BY c.conname
166
+ SQL
202
167
 
203
- fk_info.map do |row|
204
- options = {
205
- column: row['column'],
206
- name: row['name'],
207
- primary_key: row['primary_key']
208
- }
168
+ fk_info.map do |row|
169
+ options = {
170
+ column: row['column'],
171
+ name: row['name'],
172
+ primary_key: row['primary_key']
173
+ }
209
174
 
210
- options[:on_delete] = extract_foreign_key_action(row['on_delete'])
211
- options[:on_update] = extract_foreign_key_action(row['on_update'])
175
+ options[:on_delete] = extract_foreign_key_action(row['on_delete'])
176
+ options[:on_update] = extract_foreign_key_action(row['on_update'])
212
177
 
213
- ::ActiveRecord::ConnectionAdapters::ForeignKeyDefinition.new(table_name, row['to_table'], options)
214
- end
178
+ ::ActiveRecord::ConnectionAdapters::ForeignKeyDefinition.new(table_name, row['to_table'], options)
215
179
  end
216
180
  end
217
181
  end
@@ -55,7 +55,6 @@ module Switchman
55
55
  if rel.shard_source_value == :implicit && rel.primary_shard != primary_shard
56
56
  rel.shard!(primary_shard)
57
57
  end
58
- self.bind_values += rel.bind_values if ::Rails.version < '4.2'
59
58
  end
60
59
 
61
60
  [@klass.send(:sanitize_sql, other.empty? ? opts : ([opts] + other))]
@@ -104,7 +103,7 @@ module Switchman
104
103
  end
105
104
  end
106
105
 
107
- if ::Rails.version >= '4.2' && ::Rails.version < '5'
106
+ if ::Rails.version < '5'
108
107
  # fixes an issue in Rails 4.2 with `reverse_sql_order` and qualified names
109
108
  # where quoted_table_name is called before shard(s) have been activated
110
109
  # if there's no ordering
@@ -192,7 +191,7 @@ module Switchman
192
191
  else
193
192
  if bind_values && idx = bind_values.find_index{|b| b.is_a?(Array) && b.first.try(:name).to_s == klass.primary_key.to_s}
194
193
  column, value = bind_values[idx]
195
- unless ::Rails.version >= '4.2' && value.is_a?(::ActiveRecord::StatementCache::Substitute)
194
+ unless value.is_a?(::ActiveRecord::StatementCache::Substitute)
196
195
  local_id, id_shard = Shard.local_id_for(value)
197
196
  id_shard ||= Shard.current(klass.shard_category) if local_id
198
197
  end
@@ -299,7 +298,7 @@ module Switchman
299
298
  local_id = Shard.relative_id_for(value, current_source_shard, target_shard)
300
299
  next unless local_id
301
300
  unless remove && local_id > Shard::IDS_PER_SHARD
302
- if ::Rails.version > "4.2" && value.is_a?(::Arel::Nodes::Casted)
301
+ if value.is_a?(::Arel::Nodes::Casted)
303
302
  if local_id == value.val
304
303
  local_id = value
305
304
  elsif local_id != value
@@ -328,7 +327,7 @@ module Switchman
328
327
  else
329
328
  if bind_values && idx = bind_values.find_index{|b| b.is_a?(Array) && b.first.try(:name).to_s == predicate.left.name.to_s}
330
329
  column, value = bind_values[idx]
331
- if ::Rails.version >= '4.2' && value.is_a?(::ActiveRecord::StatementCache::Substitute)
330
+ if value.is_a?(::ActiveRecord::StatementCache::Substitute)
332
331
  value.sharded = true # mark for transposition later
333
332
  value.primary = true if type == :primary
334
333
  else
@@ -347,7 +346,7 @@ module Switchman
347
346
 
348
347
  if new_right_value == predicate.right
349
348
  predicate
350
- elsif ::Rails.version >= "4.2" && predicate.right.is_a?(::Arel::Nodes::Casted)
349
+ elsif predicate.right.is_a?(::Arel::Nodes::Casted)
351
350
  if new_right_value == predicate.right.val
352
351
  predicate
353
352
  else
@@ -41,16 +41,8 @@ module Switchman
41
41
  end
42
42
 
43
43
  module AssociationReflection
44
- # removes memoization - ActiveRecord::ModelSchema does that anyway;
45
- # and in fact this is the exact change AR makes in 4.2+
46
- if ::Rails.version < '4.2'
47
- def quoted_table_name
48
- klass.quoted_table_name
49
- end
50
- else
51
- def join_id_for(owner)
52
- owner.send(active_record_primary_key) # use sharded id values in association binds
53
- end
44
+ def join_id_for(owner)
45
+ owner.send(active_record_primary_key) # use sharded id values in association binds
54
46
  end
55
47
  end
56
48
  end
@@ -12,24 +12,17 @@ module Switchman
12
12
  module Visitors
13
13
  module ToSql
14
14
  def visit_Arel_Nodes_TableAlias *args
15
- if ::Rails.version < '4.2'
16
- o = args.shift
17
- "#{visit o.relation, *args} #{quote_local_table_name o.name}"
18
- else
19
- o, collector = args
20
- collector = visit o.relation, collector
21
- collector << " "
22
- collector << quote_local_table_name(o.name)
23
- end
15
+ o, collector = args
16
+ collector = visit o.relation, collector
17
+ collector << " "
18
+ collector << quote_local_table_name(o.name)
24
19
  end
25
20
 
26
21
  def visit_Arel_Attributes_Attribute *args
27
22
  o = args.first
28
23
  join_name = o.relation.table_alias || o.relation.name
29
24
  result = "#{quote_local_table_name join_name}.#{quote_column_name o.name}"
30
- unless ::Rails.version < '4.2'.freeze
31
- result = args.last << result
32
- end
25
+ result = args.last << result
33
26
  result
34
27
  end
35
28
 
@@ -38,14 +31,6 @@ module Switchman
38
31
  @connection.quote_local_table_name(name)
39
32
  end
40
33
  end
41
-
42
- module PostgreSQL
43
- # the only difference is to remove caching (which only applies to Arel < 6.0/AR < 4.2)
44
- def quote_table_name name
45
- return name if ::Arel::Nodes::SqlLiteral === name
46
- @connection.quote_table_name(name)
47
- end
48
- end
49
34
  end
50
35
  end
51
36
  end
@@ -80,8 +80,9 @@ module Switchman
80
80
  require "switchman/active_record/reflection"
81
81
  require "switchman/active_record/relation"
82
82
  require "switchman/active_record/spawn_methods"
83
- require "switchman/active_record/where_clause_factory"
83
+ require "switchman/active_record/statement_cache"
84
84
  require "switchman/active_record/type_caster"
85
+ require "switchman/active_record/where_clause_factory"
85
86
  require "switchman/arel"
86
87
  require "switchman/rails"
87
88
  require "switchman/shackles/relation"
@@ -95,23 +96,16 @@ module Switchman
95
96
  include ActiveRecord::Persistence
96
97
  singleton_class.prepend ActiveRecord::ModelSchema::ClassMethods
97
98
 
98
- if ::Rails.version > '4.2'
99
- require "switchman/active_record/statement_cache"
100
- ::ActiveRecord::StatementCache.prepend(ActiveRecord::StatementCache)
101
- ::ActiveRecord::StatementCache.singleton_class.prepend(ActiveRecord::StatementCache::ClassMethods)
102
- ::ActiveRecord::StatementCache::BindMap.prepend(ActiveRecord::StatementCache::BindMap)
103
- ::ActiveRecord::StatementCache::Substitute.send(:attr_accessor, :primary, :sharded)
99
+ ::ActiveRecord::StatementCache.prepend(ActiveRecord::StatementCache)
100
+ ::ActiveRecord::StatementCache.singleton_class.prepend(ActiveRecord::StatementCache::ClassMethods)
101
+ ::ActiveRecord::StatementCache::BindMap.prepend(ActiveRecord::StatementCache::BindMap)
102
+ ::ActiveRecord::StatementCache::Substitute.send(:attr_accessor, :primary, :sharded)
104
103
 
105
- ::ActiveRecord::Associations::CollectionAssociation.prepend(ActiveRecord::CollectionAssociation)
106
- end
104
+ ::ActiveRecord::Associations::CollectionAssociation.prepend(ActiveRecord::CollectionAssociation)
107
105
 
108
- if ::Rails.version >= '4.1.15'
109
- ::ActiveRecord::PredicateBuilder.singleton_class.prepend(ActiveRecord::PredicateBuilder)
110
- end
106
+ ::ActiveRecord::PredicateBuilder.singleton_class.prepend(ActiveRecord::PredicateBuilder)
111
107
 
112
- if ::Rails.version > '4.1'
113
- prepend(ActiveRecord::AutosaveAssociation)
114
- end
108
+ prepend(ActiveRecord::AutosaveAssociation)
115
109
 
116
110
  ::ActiveRecord::Associations::Association.prepend(ActiveRecord::Association)
117
111
  ::ActiveRecord::Associations::BelongsToAssociation.prepend(ActiveRecord::BelongsToAssociation)
@@ -132,13 +126,9 @@ module Switchman
132
126
  ::ActiveRecord::ConnectionAdapters::QueryCache.send(:remove_method, :select_all)
133
127
 
134
128
  ::ActiveRecord::LogSubscriber.prepend(ActiveRecord::LogSubscriber)
135
- if ::Rails.version >= '4.2'
136
- ::ActiveRecord::Reflection::AbstractReflection.include(ActiveRecord::Reflection::AbstractReflection)
137
- ::ActiveRecord::Reflection::AssociationReflection.prepend(ActiveRecord::Reflection::AssociationScopeCache)
138
- ::ActiveRecord::Reflection::ThroughReflection.prepend(ActiveRecord::Reflection::AssociationScopeCache)
139
- else
140
- ::ActiveRecord::Reflection::AssociationReflection.include(ActiveRecord::Reflection::AbstractReflection)
141
- end
129
+ ::ActiveRecord::Reflection::AbstractReflection.include(ActiveRecord::Reflection::AbstractReflection)
130
+ ::ActiveRecord::Reflection::AssociationReflection.prepend(ActiveRecord::Reflection::AssociationScopeCache)
131
+ ::ActiveRecord::Reflection::ThroughReflection.prepend(ActiveRecord::Reflection::AssociationScopeCache)
142
132
  ::ActiveRecord::Reflection::AssociationReflection.prepend(ActiveRecord::Reflection::AssociationReflection)
143
133
  ::ActiveRecord::Relation.prepend(ActiveRecord::Batches)
144
134
  ::ActiveRecord::Relation.prepend(ActiveRecord::Calculations)
@@ -159,7 +149,6 @@ module Switchman
159
149
 
160
150
  ::Arel::Table.prepend(Arel::Table)
161
151
  ::Arel::Visitors::ToSql.prepend(Arel::Visitors::ToSql)
162
- ::Arel::Visitors::PostgreSQL.include(Arel::Visitors::PostgreSQL) if ::Rails.version < '4.2'
163
152
  end
164
153
  end
165
154
 
@@ -1,3 +1,3 @@
1
1
  module Switchman
2
- VERSION = "1.7.4"
2
+ VERSION = "1.8.0"
3
3
  end
@@ -198,58 +198,37 @@ end
198
198
  module Switchman
199
199
  module ActiveRecord
200
200
  module PostgreSQLDatabaseTasks
201
- if ::Rails.version < '4.2'
202
- def structure_dump(filename)
203
- set_psql_env
204
- search_path = configuration['schema_search_path']
205
- unless search_path.blank?
206
- search_path = search_path.split(",").map{|search_path_part| "--schema=#{Shellwords.escape(search_path_part.strip)}" }.join(" ")
207
- serialized_search_path = ::ActiveRecord::Base.connection.schema_search_path
208
- end
209
- if configuration['use_qualified_names']
210
- shard = Shard.current.name
211
- serialized_search_path = shard
212
- search_path = "--schema=#{Shellwords.escape(shard)}"
213
- end
214
-
215
- command = "pg_dump -s -x -O -f #{Shellwords.escape(filename)} #{search_path} #{Shellwords.escape(configuration['database'])}"
216
- raise 'Error dumping database' unless Kernel.system(command)
217
-
218
- File.open(filename, "a") { |f| f << "SET search_path TO #{serialized_search_path};\n\n" }
201
+ def structure_dump(filename)
202
+ set_psql_env
203
+ args = ['-s', '-x', '-O', '-f', filename]
204
+ search_path = configuration['schema_search_path']
205
+ if configuration['use_qualified_names']
206
+ shard = Shard.current.name
207
+ serialized_search_path = shard
208
+ args << "--schema=#{Shellwords.escape(shard)}"
209
+ elsif !search_path.blank?
210
+ args << search_path.split(',').map do |part|
211
+ "--schema=#{part.strip}"
212
+ end.join(' ')
213
+ serialized_search_path = connection.schema_search_path
219
214
  end
220
- else
221
- def structure_dump(filename)
222
- set_psql_env
223
- args = ['-s', '-x', '-O', '-f', filename]
224
- search_path = configuration['schema_search_path']
225
- if configuration['use_qualified_names']
226
- shard = Shard.current.name
227
- serialized_search_path = shard
228
- args << "--schema=#{Shellwords.escape(shard)}"
229
- elsif !search_path.blank?
230
- args << search_path.split(',').map do |part|
231
- "--schema=#{part.strip}"
232
- end.join(' ')
233
- serialized_search_path = connection.schema_search_path
234
- end
235
215
 
236
- args << configuration['database']
237
- run_cmd('pg_dump', args, 'dumping')
238
- File.open(filename, "a") { |f| f << "SET search_path TO #{serialized_search_path};\n\n" }
239
- end
216
+ args << configuration['database']
217
+ run_cmd('pg_dump', args, 'dumping')
218
+ File.open(filename, "a") { |f| f << "SET search_path TO #{serialized_search_path};\n\n" }
219
+ end
240
220
 
241
- if ::Rails.version < '4.2.5'
242
- # These methods are backported from rails 4.2.5 to work with the above
243
- def run_cmd(cmd, args, action)
244
- fail run_cmd_error(cmd, args, action) unless Kernel.system(cmd, *args)
245
- end
221
+ if ::Rails.version < '4.2.5'
222
+ # These methods are backported from rails 4.2.5 to work with the above
223
+ def run_cmd(cmd, args, action)
224
+ fail run_cmd_error(cmd, args, action) unless Kernel.system(cmd, *args)
225
+ end
246
226
 
247
- def run_cmd_error(cmd, args, action)
248
- msg = "failed to execute:\n"
249
- msg << "#{cmd} #{args.join(' ')}\n\n"
250
- msg << "Please check the output above for any errors and make sure that `#{cmd}` is installed in your PATH and has proper permissions.\n\n"
251
- msg
252
- end
227
+ def run_cmd_error(cmd, args, action)
228
+ msg = "failed to execute:\n"
229
+ msg << "#{cmd} #{args.join(' ')}\n\n"
230
+ msg << "Please check the output above for any errors and make sure that `#{cmd}` is installed in your PATH and has proper permissions.\n\n"
231
+ msg
253
232
  end
254
233
  end
255
234
  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.7.4
4
+ version: 1.8.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: 2016-10-31 00:00:00.000000000 Z
13
+ date: 2016-11-08 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: '4.0'
21
+ version: '4.2'
22
22
  - - "<="
23
23
  - !ruby/object:Gem::Version
24
24
  version: '5.1'
@@ -28,7 +28,7 @@ dependencies:
28
28
  requirements:
29
29
  - - ">="
30
30
  - !ruby/object:Gem::Version
31
- version: '4.0'
31
+ version: '4.2'
32
32
  - - "<="
33
33
  - !ruby/object:Gem::Version
34
34
  version: '5.1'
@@ -38,7 +38,7 @@ dependencies:
38
38
  requirements:
39
39
  - - ">="
40
40
  - !ruby/object:Gem::Version
41
- version: '4.0'
41
+ version: '4.2'
42
42
  - - "<="
43
43
  - !ruby/object:Gem::Version
44
44
  version: '5.1'
@@ -48,7 +48,7 @@ dependencies:
48
48
  requirements:
49
49
  - - ">="
50
50
  - !ruby/object:Gem::Version
51
- version: '4.0'
51
+ version: '4.2'
52
52
  - - "<="
53
53
  - !ruby/object:Gem::Version
54
54
  version: '5.1'