activerecord 5.0.7.2 → 5.1.0.beta1

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of activerecord might be problematic. Click here for more details.

Files changed (216) hide show
  1. checksums.yaml +5 -5
  2. data/CHANGELOG.md +389 -2252
  3. data/MIT-LICENSE +1 -1
  4. data/README.rdoc +1 -1
  5. data/examples/performance.rb +28 -28
  6. data/examples/simple.rb +3 -3
  7. data/lib/active_record.rb +20 -20
  8. data/lib/active_record/aggregations.rb +244 -244
  9. data/lib/active_record/association_relation.rb +5 -5
  10. data/lib/active_record/associations.rb +1579 -1569
  11. data/lib/active_record/associations/alias_tracker.rb +1 -1
  12. data/lib/active_record/associations/association.rb +23 -15
  13. data/lib/active_record/associations/association_scope.rb +83 -81
  14. data/lib/active_record/associations/belongs_to_association.rb +0 -1
  15. data/lib/active_record/associations/builder/belongs_to.rb +16 -14
  16. data/lib/active_record/associations/builder/collection_association.rb +1 -2
  17. data/lib/active_record/associations/builder/has_and_belongs_to_many.rb +27 -27
  18. data/lib/active_record/associations/collection_association.rb +74 -241
  19. data/lib/active_record/associations/collection_proxy.rb +144 -70
  20. data/lib/active_record/associations/has_many_association.rb +15 -19
  21. data/lib/active_record/associations/has_many_through_association.rb +12 -5
  22. data/lib/active_record/associations/has_one_association.rb +22 -28
  23. data/lib/active_record/associations/has_one_through_association.rb +5 -1
  24. data/lib/active_record/associations/join_dependency.rb +117 -115
  25. data/lib/active_record/associations/join_dependency/join_association.rb +16 -13
  26. data/lib/active_record/associations/join_dependency/join_base.rb +1 -1
  27. data/lib/active_record/associations/join_dependency/join_part.rb +1 -1
  28. data/lib/active_record/associations/preloader.rb +94 -94
  29. data/lib/active_record/associations/preloader/association.rb +87 -64
  30. data/lib/active_record/associations/preloader/belongs_to.rb +0 -2
  31. data/lib/active_record/associations/preloader/collection_association.rb +6 -6
  32. data/lib/active_record/associations/preloader/has_many.rb +0 -2
  33. data/lib/active_record/associations/preloader/singular_association.rb +6 -8
  34. data/lib/active_record/associations/preloader/through_association.rb +34 -41
  35. data/lib/active_record/associations/singular_association.rb +8 -25
  36. data/lib/active_record/associations/through_association.rb +3 -6
  37. data/lib/active_record/attribute.rb +98 -71
  38. data/lib/active_record/attribute/user_provided_default.rb +4 -2
  39. data/lib/active_record/attribute_assignment.rb +61 -61
  40. data/lib/active_record/attribute_decorators.rb +35 -13
  41. data/lib/active_record/attribute_methods.rb +56 -65
  42. data/lib/active_record/attribute_methods/before_type_cast.rb +7 -7
  43. data/lib/active_record/attribute_methods/dirty.rb +216 -34
  44. data/lib/active_record/attribute_methods/primary_key.rb +78 -73
  45. data/lib/active_record/attribute_methods/read.rb +39 -35
  46. data/lib/active_record/attribute_methods/serialization.rb +7 -7
  47. data/lib/active_record/attribute_methods/time_zone_conversion.rb +35 -58
  48. data/lib/active_record/attribute_methods/write.rb +36 -30
  49. data/lib/active_record/attribute_mutation_tracker.rb +53 -10
  50. data/lib/active_record/attribute_set.rb +9 -6
  51. data/lib/active_record/attribute_set/builder.rb +41 -49
  52. data/lib/active_record/attribute_set/yaml_encoder.rb +41 -0
  53. data/lib/active_record/attributes.rb +21 -21
  54. data/lib/active_record/autosave_association.rb +13 -13
  55. data/lib/active_record/base.rb +24 -22
  56. data/lib/active_record/callbacks.rb +52 -14
  57. data/lib/active_record/coders/yaml_column.rb +9 -11
  58. data/lib/active_record/collection_cache_key.rb +6 -17
  59. data/lib/active_record/connection_adapters/abstract/connection_pool.rb +320 -278
  60. data/lib/active_record/connection_adapters/abstract/database_limits.rb +1 -3
  61. data/lib/active_record/connection_adapters/abstract/database_statements.rb +22 -34
  62. data/lib/active_record/connection_adapters/abstract/query_cache.rb +31 -27
  63. data/lib/active_record/connection_adapters/abstract/quoting.rb +44 -57
  64. data/lib/active_record/connection_adapters/abstract/schema_creation.rb +9 -19
  65. data/lib/active_record/connection_adapters/abstract/schema_definitions.rb +78 -79
  66. data/lib/active_record/connection_adapters/abstract/schema_dumper.rb +53 -41
  67. data/lib/active_record/connection_adapters/abstract/schema_statements.rb +99 -93
  68. data/lib/active_record/connection_adapters/abstract/transaction.rb +1 -5
  69. data/lib/active_record/connection_adapters/abstract_adapter.rb +156 -128
  70. data/lib/active_record/connection_adapters/abstract_mysql_adapter.rb +424 -382
  71. data/lib/active_record/connection_adapters/column.rb +27 -5
  72. data/lib/active_record/connection_adapters/connection_specification.rb +128 -118
  73. data/lib/active_record/connection_adapters/mysql/column.rb +6 -31
  74. data/lib/active_record/connection_adapters/mysql/database_statements.rb +45 -43
  75. data/lib/active_record/connection_adapters/mysql/explain_pretty_printer.rb +22 -22
  76. data/lib/active_record/connection_adapters/mysql/quoting.rb +6 -12
  77. data/lib/active_record/connection_adapters/mysql/schema_creation.rb +49 -45
  78. data/lib/active_record/connection_adapters/mysql/schema_definitions.rb +16 -19
  79. data/lib/active_record/connection_adapters/mysql/schema_dumper.rb +49 -31
  80. data/lib/active_record/connection_adapters/mysql/type_metadata.rb +5 -6
  81. data/lib/active_record/connection_adapters/mysql2_adapter.rb +24 -26
  82. data/lib/active_record/connection_adapters/postgresql/column.rb +1 -28
  83. data/lib/active_record/connection_adapters/postgresql/database_statements.rb +46 -35
  84. data/lib/active_record/connection_adapters/postgresql/explain_pretty_printer.rb +3 -3
  85. data/lib/active_record/connection_adapters/postgresql/oid.rb +22 -21
  86. data/lib/active_record/connection_adapters/postgresql/oid/array.rb +9 -9
  87. data/lib/active_record/connection_adapters/postgresql/oid/bit.rb +5 -3
  88. data/lib/active_record/connection_adapters/postgresql/oid/bytea.rb +1 -1
  89. data/lib/active_record/connection_adapters/postgresql/oid/cidr.rb +1 -1
  90. data/lib/active_record/connection_adapters/postgresql/oid/date_time.rb +2 -2
  91. data/lib/active_record/connection_adapters/postgresql/oid/enum.rb +3 -3
  92. data/lib/active_record/connection_adapters/postgresql/oid/hstore.rb +16 -16
  93. data/lib/active_record/connection_adapters/postgresql/oid/{rails_5_1_point.rb → legacy_point.rb} +9 -16
  94. data/lib/active_record/connection_adapters/postgresql/oid/money.rb +2 -2
  95. data/lib/active_record/connection_adapters/postgresql/oid/oid.rb +13 -0
  96. data/lib/active_record/connection_adapters/postgresql/oid/point.rb +28 -8
  97. data/lib/active_record/connection_adapters/postgresql/oid/range.rb +28 -30
  98. data/lib/active_record/connection_adapters/postgresql/oid/specialized_string.rb +2 -1
  99. data/lib/active_record/connection_adapters/postgresql/oid/type_map_initializer.rb +51 -51
  100. data/lib/active_record/connection_adapters/postgresql/quoting.rb +38 -36
  101. data/lib/active_record/connection_adapters/postgresql/schema_creation.rb +15 -0
  102. data/lib/active_record/connection_adapters/postgresql/schema_definitions.rb +37 -24
  103. data/lib/active_record/connection_adapters/postgresql/schema_dumper.rb +19 -23
  104. data/lib/active_record/connection_adapters/postgresql/schema_statements.rb +161 -170
  105. data/lib/active_record/connection_adapters/postgresql/type_metadata.rb +4 -4
  106. data/lib/active_record/connection_adapters/postgresql/utils.rb +9 -7
  107. data/lib/active_record/connection_adapters/postgresql_adapter.rb +179 -152
  108. data/lib/active_record/connection_adapters/schema_cache.rb +16 -7
  109. data/lib/active_record/connection_adapters/sql_type_metadata.rb +3 -3
  110. data/lib/active_record/connection_adapters/sqlite3/explain_pretty_printer.rb +1 -1
  111. data/lib/active_record/connection_adapters/sqlite3/quoting.rb +16 -20
  112. data/lib/active_record/connection_adapters/sqlite3/schema_creation.rb +1 -8
  113. data/lib/active_record/connection_adapters/sqlite3/schema_definitions.rb +28 -0
  114. data/lib/active_record/connection_adapters/sqlite3/schema_dumper.rb +17 -0
  115. data/lib/active_record/connection_adapters/sqlite3_adapter.rb +187 -130
  116. data/lib/active_record/connection_adapters/statement_pool.rb +7 -7
  117. data/lib/active_record/connection_handling.rb +14 -26
  118. data/lib/active_record/core.rb +110 -93
  119. data/lib/active_record/counter_cache.rb +62 -13
  120. data/lib/active_record/define_callbacks.rb +20 -0
  121. data/lib/active_record/dynamic_matchers.rb +80 -79
  122. data/lib/active_record/enum.rb +8 -6
  123. data/lib/active_record/errors.rb +58 -15
  124. data/lib/active_record/explain.rb +1 -2
  125. data/lib/active_record/explain_registry.rb +1 -1
  126. data/lib/active_record/explain_subscriber.rb +7 -4
  127. data/lib/active_record/fixture_set/file.rb +11 -8
  128. data/lib/active_record/fixtures.rb +66 -53
  129. data/lib/active_record/gem_version.rb +3 -3
  130. data/lib/active_record/inheritance.rb +93 -79
  131. data/lib/active_record/integration.rb +7 -7
  132. data/lib/active_record/internal_metadata.rb +3 -16
  133. data/lib/active_record/legacy_yaml_adapter.rb +1 -1
  134. data/lib/active_record/locking/optimistic.rb +64 -56
  135. data/lib/active_record/locking/pessimistic.rb +10 -1
  136. data/lib/active_record/log_subscriber.rb +29 -29
  137. data/lib/active_record/migration.rb +155 -172
  138. data/lib/active_record/migration/command_recorder.rb +94 -94
  139. data/lib/active_record/migration/compatibility.rb +76 -37
  140. data/lib/active_record/migration/join_table.rb +6 -6
  141. data/lib/active_record/model_schema.rb +85 -119
  142. data/lib/active_record/nested_attributes.rb +200 -199
  143. data/lib/active_record/null_relation.rb +10 -33
  144. data/lib/active_record/persistence.rb +45 -38
  145. data/lib/active_record/query_cache.rb +4 -8
  146. data/lib/active_record/querying.rb +2 -3
  147. data/lib/active_record/railtie.rb +16 -17
  148. data/lib/active_record/railties/controller_runtime.rb +6 -2
  149. data/lib/active_record/railties/databases.rake +125 -140
  150. data/lib/active_record/railties/jdbcmysql_error.rb +1 -1
  151. data/lib/active_record/readonly_attributes.rb +2 -2
  152. data/lib/active_record/reflection.rb +79 -96
  153. data/lib/active_record/relation.rb +72 -115
  154. data/lib/active_record/relation/batches.rb +87 -58
  155. data/lib/active_record/relation/batches/batch_enumerator.rb +1 -1
  156. data/lib/active_record/relation/calculations.rb +154 -160
  157. data/lib/active_record/relation/delegation.rb +30 -29
  158. data/lib/active_record/relation/finder_methods.rb +195 -226
  159. data/lib/active_record/relation/merger.rb +58 -62
  160. data/lib/active_record/relation/predicate_builder.rb +92 -89
  161. data/lib/active_record/relation/predicate_builder/array_handler.rb +7 -5
  162. data/lib/active_record/relation/predicate_builder/association_query_handler.rb +23 -23
  163. data/lib/active_record/relation/predicate_builder/base_handler.rb +3 -1
  164. data/lib/active_record/relation/predicate_builder/basic_object_handler.rb +0 -8
  165. data/lib/active_record/relation/predicate_builder/polymorphic_array_handler.rb +12 -10
  166. data/lib/active_record/relation/predicate_builder/range_handler.rb +0 -8
  167. data/lib/active_record/relation/query_attribute.rb +1 -1
  168. data/lib/active_record/relation/query_methods.rb +247 -295
  169. data/lib/active_record/relation/record_fetch_warning.rb +3 -3
  170. data/lib/active_record/relation/spawn_methods.rb +4 -5
  171. data/lib/active_record/relation/where_clause.rb +79 -65
  172. data/lib/active_record/relation/where_clause_factory.rb +47 -8
  173. data/lib/active_record/result.rb +29 -31
  174. data/lib/active_record/runtime_registry.rb +3 -3
  175. data/lib/active_record/sanitization.rb +182 -197
  176. data/lib/active_record/schema.rb +3 -3
  177. data/lib/active_record/schema_dumper.rb +14 -37
  178. data/lib/active_record/schema_migration.rb +3 -3
  179. data/lib/active_record/scoping.rb +9 -10
  180. data/lib/active_record/scoping/default.rb +87 -91
  181. data/lib/active_record/scoping/named.rb +16 -28
  182. data/lib/active_record/secure_token.rb +2 -2
  183. data/lib/active_record/statement_cache.rb +13 -15
  184. data/lib/active_record/store.rb +31 -32
  185. data/lib/active_record/suppressor.rb +2 -1
  186. data/lib/active_record/table_metadata.rb +9 -5
  187. data/lib/active_record/tasks/database_tasks.rb +72 -65
  188. data/lib/active_record/tasks/mysql_database_tasks.rb +75 -72
  189. data/lib/active_record/tasks/postgresql_database_tasks.rb +53 -48
  190. data/lib/active_record/tasks/sqlite_database_tasks.rb +18 -16
  191. data/lib/active_record/timestamp.rb +39 -25
  192. data/lib/active_record/touch_later.rb +1 -2
  193. data/lib/active_record/transactions.rb +98 -110
  194. data/lib/active_record/type.rb +17 -13
  195. data/lib/active_record/type/adapter_specific_registry.rb +46 -42
  196. data/lib/active_record/type/decimal_without_scale.rb +9 -0
  197. data/lib/active_record/type/hash_lookup_type_map.rb +3 -3
  198. data/lib/active_record/type/serialized.rb +8 -8
  199. data/lib/active_record/type/text.rb +9 -0
  200. data/lib/active_record/type/time.rb +0 -1
  201. data/lib/active_record/type/type_map.rb +11 -15
  202. data/lib/active_record/type/unsigned_integer.rb +15 -0
  203. data/lib/active_record/type_caster.rb +2 -2
  204. data/lib/active_record/type_caster/connection.rb +8 -6
  205. data/lib/active_record/type_caster/map.rb +3 -1
  206. data/lib/active_record/validations.rb +4 -4
  207. data/lib/active_record/validations/associated.rb +1 -1
  208. data/lib/active_record/validations/presence.rb +2 -2
  209. data/lib/active_record/validations/uniqueness.rb +8 -39
  210. data/lib/active_record/version.rb +1 -1
  211. data/lib/rails/generators/active_record.rb +4 -4
  212. data/lib/rails/generators/active_record/migration.rb +2 -2
  213. data/lib/rails/generators/active_record/migration/migration_generator.rb +37 -34
  214. data/lib/rails/generators/active_record/model/model_generator.rb +9 -9
  215. metadata +22 -13
  216. data/lib/active_record/relation/predicate_builder/class_handler.rb +0 -27
@@ -25,9 +25,9 @@ module ActiveRecord
25
25
  value.sub!(/^\((.+)\)$/, '-\1') # (4)
26
26
  case value
27
27
  when /^-?\D+[\d,]+\.\d{2}$/ # (1)
28
- value.gsub!(/[^-\d.]/, '')
28
+ value.gsub!(/[^-\d.]/, "")
29
29
  when /^-?\D+[\d.]+,\d{2}$/ # (2)
30
- value.gsub!(/[^-\d,]/, '').sub!(/,/, '.')
30
+ value.gsub!(/[^-\d,]/, "").sub!(/,/, ".")
31
31
  end
32
32
 
33
33
  super(value)
@@ -0,0 +1,13 @@
1
+ module ActiveRecord
2
+ module ConnectionAdapters
3
+ module PostgreSQL
4
+ module OID # :nodoc:
5
+ class Oid < Type::Integer # :nodoc:
6
+ def type
7
+ :oid
8
+ end
9
+ end
10
+ end
11
+ end
12
+ end
13
+ end
@@ -1,4 +1,6 @@
1
1
  module ActiveRecord
2
+ Point = Struct.new(:x, :y)
3
+
2
4
  module ConnectionAdapters
3
5
  module PostgreSQL
4
6
  module OID # :nodoc:
@@ -12,20 +14,34 @@ module ActiveRecord
12
14
  def cast(value)
13
15
  case value
14
16
  when ::String
15
- if value[0] == '(' && value[-1] == ')'
17
+ return if value.blank?
18
+
19
+ if value[0] == "(" && value[-1] == ")"
16
20
  value = value[1...-1]
17
21
  end
18
- cast(value.split(','))
22
+ x, y = value.split(",")
23
+ build_point(x, y)
19
24
  when ::Array
20
- value.map { |v| Float(v) }
25
+ build_point(*value)
21
26
  else
22
27
  value
23
28
  end
24
29
  end
25
30
 
26
31
  def serialize(value)
27
- if value.is_a?(::Array)
28
- "(#{number_for_point(value[0])},#{number_for_point(value[1])})"
32
+ case value
33
+ when ActiveRecord::Point
34
+ "(#{number_for_point(value.x)},#{number_for_point(value.y)})"
35
+ when ::Array
36
+ serialize(build_point(*value))
37
+ else
38
+ super
39
+ end
40
+ end
41
+
42
+ def type_cast_for_schema(value)
43
+ if ActiveRecord::Point === value
44
+ [value.x, value.y]
29
45
  else
30
46
  super
31
47
  end
@@ -33,9 +49,13 @@ module ActiveRecord
33
49
 
34
50
  private
35
51
 
36
- def number_for_point(number)
37
- number.to_s.gsub(/\.0$/, '')
38
- end
52
+ def number_for_point(number)
53
+ number.to_s.gsub(/\.0$/, "")
54
+ end
55
+
56
+ def build_point(x, y)
57
+ ActiveRecord::Point.new(Float(x), Float(y))
58
+ end
39
59
  end
40
60
  end
41
61
  end
@@ -1,5 +1,3 @@
1
- require 'active_support/core_ext/string/filters'
2
-
3
1
  module ActiveRecord
4
2
  module ConnectionAdapters
5
3
  module PostgreSQL
@@ -14,11 +12,11 @@ module ActiveRecord
14
12
  end
15
13
 
16
14
  def type_cast_for_schema(value)
17
- value.inspect.gsub('Infinity', '::Float::INFINITY')
15
+ value.inspect.gsub("Infinity", "::Float::INFINITY")
18
16
  end
19
17
 
20
18
  def cast_value(value)
21
- return if value == 'empty'
19
+ return if value == "empty"
22
20
  return value unless value.is_a?(::String)
23
21
 
24
22
  extracted = extract_bounds(value)
@@ -55,37 +53,37 @@ module ActiveRecord
55
53
 
56
54
  private
57
55
 
58
- def type_cast_single(value)
59
- infinity?(value) ? value : @subtype.deserialize(value)
60
- end
56
+ def type_cast_single(value)
57
+ infinity?(value) ? value : @subtype.deserialize(value)
58
+ end
61
59
 
62
- def type_cast_single_for_database(value)
63
- infinity?(value) ? '' : @subtype.serialize(value)
64
- end
60
+ def type_cast_single_for_database(value)
61
+ infinity?(value) ? "" : @subtype.serialize(value)
62
+ end
65
63
 
66
- def extract_bounds(value)
67
- from, to = value[1..-2].split(',')
68
- {
69
- from: (value[1] == ',' || from == '-infinity') ? infinity(negative: true) : from,
70
- to: (value[-2] == ',' || to == 'infinity') ? infinity : to,
71
- exclude_start: (value[0] == '('),
72
- exclude_end: (value[-1] == ')')
73
- }
74
- end
64
+ def extract_bounds(value)
65
+ from, to = value[1..-2].split(",")
66
+ {
67
+ from: (value[1] == "," || from == "-infinity") ? infinity(negative: true) : from,
68
+ to: (value[-2] == "," || to == "infinity") ? infinity : to,
69
+ exclude_start: (value[0] == "("),
70
+ exclude_end: (value[-1] == ")")
71
+ }
72
+ end
75
73
 
76
- def infinity(negative: false)
77
- if subtype.respond_to?(:infinity)
78
- subtype.infinity(negative: negative)
79
- elsif negative
80
- -::Float::INFINITY
81
- else
82
- ::Float::INFINITY
74
+ def infinity(negative: false)
75
+ if subtype.respond_to?(:infinity)
76
+ subtype.infinity(negative: negative)
77
+ elsif negative
78
+ -::Float::INFINITY
79
+ else
80
+ ::Float::INFINITY
81
+ end
83
82
  end
84
- end
85
83
 
86
- def infinity?(value)
87
- value.respond_to?(:infinite?) && value.infinite?
88
- end
84
+ def infinity?(value)
85
+ value.respond_to?(:infinite?) && value.infinite?
86
+ end
89
87
  end
90
88
  end
91
89
  end
@@ -5,8 +5,9 @@ module ActiveRecord
5
5
  class SpecializedString < Type::String # :nodoc:
6
6
  attr_reader :type
7
7
 
8
- def initialize(type)
8
+ def initialize(type, **options)
9
9
  @type = type
10
+ super(options)
10
11
  end
11
12
  end
12
13
  end
@@ -13,13 +13,13 @@ module ActiveRecord
13
13
  end
14
14
 
15
15
  def run(records)
16
- nodes = records.reject { |row| @store.key? row['oid'].to_i }
17
- mapped, nodes = nodes.partition { |row| @store.key? row['typname'] }
18
- ranges, nodes = nodes.partition { |row| row['typtype'] == 'r'.freeze }
19
- enums, nodes = nodes.partition { |row| row['typtype'] == 'e'.freeze }
20
- domains, nodes = nodes.partition { |row| row['typtype'] == 'd'.freeze }
21
- arrays, nodes = nodes.partition { |row| row['typinput'] == 'array_in'.freeze }
22
- composites, nodes = nodes.partition { |row| row['typelem'].to_i != 0 }
16
+ nodes = records.reject { |row| @store.key? row["oid"].to_i }
17
+ mapped, nodes = nodes.partition { |row| @store.key? row["typname"] }
18
+ ranges, nodes = nodes.partition { |row| row["typtype"] == "r".freeze }
19
+ enums, nodes = nodes.partition { |row| row["typtype"] == "e".freeze }
20
+ domains, nodes = nodes.partition { |row| row["typtype"] == "d".freeze }
21
+ arrays, nodes = nodes.partition { |row| row["typinput"] == "array_in".freeze }
22
+ composites, nodes = nodes.partition { |row| row["typelem"].to_i != 0 }
23
23
 
24
24
  mapped.each { |row| register_mapped_type(row) }
25
25
  enums.each { |row| register_enum_type(row) }
@@ -42,66 +42,66 @@ module ActiveRecord
42
42
  end
43
43
 
44
44
  private
45
- def register_mapped_type(row)
46
- alias_type row['oid'], row['typname']
47
- end
45
+ def register_mapped_type(row)
46
+ alias_type row["oid"], row["typname"]
47
+ end
48
48
 
49
- def register_enum_type(row)
50
- register row['oid'], OID::Enum.new
51
- end
49
+ def register_enum_type(row)
50
+ register row["oid"], OID::Enum.new
51
+ end
52
52
 
53
- def register_array_type(row)
54
- register_with_subtype(row['oid'], row['typelem'].to_i) do |subtype|
55
- OID::Array.new(subtype, row['typdelim'])
53
+ def register_array_type(row)
54
+ register_with_subtype(row["oid"], row["typelem"].to_i) do |subtype|
55
+ OID::Array.new(subtype, row["typdelim"])
56
+ end
56
57
  end
57
- end
58
58
 
59
- def register_range_type(row)
60
- register_with_subtype(row['oid'], row['rngsubtype'].to_i) do |subtype|
61
- OID::Range.new(subtype, row['typname'].to_sym)
59
+ def register_range_type(row)
60
+ register_with_subtype(row["oid"], row["rngsubtype"].to_i) do |subtype|
61
+ OID::Range.new(subtype, row["typname"].to_sym)
62
+ end
62
63
  end
63
- end
64
64
 
65
- def register_domain_type(row)
66
- if base_type = @store.lookup(row["typbasetype"].to_i)
67
- register row['oid'], base_type
68
- else
69
- warn "unknown base type (OID: #{row["typbasetype"]}) for domain #{row["typname"]}."
65
+ def register_domain_type(row)
66
+ if base_type = @store.lookup(row["typbasetype"].to_i)
67
+ register row["oid"], base_type
68
+ else
69
+ warn "unknown base type (OID: #{row["typbasetype"]}) for domain #{row["typname"]}."
70
+ end
70
71
  end
71
- end
72
72
 
73
- def register_composite_type(row)
74
- if subtype = @store.lookup(row['typelem'].to_i)
75
- register row['oid'], OID::Vector.new(row['typdelim'], subtype)
73
+ def register_composite_type(row)
74
+ if subtype = @store.lookup(row["typelem"].to_i)
75
+ register row["oid"], OID::Vector.new(row["typdelim"], subtype)
76
+ end
76
77
  end
77
- end
78
78
 
79
- def register(oid, oid_type = nil, &block)
80
- oid = assert_valid_registration(oid, oid_type || block)
81
- if block_given?
82
- @store.register_type(oid, &block)
83
- else
84
- @store.register_type(oid, oid_type)
79
+ def register(oid, oid_type = nil, &block)
80
+ oid = assert_valid_registration(oid, oid_type || block)
81
+ if block_given?
82
+ @store.register_type(oid, &block)
83
+ else
84
+ @store.register_type(oid, oid_type)
85
+ end
85
86
  end
86
- end
87
87
 
88
- def alias_type(oid, target)
89
- oid = assert_valid_registration(oid, target)
90
- @store.alias_type(oid, target)
91
- end
88
+ def alias_type(oid, target)
89
+ oid = assert_valid_registration(oid, target)
90
+ @store.alias_type(oid, target)
91
+ end
92
92
 
93
- def register_with_subtype(oid, target_oid)
94
- if @store.key?(target_oid)
95
- register(oid) do |_, *args|
96
- yield @store.lookup(target_oid, *args)
93
+ def register_with_subtype(oid, target_oid)
94
+ if @store.key?(target_oid)
95
+ register(oid) do |_, *args|
96
+ yield @store.lookup(target_oid, *args)
97
+ end
97
98
  end
98
99
  end
99
- end
100
100
 
101
- def assert_valid_registration(oid, oid_type)
102
- raise ArgumentError, "can't register nil type for OID #{oid}" if oid_type.nil?
103
- oid.to_i
104
- end
101
+ def assert_valid_registration(oid, oid_type)
102
+ raise ArgumentError, "can't register nil type for OID #{oid}" if oid_type.nil?
103
+ oid.to_i
104
+ end
105
105
  end
106
106
  end
107
107
  end
@@ -28,12 +28,12 @@ module ActiveRecord
28
28
  # - "schema.name".table_name
29
29
  # - "schema.name"."table.name"
30
30
  def quote_table_name(name) # :nodoc:
31
- @quoted_table_names[name] ||= Utils.extract_schema_qualified_name(name.to_s).quoted
31
+ @quoted_table_names[name] ||= Utils.extract_schema_qualified_name(name.to_s).quoted.freeze
32
32
  end
33
33
 
34
34
  # Quotes schema names for use in SQL queries.
35
35
  def quote_schema_name(name)
36
- PG::Connection.quote_ident(name)
36
+ PGconn.quote_ident(name)
37
37
  end
38
38
 
39
39
  def quote_table_name_for_assignment(table, attr)
@@ -42,7 +42,7 @@ module ActiveRecord
42
42
 
43
43
  # Quotes column names for use in SQL queries.
44
44
  def quote_column_name(name) # :nodoc:
45
- @quoted_column_names[name] ||= PG::Connection.quote_ident(super)
45
+ @quoted_column_names[name] ||= PGconn.quote_ident(super).freeze
46
46
  end
47
47
 
48
48
  # Quote date/time values for use in SQL input.
@@ -55,10 +55,14 @@ module ActiveRecord
55
55
  end
56
56
  end
57
57
 
58
+ def quoted_binary(value) # :nodoc:
59
+ "'#{escape_bytea(value.to_s)}'"
60
+ end
61
+
58
62
  def quote_default_expression(value, column) # :nodoc:
59
63
  if value.is_a?(Proc)
60
64
  value.call
61
- elsif column.type == :uuid && value =~ /\(\)/
65
+ elsif column.type == :uuid && value.include?("()")
62
66
  value # Does not quote function default values for UUID columns
63
67
  elsif column.respond_to?(:array?)
64
68
  value = type_cast_from_column(column, value)
@@ -74,46 +78,44 @@ module ActiveRecord
74
78
 
75
79
  private
76
80
 
77
- def _quote(value)
78
- case value
79
- when Type::Binary::Data
80
- "'#{escape_bytea(value.to_s)}'"
81
- when OID::Xml::Data
82
- "xml '#{quote_string(value.to_s)}'"
83
- when OID::Bit::Data
84
- if value.binary?
85
- "B'#{value}'"
86
- elsif value.hex?
87
- "X'#{value}'"
88
- end
89
- when Float
90
- if value.infinite? || value.nan?
91
- "'#{value}'"
81
+ def _quote(value)
82
+ case value
83
+ when OID::Xml::Data
84
+ "xml '#{quote_string(value.to_s)}'"
85
+ when OID::Bit::Data
86
+ if value.binary?
87
+ "B'#{value}'"
88
+ elsif value.hex?
89
+ "X'#{value}'"
90
+ end
91
+ when Float
92
+ if value.infinite? || value.nan?
93
+ "'#{value}'"
94
+ else
95
+ super
96
+ end
97
+ when OID::Array::Data
98
+ _quote(encode_array(value))
92
99
  else
93
100
  super
94
101
  end
95
- when OID::Array::Data
96
- _quote(encode_array(value))
97
- else
98
- super
99
102
  end
100
- end
101
103
 
102
- def _type_cast(value)
103
- case value
104
- when Type::Binary::Data
105
- # Return a bind param hash with format as binary.
106
- # See https://deveiate.org/code/pg/PG/Connection.html#method-i-exec_prepared-doc
107
- # for more information
108
- { value: value.to_s, format: 1 }
109
- when OID::Xml::Data, OID::Bit::Data
110
- value.to_s
104
+ def _type_cast(value)
105
+ case value
106
+ when Type::Binary::Data
107
+ # Return a bind param hash with format as binary.
108
+ # See http://deveiate.org/code/pg/PGconn.html#method-i-exec_prepared-doc
109
+ # for more information
110
+ { value: value.to_s, format: 1 }
111
+ when OID::Xml::Data, OID::Bit::Data
112
+ value.to_s
111
113
  when OID::Array::Data
112
114
  encode_array(value)
113
- else
114
- super
115
+ else
116
+ super
117
+ end
115
118
  end
116
- end
117
119
 
118
120
  def encode_array(array_data)
119
121
  encoder = array_data.encoder
@@ -0,0 +1,15 @@
1
+ module ActiveRecord
2
+ module ConnectionAdapters
3
+ module PostgreSQL
4
+ class SchemaCreation < AbstractAdapter::SchemaCreation # :nodoc:
5
+ private
6
+ def add_column_options!(sql, options)
7
+ if options[:collation]
8
+ sql << " COLLATE \"#{options[:collation]}\""
9
+ end
10
+ super
11
+ end
12
+ end
13
+ end
14
+ end
15
+ end