activerecord 6.0.0 → 6.0.3

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 (150) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +185 -1
  3. data/README.rdoc +1 -1
  4. data/lib/active_record.rb +1 -0
  5. data/lib/active_record/advisory_lock_base.rb +18 -0
  6. data/lib/active_record/aggregations.rb +0 -1
  7. data/lib/active_record/association_relation.rb +10 -8
  8. data/lib/active_record/associations.rb +2 -2
  9. data/lib/active_record/associations/alias_tracker.rb +0 -1
  10. data/lib/active_record/associations/association.rb +5 -1
  11. data/lib/active_record/associations/builder/has_and_belongs_to_many.rb +0 -2
  12. data/lib/active_record/associations/collection_association.rb +6 -2
  13. data/lib/active_record/associations/collection_proxy.rb +1 -2
  14. data/lib/active_record/associations/has_many_association.rb +0 -1
  15. data/lib/active_record/associations/join_dependency.rb +13 -0
  16. data/lib/active_record/associations/join_dependency/join_association.rb +1 -1
  17. data/lib/active_record/associations/preloader.rb +2 -3
  18. data/lib/active_record/attribute_assignment.rb +0 -1
  19. data/lib/active_record/attribute_decorators.rb +0 -2
  20. data/lib/active_record/attribute_methods/before_type_cast.rb +0 -1
  21. data/lib/active_record/attribute_methods/dirty.rb +2 -2
  22. data/lib/active_record/attribute_methods/primary_key.rb +0 -2
  23. data/lib/active_record/attribute_methods/read.rb +0 -1
  24. data/lib/active_record/attribute_methods/serialization.rb +0 -1
  25. data/lib/active_record/attribute_methods/time_zone_conversion.rb +0 -2
  26. data/lib/active_record/attribute_methods/write.rb +0 -1
  27. data/lib/active_record/attributes.rb +0 -1
  28. data/lib/active_record/autosave_association.rb +8 -6
  29. data/lib/active_record/callbacks.rb +1 -2
  30. data/lib/active_record/coders/yaml_column.rb +0 -1
  31. data/lib/active_record/connection_adapters/abstract/connection_pool.rb +14 -7
  32. data/lib/active_record/connection_adapters/abstract/database_statements.rb +21 -15
  33. data/lib/active_record/connection_adapters/abstract/query_cache.rb +2 -2
  34. data/lib/active_record/connection_adapters/abstract/schema_creation.rb +1 -2
  35. data/lib/active_record/connection_adapters/abstract/schema_definitions.rb +27 -27
  36. data/lib/active_record/connection_adapters/abstract/schema_statements.rb +47 -30
  37. data/lib/active_record/connection_adapters/abstract/transaction.rb +4 -5
  38. data/lib/active_record/connection_adapters/abstract_adapter.rb +23 -8
  39. data/lib/active_record/connection_adapters/abstract_mysql_adapter.rb +25 -32
  40. data/lib/active_record/connection_adapters/connection_specification.rb +2 -3
  41. data/lib/active_record/connection_adapters/mysql/column.rb +1 -1
  42. data/lib/active_record/connection_adapters/mysql/database_statements.rb +8 -12
  43. data/lib/active_record/connection_adapters/mysql/explain_pretty_printer.rb +0 -1
  44. data/lib/active_record/connection_adapters/mysql/schema_creation.rb +1 -2
  45. data/lib/active_record/connection_adapters/mysql/schema_statements.rb +8 -8
  46. data/lib/active_record/connection_adapters/mysql2_adapter.rb +0 -1
  47. data/lib/active_record/connection_adapters/postgresql/database_statements.rb +9 -3
  48. data/lib/active_record/connection_adapters/postgresql/oid/array.rb +0 -1
  49. data/lib/active_record/connection_adapters/postgresql/oid/enum.rb +0 -1
  50. data/lib/active_record/connection_adapters/postgresql/oid/hstore.rb +0 -1
  51. data/lib/active_record/connection_adapters/postgresql/oid/legacy_point.rb +0 -1
  52. data/lib/active_record/connection_adapters/postgresql/oid/oid.rb +1 -1
  53. data/lib/active_record/connection_adapters/postgresql/oid/point.rb +0 -1
  54. data/lib/active_record/connection_adapters/postgresql/oid/range.rb +0 -1
  55. data/lib/active_record/connection_adapters/postgresql/oid/specialized_string.rb +1 -1
  56. data/lib/active_record/connection_adapters/postgresql/oid/uuid.rb +0 -1
  57. data/lib/active_record/connection_adapters/postgresql/referential_integrity.rb +1 -1
  58. data/lib/active_record/connection_adapters/postgresql/schema_creation.rb +2 -2
  59. data/lib/active_record/connection_adapters/postgresql/schema_definitions.rb +1 -1
  60. data/lib/active_record/connection_adapters/postgresql/schema_dumper.rb +0 -1
  61. data/lib/active_record/connection_adapters/postgresql/schema_statements.rb +15 -29
  62. data/lib/active_record/connection_adapters/postgresql/utils.rb +0 -1
  63. data/lib/active_record/connection_adapters/postgresql_adapter.rb +9 -2
  64. data/lib/active_record/connection_adapters/sqlite3/database_statements.rb +8 -7
  65. data/lib/active_record/connection_adapters/sqlite3/quoting.rb +0 -1
  66. data/lib/active_record/connection_adapters/sqlite3/schema_statements.rb +3 -3
  67. data/lib/active_record/connection_adapters/sqlite3_adapter.rb +12 -7
  68. data/lib/active_record/connection_adapters/statement_pool.rb +0 -1
  69. data/lib/active_record/connection_handling.rb +13 -22
  70. data/lib/active_record/core.rb +8 -6
  71. data/lib/active_record/counter_cache.rb +4 -1
  72. data/lib/active_record/database_configurations/url_config.rb +0 -1
  73. data/lib/active_record/dynamic_matchers.rb +2 -3
  74. data/lib/active_record/explain.rb +0 -1
  75. data/lib/active_record/fixture_set/table_row.rb +0 -1
  76. data/lib/active_record/fixture_set/table_rows.rb +0 -1
  77. data/lib/active_record/fixtures.rb +0 -3
  78. data/lib/active_record/gem_version.rb +1 -1
  79. data/lib/active_record/inheritance.rb +0 -3
  80. data/lib/active_record/insert_all.rb +4 -4
  81. data/lib/active_record/internal_metadata.rb +1 -1
  82. data/lib/active_record/locking/optimistic.rb +0 -1
  83. data/lib/active_record/log_subscriber.rb +1 -1
  84. data/lib/active_record/middleware/database_selector.rb +0 -1
  85. data/lib/active_record/middleware/database_selector/resolver.rb +9 -14
  86. data/lib/active_record/migration.rb +4 -4
  87. data/lib/active_record/migration/command_recorder.rb +6 -18
  88. data/lib/active_record/migration/compatibility.rb +3 -3
  89. data/lib/active_record/migration/join_table.rb +0 -1
  90. data/lib/active_record/model_schema.rb +3 -2
  91. data/lib/active_record/nested_attributes.rb +0 -2
  92. data/lib/active_record/no_touching.rb +2 -2
  93. data/lib/active_record/null_relation.rb +0 -1
  94. data/lib/active_record/persistence.rb +4 -5
  95. data/lib/active_record/querying.rb +1 -1
  96. data/lib/active_record/railtie.rb +1 -1
  97. data/lib/active_record/railties/collection_cache_association_loading.rb +1 -1
  98. data/lib/active_record/railties/databases.rake +3 -0
  99. data/lib/active_record/reflection.rb +8 -8
  100. data/lib/active_record/relation.rb +13 -1
  101. data/lib/active_record/relation/batches.rb +0 -1
  102. data/lib/active_record/relation/calculations.rb +1 -1
  103. data/lib/active_record/relation/delegation.rb +7 -6
  104. data/lib/active_record/relation/finder_methods.rb +10 -2
  105. data/lib/active_record/relation/from_clause.rb +4 -0
  106. data/lib/active_record/relation/merger.rb +0 -1
  107. data/lib/active_record/relation/predicate_builder.rb +1 -5
  108. data/lib/active_record/relation/query_methods.rb +37 -12
  109. data/lib/active_record/relation/spawn_methods.rb +0 -1
  110. data/lib/active_record/relation/where_clause.rb +0 -1
  111. data/lib/active_record/result.rb +0 -1
  112. data/lib/active_record/schema_migration.rb +1 -1
  113. data/lib/active_record/scoping.rb +0 -1
  114. data/lib/active_record/scoping/default.rb +0 -1
  115. data/lib/active_record/scoping/named.rb +3 -3
  116. data/lib/active_record/store.rb +1 -1
  117. data/lib/active_record/suppressor.rb +2 -2
  118. data/lib/active_record/table_metadata.rb +16 -1
  119. data/lib/active_record/tasks/mysql_database_tasks.rb +0 -1
  120. data/lib/active_record/tasks/postgresql_database_tasks.rb +0 -1
  121. data/lib/active_record/tasks/sqlite_database_tasks.rb +0 -1
  122. data/lib/active_record/test_fixtures.rb +2 -1
  123. data/lib/active_record/timestamp.rb +0 -1
  124. data/lib/active_record/touch_later.rb +1 -2
  125. data/lib/active_record/transactions.rb +9 -9
  126. data/lib/active_record/type.rb +0 -1
  127. data/lib/active_record/type/adapter_specific_registry.rb +2 -5
  128. data/lib/active_record/type/hash_lookup_type_map.rb +0 -1
  129. data/lib/active_record/type/serialized.rb +0 -1
  130. data/lib/active_record/type/type_map.rb +0 -1
  131. data/lib/active_record/type/unsigned_integer.rb +0 -1
  132. data/lib/active_record/validations.rb +2 -3
  133. data/lib/active_record/validations/associated.rb +1 -2
  134. data/lib/arel.rb +17 -6
  135. data/lib/arel/predications.rb +5 -6
  136. data/lib/arel/visitors/depth_first.rb +0 -1
  137. data/lib/arel/visitors/dot.rb +0 -1
  138. data/lib/arel/visitors/mssql.rb +0 -1
  139. data/lib/arel/visitors/oracle.rb +1 -2
  140. data/lib/arel/visitors/oracle12.rb +0 -1
  141. data/lib/arel/visitors/postgresql.rb +0 -1
  142. data/lib/arel/visitors/sqlite.rb +0 -1
  143. data/lib/arel/visitors/to_sql.rb +0 -1
  144. data/lib/arel/visitors/visitor.rb +0 -1
  145. data/lib/arel/visitors/where_sql.rb +0 -1
  146. data/lib/rails/generators/active_record/application_record/application_record_generator.rb +0 -1
  147. data/lib/rails/generators/active_record/migration.rb +0 -1
  148. data/lib/rails/generators/active_record/migration/templates/migration.rb.tt +1 -1
  149. data/lib/rails/generators/active_record/model/model_generator.rb +0 -1
  150. metadata +13 -9
@@ -7,7 +7,6 @@ module ActiveRecord
7
7
  include ActiveModel::AttributeAssignment
8
8
 
9
9
  private
10
-
11
10
  def _assign_attributes(attributes)
12
11
  multi_parameter_attributes = {}
13
12
  nested_parameter_attributes = {}
@@ -46,7 +46,6 @@ module ActiveRecord
46
46
  end
47
47
 
48
48
  private
49
-
50
49
  def load_schema!
51
50
  super
52
51
  attribute_types.each do |name, type|
@@ -75,7 +74,6 @@ module ActiveRecord
75
74
  end
76
75
 
77
76
  private
78
-
79
77
  def decorators_for(name, type)
80
78
  matching(name, type).map(&:last)
81
79
  end
@@ -66,7 +66,6 @@ module ActiveRecord
66
66
  end
67
67
 
68
68
  private
69
-
70
69
  # Dispatch target for <tt>*_before_type_cast</tt> attribute methods.
71
70
  def attribute_before_type_cast(attribute_name)
72
71
  read_attribute_before_type_cast(attribute_name)
@@ -49,7 +49,7 @@ module ActiveRecord
49
49
  # +to+ When passed, this method will return false unless the value was
50
50
  # changed to the given value
51
51
  def saved_change_to_attribute?(attr_name, **options)
52
- mutations_before_last_save.changed?(attr_name.to_s, options)
52
+ mutations_before_last_save.changed?(attr_name.to_s, **options)
53
53
  end
54
54
 
55
55
  # Returns the change to an attribute during the last save. If the
@@ -99,7 +99,7 @@ module ActiveRecord
99
99
  # +to+ When passed, this method will return false unless the value will be
100
100
  # changed to the given value
101
101
  def will_save_change_to_attribute?(attr_name, **options)
102
- mutations_from_database.changed?(attr_name.to_s, options)
102
+ mutations_from_database.changed?(attr_name.to_s, **options)
103
103
  end
104
104
 
105
105
  # Returns the change to an attribute that will be persisted during the
@@ -45,7 +45,6 @@ module ActiveRecord
45
45
  end
46
46
 
47
47
  private
48
-
49
48
  def attribute_method?(attr_name)
50
49
  attr_name == "id" || super
51
50
  end
@@ -120,7 +119,6 @@ module ActiveRecord
120
119
  end
121
120
 
122
121
  private
123
-
124
122
  def suppress_composite_primary_key(pk)
125
123
  return pk unless pk.is_a?(Array)
126
124
 
@@ -7,7 +7,6 @@ module ActiveRecord
7
7
 
8
8
  module ClassMethods # :nodoc:
9
9
  private
10
-
11
10
  def define_method_attribute(name)
12
11
  ActiveModel::AttributeMethods::AttrNames.define_attribute_accessor_method(
13
12
  generated_attribute_methods, name
@@ -79,7 +79,6 @@ module ActiveRecord
79
79
  end
80
80
 
81
81
  private
82
-
83
82
  def type_incompatible_with_serialize?(type, class_name)
84
83
  type.is_a?(ActiveRecord::Type::Json) && class_name == ::JSON ||
85
84
  type.respond_to?(:type_cast_array, true) && class_name == ::Array
@@ -25,7 +25,6 @@ module ActiveRecord
25
25
  end
26
26
 
27
27
  private
28
-
29
28
  def convert_time_to_time_zone(value)
30
29
  return if value.nil?
31
30
 
@@ -64,7 +63,6 @@ module ActiveRecord
64
63
 
65
64
  module ClassMethods # :nodoc:
66
65
  private
67
-
68
66
  def inherited(subclass)
69
67
  super
70
68
  # We need to apply this decorator here, rather than on module inclusion. The closure
@@ -11,7 +11,6 @@ module ActiveRecord
11
11
 
12
12
  module ClassMethods # :nodoc:
13
13
  private
14
-
15
14
  def define_method_attribute=(name)
16
15
  ActiveModel::AttributeMethods::AttrNames.define_attribute_accessor_method(
17
16
  generated_attribute_methods, name, writer: true,
@@ -255,7 +255,6 @@ module ActiveRecord
255
255
  end
256
256
 
257
257
  private
258
-
259
258
  NO_DEFAULT_PROVIDED = Object.new # :nodoc:
260
259
  private_constant :NO_DEFAULT_PROVIDED
261
260
 
@@ -147,7 +147,6 @@ module ActiveRecord
147
147
 
148
148
  module ClassMethods # :nodoc:
149
149
  private
150
-
151
150
  def define_non_cyclic_method(name, &block)
152
151
  return if instance_methods(false).include?(name)
153
152
  define_method(name) do |*args|
@@ -267,12 +266,11 @@ module ActiveRecord
267
266
  end
268
267
 
269
268
  private
270
-
271
269
  # Returns the record for an association collection that should be validated
272
270
  # or saved. If +autosave+ is +false+ only new records will be returned,
273
271
  # unless the parent is/was a new record itself.
274
272
  def associated_records_to_validate_or_save(association, new_record, autosave)
275
- if new_record
273
+ if new_record || custom_validation_context?
276
274
  association && association.target
277
275
  elsif autosave
278
276
  association.target.find_all(&:changed_for_autosave?)
@@ -304,7 +302,7 @@ module ActiveRecord
304
302
  def validate_single_association(reflection)
305
303
  association = association_instance_get(reflection.name)
306
304
  record = association && association.reader
307
- association_valid?(reflection, record) if record && record.changed_for_autosave?
305
+ association_valid?(reflection, record) if record && (record.changed_for_autosave? || custom_validation_context?)
308
306
  end
309
307
 
310
308
  # Validate the associated records if <tt>:validate</tt> or
@@ -324,7 +322,7 @@ module ActiveRecord
324
322
  def association_valid?(reflection, record, index = nil)
325
323
  return true if record.destroyed? || (reflection.options[:autosave] && record.marked_for_destruction?)
326
324
 
327
- context = validation_context unless [:create, :update].include?(validation_context)
325
+ context = validation_context if custom_validation_context?
328
326
 
329
327
  unless valid = record.valid?(context)
330
328
  if reflection.options[:autosave]
@@ -363,7 +361,7 @@ module ActiveRecord
363
361
  # Is used as a before_save callback to check while saving a collection
364
362
  # association whether or not the parent was a new record before saving.
365
363
  def before_save_collection_association
366
- @new_record_before_save = new_record?
364
+ @new_record_before_save ||= new_record?
367
365
  end
368
366
 
369
367
  def after_save_collection_association
@@ -499,6 +497,10 @@ module ActiveRecord
499
497
  end
500
498
  end
501
499
 
500
+ def custom_validation_context?
501
+ validation_context && [:create, :update].exclude?(validation_context)
502
+ end
503
+
502
504
  def _ensure_no_duplicate_errors
503
505
  errors.messages.each_key do |attribute|
504
506
  errors[attribute].uniq!
@@ -314,7 +314,7 @@ module ActiveRecord
314
314
  @_destroy_callback_already_called = false
315
315
  end
316
316
 
317
- def touch(*) #:nodoc:
317
+ def touch(*, **) #:nodoc:
318
318
  _run_touch_callbacks { super }
319
319
  end
320
320
 
@@ -323,7 +323,6 @@ module ActiveRecord
323
323
  end
324
324
 
325
325
  private
326
-
327
326
  def create_or_update(**)
328
327
  _run_save_callbacks { super }
329
328
  end
@@ -39,7 +39,6 @@ module ActiveRecord
39
39
  end
40
40
 
41
41
  private
42
-
43
42
  def check_arity_of_constructor
44
43
  load(nil)
45
44
  rescue ArgumentError
@@ -167,7 +167,6 @@ module ActiveRecord
167
167
  end
168
168
 
169
169
  private
170
-
171
170
  def internal_poll(timeout)
172
171
  no_wait_poll || (timeout && wait_poll(timeout))
173
172
  end
@@ -317,23 +316,24 @@ module ActiveRecord
317
316
 
318
317
  @mutex = Mutex.new
319
318
  @pools = {}
319
+ @threads = {}
320
320
 
321
321
  class << self
322
322
  def register_pool(pool, frequency) # :nodoc:
323
323
  @mutex.synchronize do
324
- unless @pools.key?(frequency)
325
- @pools[frequency] = []
326
- spawn_thread(frequency)
324
+ unless @threads[frequency]&.alive?
325
+ @threads[frequency] = spawn_thread(frequency)
327
326
  end
327
+ @pools[frequency] ||= []
328
328
  @pools[frequency] << WeakRef.new(pool)
329
329
  end
330
330
  end
331
331
 
332
332
  private
333
-
334
333
  def spawn_thread(frequency)
335
334
  Thread.new(frequency) do |t|
336
- loop do
335
+ running = true
336
+ while running
337
337
  sleep t
338
338
  @mutex.synchronize do
339
339
  @pools[frequency].select!(&:weakref_alive?)
@@ -342,6 +342,12 @@ module ActiveRecord
342
342
  p.flush
343
343
  rescue WeakRef::RefError
344
344
  end
345
+
346
+ if @pools[frequency].empty?
347
+ @pools.delete(frequency)
348
+ @threads.delete(frequency)
349
+ running = false
350
+ end
345
351
  end
346
352
  end
347
353
  end
@@ -642,6 +648,7 @@ module ActiveRecord
642
648
  # or a thread dies unexpectedly.
643
649
  def reap
644
650
  stale_connections = synchronize do
651
+ return unless @connections
645
652
  @connections.select do |conn|
646
653
  conn.in_use? && !conn.owner.alive?
647
654
  end.each do |conn|
@@ -666,6 +673,7 @@ module ActiveRecord
666
673
  return if minimum_idle.nil?
667
674
 
668
675
  idle_connections = synchronize do
676
+ return unless @connections
669
677
  @connections.select do |conn|
670
678
  !conn.in_use? && conn.seconds_idle >= minimum_idle
671
679
  end.each do |conn|
@@ -1151,7 +1159,6 @@ module ActiveRecord
1151
1159
  end
1152
1160
 
1153
1161
  private
1154
-
1155
1162
  def owner_to_pool
1156
1163
  @owner_to_pool[Process.pid]
1157
1164
  end
@@ -149,6 +149,10 @@ module ActiveRecord
149
149
  exec_query(sql, name, binds)
150
150
  end
151
151
 
152
+ def exec_insert_all(sql, name) # :nodoc:
153
+ exec_query(sql, name)
154
+ end
155
+
152
156
  # Executes an INSERT query and returns the new record's ID
153
157
  #
154
158
  # +id_value+ will be returned unless the value is +nil+, in
@@ -178,7 +182,7 @@ module ActiveRecord
178
182
 
179
183
  # Executes the truncate statement.
180
184
  def truncate(table_name, name = nil)
181
- execute(build_truncate_statements(table_name), name)
185
+ execute(build_truncate_statement(table_name), name)
182
186
  end
183
187
 
184
188
  def truncate_tables(*table_names) # :nodoc:
@@ -186,9 +190,8 @@ module ActiveRecord
186
190
 
187
191
  with_multi_statements do
188
192
  disable_referential_integrity do
189
- Array(build_truncate_statements(*table_names)).each do |sql|
190
- execute_batch(sql, "Truncate Tables")
191
- end
193
+ statements = build_truncate_statements(table_names)
194
+ execute_batch(statements, "Truncate Tables")
192
195
  end
193
196
  end
194
197
  end
@@ -359,14 +362,12 @@ module ActiveRecord
359
362
  def insert_fixtures_set(fixture_set, tables_to_delete = [])
360
363
  fixture_inserts = build_fixture_statements(fixture_set)
361
364
  table_deletes = tables_to_delete.map { |table| "DELETE FROM #{quote_table_name(table)}" }
362
- total_sql = Array(combine_multi_statements(table_deletes + fixture_inserts))
365
+ statements = table_deletes + fixture_inserts
363
366
 
364
367
  with_multi_statements do
365
368
  disable_referential_integrity do
366
369
  transaction(requires_new: true) do
367
- total_sql.each do |sql|
368
- execute_batch(sql, "Fixtures Load")
369
- end
370
+ execute_batch(statements, "Fixtures Load")
370
371
  end
371
372
  end
372
373
  end
@@ -402,8 +403,10 @@ module ActiveRecord
402
403
  end
403
404
 
404
405
  private
405
- def execute_batch(sql, name = nil)
406
- execute(sql, name)
406
+ def execute_batch(statements, name = nil)
407
+ statements.each do |statement|
408
+ execute(statement, name)
409
+ end
407
410
  end
408
411
 
409
412
  DEFAULT_INSERT_VALUE = Arel.sql("DEFAULT").freeze
@@ -453,7 +456,7 @@ module ActiveRecord
453
456
  end
454
457
 
455
458
  manager.values = manager.create_values_list(values_list)
456
- manager.to_sql
459
+ visitor.compile(manager.ast)
457
460
  end
458
461
 
459
462
  def build_fixture_statements(fixture_set)
@@ -463,11 +466,14 @@ module ActiveRecord
463
466
  end.compact
464
467
  end
465
468
 
466
- def build_truncate_statements(*table_names)
467
- truncate_tables = table_names.map do |table_name|
468
- "TRUNCATE TABLE #{quote_table_name(table_name)}"
469
+ def build_truncate_statement(table_name)
470
+ "TRUNCATE TABLE #{quote_table_name(table_name)}"
471
+ end
472
+
473
+ def build_truncate_statements(table_names)
474
+ table_names.map do |table_name|
475
+ build_truncate_statement(table_name)
469
476
  end
470
- combine_multi_statements(truncate_tables)
471
477
  end
472
478
 
473
479
  def with_multi_statements
@@ -8,7 +8,7 @@ module ActiveRecord
8
8
  class << self
9
9
  def included(base) #:nodoc:
10
10
  dirties_query_cache base, :insert, :update, :delete, :truncate, :truncate_tables,
11
- :rollback_to_savepoint, :rollback_db_transaction
11
+ :rollback_to_savepoint, :rollback_db_transaction, :exec_insert_all
12
12
 
13
13
  base.set_callback :checkout, :after, :configure_query_cache!
14
14
  base.set_callback :checkin, :after, :disable_query_cache!
@@ -109,7 +109,6 @@ module ActiveRecord
109
109
  end
110
110
 
111
111
  private
112
-
113
112
  def cache_sql(sql, name, binds)
114
113
  @lock.synchronize do
115
114
  result =
@@ -135,6 +134,7 @@ module ActiveRecord
135
134
  type_casted_binds: -> { type_casted_binds(binds) },
136
135
  name: name,
137
136
  connection_id: object_id,
137
+ connection: self,
138
138
  cached: true
139
139
  }
140
140
  end
@@ -19,7 +19,6 @@ module ActiveRecord
19
19
  to: :@conn, private: true
20
20
 
21
21
  private
22
-
23
22
  def visit_AlterTable(o)
24
23
  sql = +"ALTER TABLE #{quote_table_name(o.name)} "
25
24
  sql << o.adds.map { |col| accept col }.join(" ")
@@ -28,7 +27,7 @@ module ActiveRecord
28
27
  end
29
28
 
30
29
  def visit_ColumnDefinition(o)
31
- o.sql_type = type_to_sql(o.type, o.options)
30
+ o.sql_type = type_to_sql(o.type, **o.options)
32
31
  column_sql = +"#{quote_column_name(o.name)} #{o.sql_type}"
33
32
  add_column_options!(column_sql, column_options(o)) unless o.type == :primary_key
34
33
  column_sql
@@ -139,7 +139,8 @@ module ActiveRecord
139
139
 
140
140
  def add_to(table)
141
141
  columns.each do |column_options|
142
- table.column(*column_options)
142
+ kwargs = column_options.extract_options!
143
+ table.column(*column_options, **kwargs)
143
144
  end
144
145
 
145
146
  if index
@@ -147,7 +148,7 @@ module ActiveRecord
147
148
  end
148
149
 
149
150
  if foreign_key
150
- table.foreign_key(foreign_table_name, foreign_key_options)
151
+ table.foreign_key(foreign_table_name, **foreign_key_options)
151
152
  end
152
153
  end
153
154
 
@@ -199,7 +200,7 @@ module ActiveRecord
199
200
  # Appends a primary key definition to the table definition.
200
201
  # Can be called multiple times, but this is probably not a good idea.
201
202
  def primary_key(name, type = :primary_key, **options)
202
- column(name, type, options.merge(primary_key: true))
203
+ column(name, type, **options.merge(primary_key: true))
203
204
  end
204
205
 
205
206
  ##
@@ -226,7 +227,7 @@ module ActiveRecord
226
227
  module_eval <<-RUBY, __FILE__, __LINE__ + 1
227
228
  def #{column_type}(*names, **options)
228
229
  raise ArgumentError, "Missing column name(s) for #{column_type}" if names.empty?
229
- names.each { |name| column(name, :#{column_type}, options) }
230
+ names.each { |name| column(name, :#{column_type}, **options) }
230
231
  end
231
232
  RUBY
232
233
  end
@@ -363,7 +364,6 @@ module ActiveRecord
363
364
  def column(name, type, **options)
364
365
  name = name.to_s
365
366
  type = type.to_sym if type
366
- options = options.dup
367
367
 
368
368
  if @columns_hash[name]
369
369
  if @columns_hash[name].primary_key?
@@ -375,7 +375,7 @@ module ActiveRecord
375
375
 
376
376
  index_options = options.delete(:index)
377
377
  index(name, index_options.is_a?(Hash) ? index_options : {}) if index_options
378
- @columns_hash[name] = new_column_definition(name, type, options)
378
+ @columns_hash[name] = new_column_definition(name, type, **options)
379
379
  self
380
380
  end
381
381
 
@@ -393,7 +393,7 @@ module ActiveRecord
393
393
  indexes << [column_name, options]
394
394
  end
395
395
 
396
- def foreign_key(table_name, options = {}) # :nodoc:
396
+ def foreign_key(table_name, **options) # :nodoc:
397
397
  foreign_keys << [table_name, options]
398
398
  end
399
399
 
@@ -408,8 +408,8 @@ module ActiveRecord
408
408
  options[:precision] = 6
409
409
  end
410
410
 
411
- column(:created_at, :datetime, options)
412
- column(:updated_at, :datetime, options)
411
+ column(:created_at, :datetime, **options)
412
+ column(:updated_at, :datetime, **options)
413
413
  end
414
414
 
415
415
  # Adds a reference.
@@ -421,7 +421,7 @@ module ActiveRecord
421
421
  # See {connection.add_reference}[rdoc-ref:SchemaStatements#add_reference] for details of the options you can use.
422
422
  def references(*args, **options)
423
423
  args.each do |ref_name|
424
- ReferenceDefinition.new(ref_name, options).add_to(self)
424
+ ReferenceDefinition.new(ref_name, **options).add_to(self)
425
425
  end
426
426
  end
427
427
  alias :belongs_to :references
@@ -476,10 +476,10 @@ module ActiveRecord
476
476
  @foreign_key_drops << name
477
477
  end
478
478
 
479
- def add_column(name, type, options)
479
+ def add_column(name, type, **options)
480
480
  name = name.to_s
481
481
  type = type.to_sym
482
- @adds << AddColumnDefinition.new(@td.new_column_definition(name, type, options))
482
+ @adds << AddColumnDefinition.new(@td.new_column_definition(name, type, **options))
483
483
  end
484
484
  end
485
485
 
@@ -540,7 +540,7 @@ module ActiveRecord
540
540
  # See TableDefinition#column for details of the options you can use.
541
541
  def column(column_name, type, **options)
542
542
  index_options = options.delete(:index)
543
- @base.add_column(name, column_name, type, options)
543
+ @base.add_column(name, column_name, type, **options)
544
544
  index(column_name, index_options.is_a?(Hash) ? index_options : {}) if index_options
545
545
  end
546
546
 
@@ -549,8 +549,8 @@ module ActiveRecord
549
549
  # t.string(:name) unless t.column_exists?(:name, :string)
550
550
  #
551
551
  # See {connection.column_exists?}[rdoc-ref:SchemaStatements#column_exists?]
552
- def column_exists?(column_name, type = nil, options = {})
553
- @base.column_exists?(name, column_name, type, options)
552
+ def column_exists?(column_name, type = nil, **options)
553
+ @base.column_exists?(name, column_name, type, **options)
554
554
  end
555
555
 
556
556
  # Adds a new index to the table. +column_name+ can be a single Symbol, or
@@ -590,8 +590,8 @@ module ActiveRecord
590
590
  # t.timestamps(null: false)
591
591
  #
592
592
  # See {connection.add_timestamps}[rdoc-ref:SchemaStatements#add_timestamps]
593
- def timestamps(options = {})
594
- @base.add_timestamps(name, options)
593
+ def timestamps(**options)
594
+ @base.add_timestamps(name, **options)
595
595
  end
596
596
 
597
597
  # Changes the column's definition according to the new options.
@@ -641,8 +641,8 @@ module ActiveRecord
641
641
  # t.remove_timestamps
642
642
  #
643
643
  # See {connection.remove_timestamps}[rdoc-ref:SchemaStatements#remove_timestamps]
644
- def remove_timestamps(options = {})
645
- @base.remove_timestamps(name, options)
644
+ def remove_timestamps(**options)
645
+ @base.remove_timestamps(name, **options)
646
646
  end
647
647
 
648
648
  # Renames a column.
@@ -662,7 +662,7 @@ module ActiveRecord
662
662
  # See {connection.add_reference}[rdoc-ref:SchemaStatements#add_reference] for details of the options you can use.
663
663
  def references(*args, **options)
664
664
  args.each do |ref_name|
665
- @base.add_reference(name, ref_name, options)
665
+ @base.add_reference(name, ref_name, **options)
666
666
  end
667
667
  end
668
668
  alias :belongs_to :references
@@ -675,7 +675,7 @@ module ActiveRecord
675
675
  # See {connection.remove_reference}[rdoc-ref:SchemaStatements#remove_reference]
676
676
  def remove_references(*args, **options)
677
677
  args.each do |ref_name|
678
- @base.remove_reference(name, ref_name, options)
678
+ @base.remove_reference(name, ref_name, **options)
679
679
  end
680
680
  end
681
681
  alias :remove_belongs_to :remove_references
@@ -686,8 +686,8 @@ module ActiveRecord
686
686
  # t.foreign_key(:authors, column: :author_id, primary_key: "id")
687
687
  #
688
688
  # See {connection.add_foreign_key}[rdoc-ref:SchemaStatements#add_foreign_key]
689
- def foreign_key(*args)
690
- @base.add_foreign_key(name, *args)
689
+ def foreign_key(*args, **options)
690
+ @base.add_foreign_key(name, *args, **options)
691
691
  end
692
692
 
693
693
  # Removes the given foreign key from the table.
@@ -696,8 +696,8 @@ module ActiveRecord
696
696
  # t.remove_foreign_key(column: :author_id)
697
697
  #
698
698
  # See {connection.remove_foreign_key}[rdoc-ref:SchemaStatements#remove_foreign_key]
699
- def remove_foreign_key(*args)
700
- @base.remove_foreign_key(name, *args)
699
+ def remove_foreign_key(*args, **options)
700
+ @base.remove_foreign_key(name, *args, **options)
701
701
  end
702
702
 
703
703
  # Checks to see if a foreign key exists.
@@ -705,8 +705,8 @@ module ActiveRecord
705
705
  # t.foreign_key(:authors) unless t.foreign_key_exists?(:authors)
706
706
  #
707
707
  # See {connection.foreign_key_exists?}[rdoc-ref:SchemaStatements#foreign_key_exists?]
708
- def foreign_key_exists?(*args)
709
- @base.foreign_key_exists?(name, *args)
708
+ def foreign_key_exists?(*args, **options)
709
+ @base.foreign_key_exists?(name, *args, **options)
710
710
  end
711
711
  end
712
712
  end