activerecord 6.1.4.1 → 7.0.2.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 (240) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +1203 -922
  3. data/MIT-LICENSE +1 -1
  4. data/README.rdoc +1 -1
  5. data/lib/active_record/aggregations.rb +1 -1
  6. data/lib/active_record/association_relation.rb +0 -10
  7. data/lib/active_record/associations/association.rb +33 -17
  8. data/lib/active_record/associations/association_scope.rb +1 -3
  9. data/lib/active_record/associations/belongs_to_association.rb +15 -4
  10. data/lib/active_record/associations/belongs_to_polymorphic_association.rb +10 -2
  11. data/lib/active_record/associations/builder/association.rb +8 -2
  12. data/lib/active_record/associations/builder/belongs_to.rb +19 -6
  13. data/lib/active_record/associations/builder/collection_association.rb +10 -3
  14. data/lib/active_record/associations/builder/has_many.rb +3 -2
  15. data/lib/active_record/associations/builder/has_one.rb +2 -1
  16. data/lib/active_record/associations/builder/singular_association.rb +2 -2
  17. data/lib/active_record/associations/collection_association.rb +34 -27
  18. data/lib/active_record/associations/collection_proxy.rb +8 -3
  19. data/lib/active_record/associations/disable_joins_association_scope.rb +59 -0
  20. data/lib/active_record/associations/has_many_association.rb +1 -1
  21. data/lib/active_record/associations/has_many_through_association.rb +2 -1
  22. data/lib/active_record/associations/has_one_association.rb +10 -7
  23. data/lib/active_record/associations/has_one_through_association.rb +1 -1
  24. data/lib/active_record/associations/join_dependency.rb +6 -2
  25. data/lib/active_record/associations/preloader/association.rb +187 -55
  26. data/lib/active_record/associations/preloader/batch.rb +48 -0
  27. data/lib/active_record/associations/preloader/branch.rb +147 -0
  28. data/lib/active_record/associations/preloader/through_association.rb +49 -13
  29. data/lib/active_record/associations/preloader.rb +39 -113
  30. data/lib/active_record/associations/singular_association.rb +8 -2
  31. data/lib/active_record/associations/through_association.rb +3 -3
  32. data/lib/active_record/associations.rb +119 -90
  33. data/lib/active_record/asynchronous_queries_tracker.rb +60 -0
  34. data/lib/active_record/attribute_assignment.rb +1 -1
  35. data/lib/active_record/attribute_methods/before_type_cast.rb +7 -2
  36. data/lib/active_record/attribute_methods/dirty.rb +49 -16
  37. data/lib/active_record/attribute_methods/primary_key.rb +2 -2
  38. data/lib/active_record/attribute_methods/query.rb +2 -2
  39. data/lib/active_record/attribute_methods/read.rb +7 -5
  40. data/lib/active_record/attribute_methods/serialization.rb +66 -12
  41. data/lib/active_record/attribute_methods/time_zone_conversion.rb +4 -3
  42. data/lib/active_record/attribute_methods/write.rb +7 -10
  43. data/lib/active_record/attribute_methods.rb +13 -14
  44. data/lib/active_record/attributes.rb +24 -35
  45. data/lib/active_record/autosave_association.rb +8 -23
  46. data/lib/active_record/base.rb +19 -1
  47. data/lib/active_record/callbacks.rb +2 -2
  48. data/lib/active_record/connection_adapters/abstract/connection_handler.rb +292 -0
  49. data/lib/active_record/connection_adapters/abstract/connection_pool/queue.rb +209 -0
  50. data/lib/active_record/connection_adapters/abstract/connection_pool/reaper.rb +76 -0
  51. data/lib/active_record/connection_adapters/abstract/connection_pool.rb +47 -561
  52. data/lib/active_record/connection_adapters/abstract/database_limits.rb +0 -17
  53. data/lib/active_record/connection_adapters/abstract/database_statements.rb +46 -22
  54. data/lib/active_record/connection_adapters/abstract/query_cache.rb +24 -12
  55. data/lib/active_record/connection_adapters/abstract/quoting.rb +42 -72
  56. data/lib/active_record/connection_adapters/abstract/schema_creation.rb +4 -17
  57. data/lib/active_record/connection_adapters/abstract/schema_definitions.rb +38 -13
  58. data/lib/active_record/connection_adapters/abstract/schema_dumper.rb +14 -1
  59. data/lib/active_record/connection_adapters/abstract/schema_statements.rb +78 -22
  60. data/lib/active_record/connection_adapters/abstract/transaction.rb +15 -22
  61. data/lib/active_record/connection_adapters/abstract_adapter.rb +149 -74
  62. data/lib/active_record/connection_adapters/abstract_mysql_adapter.rb +97 -81
  63. data/lib/active_record/connection_adapters/column.rb +4 -0
  64. data/lib/active_record/connection_adapters/mysql/database_statements.rb +38 -24
  65. data/lib/active_record/connection_adapters/mysql/quoting.rb +35 -21
  66. data/lib/active_record/connection_adapters/mysql/schema_dumper.rb +7 -1
  67. data/lib/active_record/connection_adapters/mysql/schema_statements.rb +5 -1
  68. data/lib/active_record/connection_adapters/mysql2_adapter.rb +12 -6
  69. data/lib/active_record/connection_adapters/pool_config.rb +7 -7
  70. data/lib/active_record/connection_adapters/postgresql/column.rb +17 -1
  71. data/lib/active_record/connection_adapters/postgresql/database_statements.rb +21 -12
  72. data/lib/active_record/connection_adapters/postgresql/oid/date.rb +8 -0
  73. data/lib/active_record/connection_adapters/postgresql/oid/date_time.rb +5 -0
  74. data/lib/active_record/connection_adapters/postgresql/oid/hstore.rb +53 -14
  75. data/lib/active_record/connection_adapters/postgresql/oid/range.rb +1 -1
  76. data/lib/active_record/connection_adapters/postgresql/oid/timestamp.rb +15 -0
  77. data/lib/active_record/connection_adapters/postgresql/oid/timestamp_with_time_zone.rb +30 -0
  78. data/lib/active_record/connection_adapters/postgresql/oid/type_map_initializer.rb +18 -6
  79. data/lib/active_record/connection_adapters/postgresql/oid.rb +2 -0
  80. data/lib/active_record/connection_adapters/postgresql/quoting.rb +50 -50
  81. data/lib/active_record/connection_adapters/postgresql/referential_integrity.rb +32 -0
  82. data/lib/active_record/connection_adapters/postgresql/schema_creation.rb +21 -1
  83. data/lib/active_record/connection_adapters/postgresql/schema_definitions.rb +22 -1
  84. data/lib/active_record/connection_adapters/postgresql/schema_dumper.rb +25 -0
  85. data/lib/active_record/connection_adapters/postgresql/schema_statements.rb +35 -19
  86. data/lib/active_record/connection_adapters/postgresql_adapter.rb +207 -107
  87. data/lib/active_record/connection_adapters/schema_cache.rb +29 -4
  88. data/lib/active_record/connection_adapters/sqlite3/database_statements.rb +27 -19
  89. data/lib/active_record/connection_adapters/sqlite3/quoting.rb +28 -16
  90. data/lib/active_record/connection_adapters/sqlite3/schema_statements.rb +16 -14
  91. data/lib/active_record/connection_adapters/sqlite3_adapter.rb +89 -30
  92. data/lib/active_record/connection_adapters.rb +6 -5
  93. data/lib/active_record/connection_handling.rb +47 -53
  94. data/lib/active_record/core.rb +122 -132
  95. data/lib/active_record/database_configurations/connection_url_resolver.rb +3 -1
  96. data/lib/active_record/database_configurations/database_config.rb +12 -9
  97. data/lib/active_record/database_configurations/hash_config.rb +63 -5
  98. data/lib/active_record/database_configurations/url_config.rb +2 -2
  99. data/lib/active_record/database_configurations.rb +16 -32
  100. data/lib/active_record/delegated_type.rb +52 -11
  101. data/lib/active_record/destroy_association_async_job.rb +1 -1
  102. data/lib/active_record/disable_joins_association_relation.rb +39 -0
  103. data/lib/active_record/dynamic_matchers.rb +1 -1
  104. data/lib/active_record/encryption/cipher/aes256_gcm.rb +98 -0
  105. data/lib/active_record/encryption/cipher.rb +53 -0
  106. data/lib/active_record/encryption/config.rb +44 -0
  107. data/lib/active_record/encryption/configurable.rb +61 -0
  108. data/lib/active_record/encryption/context.rb +35 -0
  109. data/lib/active_record/encryption/contexts.rb +72 -0
  110. data/lib/active_record/encryption/derived_secret_key_provider.rb +12 -0
  111. data/lib/active_record/encryption/deterministic_key_provider.rb +14 -0
  112. data/lib/active_record/encryption/encryptable_record.rb +208 -0
  113. data/lib/active_record/encryption/encrypted_attribute_type.rb +140 -0
  114. data/lib/active_record/encryption/encrypted_fixtures.rb +38 -0
  115. data/lib/active_record/encryption/encrypting_only_encryptor.rb +12 -0
  116. data/lib/active_record/encryption/encryptor.rb +155 -0
  117. data/lib/active_record/encryption/envelope_encryption_key_provider.rb +55 -0
  118. data/lib/active_record/encryption/errors.rb +15 -0
  119. data/lib/active_record/encryption/extended_deterministic_queries.rb +160 -0
  120. data/lib/active_record/encryption/extended_deterministic_uniqueness_validator.rb +28 -0
  121. data/lib/active_record/encryption/key.rb +28 -0
  122. data/lib/active_record/encryption/key_generator.rb +42 -0
  123. data/lib/active_record/encryption/key_provider.rb +46 -0
  124. data/lib/active_record/encryption/message.rb +33 -0
  125. data/lib/active_record/encryption/message_serializer.rb +90 -0
  126. data/lib/active_record/encryption/null_encryptor.rb +21 -0
  127. data/lib/active_record/encryption/properties.rb +76 -0
  128. data/lib/active_record/encryption/read_only_null_encryptor.rb +24 -0
  129. data/lib/active_record/encryption/scheme.rb +99 -0
  130. data/lib/active_record/encryption.rb +55 -0
  131. data/lib/active_record/enum.rb +49 -42
  132. data/lib/active_record/errors.rb +67 -4
  133. data/lib/active_record/explain_registry.rb +11 -6
  134. data/lib/active_record/fixture_set/file.rb +15 -1
  135. data/lib/active_record/fixture_set/table_row.rb +41 -6
  136. data/lib/active_record/fixture_set/table_rows.rb +4 -4
  137. data/lib/active_record/fixtures.rb +17 -20
  138. data/lib/active_record/future_result.rb +139 -0
  139. data/lib/active_record/gem_version.rb +4 -4
  140. data/lib/active_record/inheritance.rb +55 -17
  141. data/lib/active_record/insert_all.rb +80 -14
  142. data/lib/active_record/integration.rb +4 -3
  143. data/lib/active_record/internal_metadata.rb +3 -5
  144. data/lib/active_record/legacy_yaml_adapter.rb +2 -39
  145. data/lib/active_record/locking/optimistic.rb +10 -9
  146. data/lib/active_record/locking/pessimistic.rb +9 -3
  147. data/lib/active_record/log_subscriber.rb +14 -3
  148. data/lib/active_record/middleware/database_selector/resolver.rb +6 -10
  149. data/lib/active_record/middleware/database_selector.rb +8 -3
  150. data/lib/active_record/middleware/shard_selector.rb +60 -0
  151. data/lib/active_record/migration/command_recorder.rb +4 -4
  152. data/lib/active_record/migration/compatibility.rb +107 -3
  153. data/lib/active_record/migration/join_table.rb +1 -1
  154. data/lib/active_record/migration.rb +109 -79
  155. data/lib/active_record/model_schema.rb +45 -58
  156. data/lib/active_record/nested_attributes.rb +13 -12
  157. data/lib/active_record/no_touching.rb +3 -3
  158. data/lib/active_record/null_relation.rb +2 -6
  159. data/lib/active_record/persistence.rb +219 -52
  160. data/lib/active_record/query_cache.rb +2 -2
  161. data/lib/active_record/query_logs.rb +138 -0
  162. data/lib/active_record/querying.rb +15 -5
  163. data/lib/active_record/railtie.rb +127 -17
  164. data/lib/active_record/railties/controller_runtime.rb +1 -1
  165. data/lib/active_record/railties/databases.rake +66 -129
  166. data/lib/active_record/readonly_attributes.rb +11 -0
  167. data/lib/active_record/reflection.rb +67 -50
  168. data/lib/active_record/relation/batches/batch_enumerator.rb +19 -5
  169. data/lib/active_record/relation/batches.rb +3 -3
  170. data/lib/active_record/relation/calculations.rb +43 -38
  171. data/lib/active_record/relation/delegation.rb +7 -7
  172. data/lib/active_record/relation/finder_methods.rb +31 -35
  173. data/lib/active_record/relation/merger.rb +20 -13
  174. data/lib/active_record/relation/predicate_builder.rb +1 -6
  175. data/lib/active_record/relation/query_attribute.rb +5 -11
  176. data/lib/active_record/relation/query_methods.rb +249 -61
  177. data/lib/active_record/relation/record_fetch_warning.rb +7 -9
  178. data/lib/active_record/relation/spawn_methods.rb +2 -2
  179. data/lib/active_record/relation/where_clause.rb +10 -19
  180. data/lib/active_record/relation.rb +184 -84
  181. data/lib/active_record/result.rb +17 -7
  182. data/lib/active_record/runtime_registry.rb +9 -13
  183. data/lib/active_record/sanitization.rb +11 -7
  184. data/lib/active_record/schema.rb +38 -23
  185. data/lib/active_record/schema_dumper.rb +25 -19
  186. data/lib/active_record/schema_migration.rb +4 -4
  187. data/lib/active_record/scoping/default.rb +61 -12
  188. data/lib/active_record/scoping/named.rb +3 -11
  189. data/lib/active_record/scoping.rb +64 -34
  190. data/lib/active_record/serialization.rb +1 -1
  191. data/lib/active_record/signed_id.rb +1 -1
  192. data/lib/active_record/suppressor.rb +11 -15
  193. data/lib/active_record/tasks/database_tasks.rb +120 -58
  194. data/lib/active_record/tasks/mysql_database_tasks.rb +1 -1
  195. data/lib/active_record/tasks/postgresql_database_tasks.rb +19 -12
  196. data/lib/active_record/test_databases.rb +1 -1
  197. data/lib/active_record/test_fixtures.rb +4 -4
  198. data/lib/active_record/timestamp.rb +3 -4
  199. data/lib/active_record/transactions.rb +9 -14
  200. data/lib/active_record/translation.rb +2 -2
  201. data/lib/active_record/type/adapter_specific_registry.rb +32 -7
  202. data/lib/active_record/type/hash_lookup_type_map.rb +34 -1
  203. data/lib/active_record/type/internal/timezone.rb +2 -2
  204. data/lib/active_record/type/serialized.rb +1 -1
  205. data/lib/active_record/type/type_map.rb +17 -20
  206. data/lib/active_record/type.rb +1 -2
  207. data/lib/active_record/validations/associated.rb +1 -1
  208. data/lib/active_record/validations/uniqueness.rb +1 -1
  209. data/lib/active_record.rb +204 -28
  210. data/lib/arel/attributes/attribute.rb +0 -8
  211. data/lib/arel/crud.rb +28 -22
  212. data/lib/arel/delete_manager.rb +18 -4
  213. data/lib/arel/filter_predications.rb +9 -0
  214. data/lib/arel/insert_manager.rb +2 -3
  215. data/lib/arel/nodes/casted.rb +1 -1
  216. data/lib/arel/nodes/delete_statement.rb +12 -13
  217. data/lib/arel/nodes/filter.rb +10 -0
  218. data/lib/arel/nodes/function.rb +1 -0
  219. data/lib/arel/nodes/insert_statement.rb +2 -2
  220. data/lib/arel/nodes/select_core.rb +2 -2
  221. data/lib/arel/nodes/select_statement.rb +2 -2
  222. data/lib/arel/nodes/update_statement.rb +8 -3
  223. data/lib/arel/nodes.rb +1 -0
  224. data/lib/arel/predications.rb +11 -3
  225. data/lib/arel/select_manager.rb +10 -4
  226. data/lib/arel/table.rb +0 -1
  227. data/lib/arel/tree_manager.rb +0 -12
  228. data/lib/arel/update_manager.rb +18 -4
  229. data/lib/arel/visitors/dot.rb +80 -90
  230. data/lib/arel/visitors/mysql.rb +8 -2
  231. data/lib/arel/visitors/postgresql.rb +0 -10
  232. data/lib/arel/visitors/to_sql.rb +58 -2
  233. data/lib/arel.rb +2 -1
  234. data/lib/rails/generators/active_record/application_record/templates/application_record.rb.tt +1 -1
  235. data/lib/rails/generators/active_record/model/templates/abstract_base_class.rb.tt +1 -1
  236. data/lib/rails/generators/active_record/model/templates/model.rb.tt +1 -1
  237. data/lib/rails/generators/active_record/model/templates/module.rb.tt +2 -2
  238. data/lib/rails/generators/active_record/multi_db/multi_db_generator.rb +16 -0
  239. data/lib/rails/generators/active_record/multi_db/templates/multi_db.rb.tt +44 -0
  240. metadata +56 -11
@@ -103,7 +103,7 @@ module Arel # :nodoc: all
103
103
  row.each_with_index do |value, k|
104
104
  collector << ", " unless k == 0
105
105
  case value
106
- when Nodes::SqlLiteral, Nodes::BindParam
106
+ when Nodes::SqlLiteral, Nodes::BindParam, ActiveModel::Attribute
107
107
  collector = visit(value, collector)
108
108
  else
109
109
  collector << quote(value).to_s
@@ -135,6 +135,8 @@ module Arel # :nodoc: all
135
135
  visit_Arel_Nodes_SelectOptions(o, collector)
136
136
  end
137
137
 
138
+ # The Oracle enhanced adapter uses this private method,
139
+ # see https://github.com/rsim/oracle-enhanced/issues/2186
138
140
  def visit_Arel_Nodes_SelectOptions(o, collector)
139
141
  collector = maybe_visit o.limit, collector
140
142
  collector = maybe_visit o.offset, collector
@@ -243,6 +245,13 @@ module Arel # :nodoc: all
243
245
  collector << ")"
244
246
  end
245
247
 
248
+ def visit_Arel_Nodes_Filter(o, collector)
249
+ visit o.left, collector
250
+ collector << " FILTER (WHERE "
251
+ visit o.right, collector
252
+ collector << ")"
253
+ end
254
+
246
255
  def visit_Arel_Nodes_Rows(o, collector)
247
256
  if o.expr
248
257
  collector << "ROWS "
@@ -357,6 +366,17 @@ module Arel # :nodoc: all
357
366
  visit(o.expr, collector) << " DESC"
358
367
  end
359
368
 
369
+ # NullsFirst is available on all but MySQL, where it is redefined.
370
+ def visit_Arel_Nodes_NullsFirst(o, collector)
371
+ visit o.expr, collector
372
+ collector << " NULLS FIRST"
373
+ end
374
+
375
+ def visit_Arel_Nodes_NullsLast(o, collector)
376
+ visit o.expr, collector
377
+ collector << " NULLS LAST"
378
+ end
379
+
360
380
  def visit_Arel_Nodes_Group(o, collector)
361
381
  visit o.expr, collector
362
382
  end
@@ -412,24 +432,48 @@ module Arel # :nodoc: all
412
432
  end
413
433
 
414
434
  def visit_Arel_Nodes_GreaterThanOrEqual(o, collector)
435
+ case unboundable?(o.right)
436
+ when 1
437
+ return collector << "1=0"
438
+ when -1
439
+ return collector << "1=1"
440
+ end
415
441
  collector = visit o.left, collector
416
442
  collector << " >= "
417
443
  visit o.right, collector
418
444
  end
419
445
 
420
446
  def visit_Arel_Nodes_GreaterThan(o, collector)
447
+ case unboundable?(o.right)
448
+ when 1
449
+ return collector << "1=0"
450
+ when -1
451
+ return collector << "1=1"
452
+ end
421
453
  collector = visit o.left, collector
422
454
  collector << " > "
423
455
  visit o.right, collector
424
456
  end
425
457
 
426
458
  def visit_Arel_Nodes_LessThanOrEqual(o, collector)
459
+ case unboundable?(o.right)
460
+ when 1
461
+ return collector << "1=1"
462
+ when -1
463
+ return collector << "1=0"
464
+ end
427
465
  collector = visit o.left, collector
428
466
  collector << " <= "
429
467
  visit o.right, collector
430
468
  end
431
469
 
432
470
  def visit_Arel_Nodes_LessThan(o, collector)
471
+ case unboundable?(o.right)
472
+ when 1
473
+ return collector << "1=1"
474
+ when -1
475
+ return collector << "1=0"
476
+ end
433
477
  collector = visit o.left, collector
434
478
  collector << " < "
435
479
  visit o.right, collector
@@ -585,7 +629,7 @@ module Arel # :nodoc: all
585
629
 
586
630
  def visit_Arel_Nodes_Assignment(o, collector)
587
631
  case o.right
588
- when Arel::Nodes::Node, Arel::Attributes::Attribute
632
+ when Arel::Nodes::Node, Arel::Attributes::Attribute, ActiveModel::Attribute
589
633
  collector = visit o.left, collector
590
634
  collector << " = "
591
635
  visit o.right, collector
@@ -695,6 +739,10 @@ module Arel # :nodoc: all
695
739
 
696
740
  def bind_block; BIND_BLOCK; end
697
741
 
742
+ def visit_ActiveModel_Attribute(o, collector)
743
+ collector.add_bind(o, &bind_block)
744
+ end
745
+
698
746
  def visit_Arel_Nodes_BindParam(o, collector)
699
747
  collector.add_bind(o.value, &bind_block)
700
748
  end
@@ -793,6 +841,10 @@ module Arel # :nodoc: all
793
841
  o.limit || o.offset || !o.orders.empty?
794
842
  end
795
843
 
844
+ def has_group_by_and_having?(o)
845
+ !o.groups.empty? && !o.havings.empty?
846
+ end
847
+
796
848
  # The default strategy for an UPDATE with joins is to use a subquery. This doesn't work
797
849
  # on MySQL (even when aliasing the tables), but MySQL allows using JOIN directly in
798
850
  # an UPDATE statement, so in the MySQL visitor we redefine this to do that.
@@ -804,6 +856,8 @@ module Arel # :nodoc: all
804
856
  stmt.orders = []
805
857
  stmt.wheres = [Nodes::In.new(o.key, [build_subselect(o.key, o)])]
806
858
  stmt.relation = o.relation.left if has_join_sources?(o)
859
+ stmt.groups = o.groups unless o.groups.empty?
860
+ stmt.havings = o.havings unless o.havings.empty?
807
861
  stmt
808
862
  else
809
863
  o
@@ -818,6 +872,8 @@ module Arel # :nodoc: all
818
872
  core.froms = o.relation
819
873
  core.wheres = o.wheres
820
874
  core.projections = [key]
875
+ core.groups = o.groups unless o.groups.empty?
876
+ core.havings = o.havings unless o.havings.empty?
821
877
  stmt.limit = o.limit
822
878
  stmt.offset = o.offset
823
879
  stmt.orders = o.orders
data/lib/arel.rb CHANGED
@@ -7,6 +7,7 @@ require "arel/factory_methods"
7
7
 
8
8
  require "arel/expressions"
9
9
  require "arel/predications"
10
+ require "arel/filter_predications"
10
11
  require "arel/window_predications"
11
12
  require "arel/math"
12
13
  require "arel/alias_predication"
@@ -29,7 +30,7 @@ module Arel
29
30
 
30
31
  # Wrap a known-safe SQL string for passing to query methods, e.g.
31
32
  #
32
- # Post.order(Arel.sql("length(title)")).last
33
+ # Post.order(Arel.sql("REPLACE(title, 'misc', 'zzzz') asc")).pluck(:id)
33
34
  #
34
35
  # Great caution should be taken to avoid SQL injection vulnerabilities.
35
36
  # This method should not be used with unsafe values such as request
@@ -1,5 +1,5 @@
1
1
  <% module_namespacing do -%>
2
2
  class ApplicationRecord < ActiveRecord::Base
3
- self.abstract_class = true
3
+ primary_abstract_class
4
4
  end
5
5
  <% end -%>
@@ -2,6 +2,6 @@
2
2
  class <%= abstract_class_name %> < ApplicationRecord
3
3
  self.abstract_class = true
4
4
 
5
- connects_to database: { <%= ActiveRecord::Base.writing_role %>: :<%= database -%> }
5
+ connects_to database: { <%= ActiveRecord.writing_role %>: :<%= database -%> }
6
6
  end
7
7
  <% end -%>
@@ -1,7 +1,7 @@
1
1
  <% module_namespacing do -%>
2
2
  class <%= class_name %> < <%= parent_class_name.classify %>
3
3
  <% attributes.select(&:reference?).each do |attribute| -%>
4
- belongs_to :<%= attribute.name %><%= ', polymorphic: true' if attribute.polymorphic? %>
4
+ belongs_to :<%= attribute.name %><%= ", polymorphic: true" if attribute.polymorphic? %>
5
5
  <% end -%>
6
6
  <% attributes.select(&:rich_text?).each do |attribute| -%>
7
7
  has_rich_text :<%= attribute.name %>
@@ -1,7 +1,7 @@
1
1
  <% module_namespacing do -%>
2
- module <%= class_path.map(&:camelize).join('::') %>
2
+ module <%= class_path.map(&:camelize).join("::") %>
3
3
  def self.table_name_prefix
4
- '<%= namespaced? ? namespaced_class_path.join('_') : class_path.join('_') %>_'
4
+ "<%= namespaced? ? namespaced_class_path.join("_") : class_path.join("_") %>_"
5
5
  end
6
6
  end
7
7
  <% end -%>
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "rails/generators/active_record"
4
+
5
+ module ActiveRecord
6
+ module Generators # :nodoc:
7
+ class MultiDbGenerator < ::Rails::Generators::Base # :nodoc:
8
+ source_root File.expand_path("templates", __dir__)
9
+
10
+ def create_multi_db
11
+ filename = "multi_db.rb"
12
+ template filename, "config/initializers/#{filename}"
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,44 @@
1
+ # Multi-db Configuration
2
+ #
3
+ # This file is used for configuration settings related to multiple databases.
4
+ #
5
+ # Enable Database Selector
6
+ #
7
+ # Inserts middleware to perform automatic connection switching.
8
+ # The `database_selector` hash is used to pass options to the DatabaseSelector
9
+ # middleware. The `delay` is used to determine how long to wait after a write
10
+ # to send a subsequent read to the primary.
11
+ #
12
+ # The `database_resolver` class is used by the middleware to determine which
13
+ # database is appropriate to use based on the time delay.
14
+ #
15
+ # The `database_resolver_context` class is used by the middleware to set
16
+ # timestamps for the last write to the primary. The resolver uses the context
17
+ # class timestamps to determine how long to wait before reading from the
18
+ # replica.
19
+ #
20
+ # By default Rails will store a last write timestamp in the session. The
21
+ # DatabaseSelector middleware is designed as such you can define your own
22
+ # strategy for connection switching and pass that into the middleware through
23
+ # these configuration options.
24
+ #
25
+ # Rails.application.configure do
26
+ # config.active_record.database_selector = { delay: 2.seconds }
27
+ # config.active_record.database_resolver = ActiveRecord::Middleware::DatabaseSelector::Resolver
28
+ # config.active_record.database_resolver_context = ActiveRecord::Middleware::DatabaseSelector::Resolver::Session
29
+ # end
30
+ #
31
+ # Enable Shard Selector
32
+ #
33
+ # Inserts middleware to perform automatic shard swapping. The `shard_selector` hash
34
+ # can be used to pass options to the `ShardSelector` middleware. The `lock` option is
35
+ # used to determine whether shard swapping should be prohibited for the request.
36
+ #
37
+ # The `shard_resolver` option is used by the middleware to determine which shard
38
+ # to switch to. The application must provide a mechanism for finding the shard name
39
+ # in a proc. See guides for an example.
40
+ #
41
+ # Rails.application.configure do
42
+ # config.active_record.shard_selector = { lock: true }
43
+ # config.active_record.shard_resolver = ->(request) { Tenant.find_by!(host: request.host).shard }
44
+ # end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: activerecord
3
3
  version: !ruby/object:Gem::Version
4
- version: 6.1.4.1
4
+ version: 7.0.2.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - David Heinemeier Hansson
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-08-19 00:00:00.000000000 Z
11
+ date: 2022-03-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -16,28 +16,28 @@ dependencies:
16
16
  requirements:
17
17
  - - '='
18
18
  - !ruby/object:Gem::Version
19
- version: 6.1.4.1
19
+ version: 7.0.2.3
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - '='
25
25
  - !ruby/object:Gem::Version
26
- version: 6.1.4.1
26
+ version: 7.0.2.3
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: activemodel
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - '='
32
32
  - !ruby/object:Gem::Version
33
- version: 6.1.4.1
33
+ version: 7.0.2.3
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - '='
39
39
  - !ruby/object:Gem::Version
40
- version: 6.1.4.1
40
+ version: 7.0.2.3
41
41
  description: Databases on Rails. Build a persistent domain model by mapping database
42
42
  tables to Ruby classes. Strong conventions for associations, validations, aggregations,
43
43
  migrations, and testing come baked-in.
@@ -70,6 +70,7 @@ files:
70
70
  - lib/active_record/associations/builder/singular_association.rb
71
71
  - lib/active_record/associations/collection_association.rb
72
72
  - lib/active_record/associations/collection_proxy.rb
73
+ - lib/active_record/associations/disable_joins_association_scope.rb
73
74
  - lib/active_record/associations/foreign_association.rb
74
75
  - lib/active_record/associations/has_many_association.rb
75
76
  - lib/active_record/associations/has_many_through_association.rb
@@ -81,9 +82,12 @@ files:
81
82
  - lib/active_record/associations/join_dependency/join_part.rb
82
83
  - lib/active_record/associations/preloader.rb
83
84
  - lib/active_record/associations/preloader/association.rb
85
+ - lib/active_record/associations/preloader/batch.rb
86
+ - lib/active_record/associations/preloader/branch.rb
84
87
  - lib/active_record/associations/preloader/through_association.rb
85
88
  - lib/active_record/associations/singular_association.rb
86
89
  - lib/active_record/associations/through_association.rb
90
+ - lib/active_record/asynchronous_queries_tracker.rb
87
91
  - lib/active_record/attribute_assignment.rb
88
92
  - lib/active_record/attribute_methods.rb
89
93
  - lib/active_record/attribute_methods/before_type_cast.rb
@@ -101,7 +105,10 @@ files:
101
105
  - lib/active_record/coders/json.rb
102
106
  - lib/active_record/coders/yaml_column.rb
103
107
  - lib/active_record/connection_adapters.rb
108
+ - lib/active_record/connection_adapters/abstract/connection_handler.rb
104
109
  - lib/active_record/connection_adapters/abstract/connection_pool.rb
110
+ - lib/active_record/connection_adapters/abstract/connection_pool/queue.rb
111
+ - lib/active_record/connection_adapters/abstract/connection_pool/reaper.rb
105
112
  - lib/active_record/connection_adapters/abstract/database_limits.rb
106
113
  - lib/active_record/connection_adapters/abstract/database_statements.rb
107
114
  - lib/active_record/connection_adapters/abstract/query_cache.rb
@@ -153,6 +160,8 @@ files:
153
160
  - lib/active_record/connection_adapters/postgresql/oid/point.rb
154
161
  - lib/active_record/connection_adapters/postgresql/oid/range.rb
155
162
  - lib/active_record/connection_adapters/postgresql/oid/specialized_string.rb
163
+ - lib/active_record/connection_adapters/postgresql/oid/timestamp.rb
164
+ - lib/active_record/connection_adapters/postgresql/oid/timestamp_with_time_zone.rb
156
165
  - lib/active_record/connection_adapters/postgresql/oid/type_map_initializer.rb
157
166
  - lib/active_record/connection_adapters/postgresql/oid/uuid.rb
158
167
  - lib/active_record/connection_adapters/postgresql/oid/vector.rb
@@ -187,7 +196,35 @@ files:
187
196
  - lib/active_record/database_configurations/url_config.rb
188
197
  - lib/active_record/delegated_type.rb
189
198
  - lib/active_record/destroy_association_async_job.rb
199
+ - lib/active_record/disable_joins_association_relation.rb
190
200
  - lib/active_record/dynamic_matchers.rb
201
+ - lib/active_record/encryption.rb
202
+ - lib/active_record/encryption/cipher.rb
203
+ - lib/active_record/encryption/cipher/aes256_gcm.rb
204
+ - lib/active_record/encryption/config.rb
205
+ - lib/active_record/encryption/configurable.rb
206
+ - lib/active_record/encryption/context.rb
207
+ - lib/active_record/encryption/contexts.rb
208
+ - lib/active_record/encryption/derived_secret_key_provider.rb
209
+ - lib/active_record/encryption/deterministic_key_provider.rb
210
+ - lib/active_record/encryption/encryptable_record.rb
211
+ - lib/active_record/encryption/encrypted_attribute_type.rb
212
+ - lib/active_record/encryption/encrypted_fixtures.rb
213
+ - lib/active_record/encryption/encrypting_only_encryptor.rb
214
+ - lib/active_record/encryption/encryptor.rb
215
+ - lib/active_record/encryption/envelope_encryption_key_provider.rb
216
+ - lib/active_record/encryption/errors.rb
217
+ - lib/active_record/encryption/extended_deterministic_queries.rb
218
+ - lib/active_record/encryption/extended_deterministic_uniqueness_validator.rb
219
+ - lib/active_record/encryption/key.rb
220
+ - lib/active_record/encryption/key_generator.rb
221
+ - lib/active_record/encryption/key_provider.rb
222
+ - lib/active_record/encryption/message.rb
223
+ - lib/active_record/encryption/message_serializer.rb
224
+ - lib/active_record/encryption/null_encryptor.rb
225
+ - lib/active_record/encryption/properties.rb
226
+ - lib/active_record/encryption/read_only_null_encryptor.rb
227
+ - lib/active_record/encryption/scheme.rb
191
228
  - lib/active_record/enum.rb
192
229
  - lib/active_record/errors.rb
193
230
  - lib/active_record/explain.rb
@@ -199,6 +236,7 @@ files:
199
236
  - lib/active_record/fixture_set/table_row.rb
200
237
  - lib/active_record/fixture_set/table_rows.rb
201
238
  - lib/active_record/fixtures.rb
239
+ - lib/active_record/future_result.rb
202
240
  - lib/active_record/gem_version.rb
203
241
  - lib/active_record/inheritance.rb
204
242
  - lib/active_record/insert_all.rb
@@ -212,6 +250,7 @@ files:
212
250
  - lib/active_record/middleware/database_selector.rb
213
251
  - lib/active_record/middleware/database_selector/resolver.rb
214
252
  - lib/active_record/middleware/database_selector/resolver/session.rb
253
+ - lib/active_record/middleware/shard_selector.rb
215
254
  - lib/active_record/migration.rb
216
255
  - lib/active_record/migration/command_recorder.rb
217
256
  - lib/active_record/migration/compatibility.rb
@@ -222,6 +261,7 @@ files:
222
261
  - lib/active_record/null_relation.rb
223
262
  - lib/active_record/persistence.rb
224
263
  - lib/active_record/query_cache.rb
264
+ - lib/active_record/query_logs.rb
225
265
  - lib/active_record/querying.rb
226
266
  - lib/active_record/railtie.rb
227
267
  - lib/active_record/railties/console_sandbox.rb
@@ -312,6 +352,7 @@ files:
312
352
  - lib/arel/errors.rb
313
353
  - lib/arel/expressions.rb
314
354
  - lib/arel/factory_methods.rb
355
+ - lib/arel/filter_predications.rb
315
356
  - lib/arel/insert_manager.rb
316
357
  - lib/arel/math.rb
317
358
  - lib/arel/nodes.rb
@@ -328,6 +369,7 @@ files:
328
369
  - lib/arel/nodes/equality.rb
329
370
  - lib/arel/nodes/extract.rb
330
371
  - lib/arel/nodes/false.rb
372
+ - lib/arel/nodes/filter.rb
331
373
  - lib/arel/nodes/full_outer_join.rb
332
374
  - lib/arel/nodes/function.rb
333
375
  - lib/arel/nodes/grouping.rb
@@ -385,15 +427,18 @@ files:
385
427
  - lib/rails/generators/active_record/model/templates/abstract_base_class.rb.tt
386
428
  - lib/rails/generators/active_record/model/templates/model.rb.tt
387
429
  - lib/rails/generators/active_record/model/templates/module.rb.tt
430
+ - lib/rails/generators/active_record/multi_db/multi_db_generator.rb
431
+ - lib/rails/generators/active_record/multi_db/templates/multi_db.rb.tt
388
432
  homepage: https://rubyonrails.org
389
433
  licenses:
390
434
  - MIT
391
435
  metadata:
392
436
  bug_tracker_uri: https://github.com/rails/rails/issues
393
- changelog_uri: https://github.com/rails/rails/blob/v6.1.4.1/activerecord/CHANGELOG.md
394
- documentation_uri: https://api.rubyonrails.org/v6.1.4.1/
437
+ changelog_uri: https://github.com/rails/rails/blob/v7.0.2.3/activerecord/CHANGELOG.md
438
+ documentation_uri: https://api.rubyonrails.org/v7.0.2.3/
395
439
  mailing_list_uri: https://discuss.rubyonrails.org/c/rubyonrails-talk
396
- source_code_uri: https://github.com/rails/rails/tree/v6.1.4.1/activerecord
440
+ source_code_uri: https://github.com/rails/rails/tree/v7.0.2.3/activerecord
441
+ rubygems_mfa_required: 'true'
397
442
  post_install_message:
398
443
  rdoc_options:
399
444
  - "--main"
@@ -404,14 +449,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
404
449
  requirements:
405
450
  - - ">="
406
451
  - !ruby/object:Gem::Version
407
- version: 2.5.0
452
+ version: 2.7.0
408
453
  required_rubygems_version: !ruby/object:Gem::Requirement
409
454
  requirements:
410
455
  - - ">="
411
456
  - !ruby/object:Gem::Version
412
457
  version: '0'
413
458
  requirements: []
414
- rubygems_version: 3.2.15
459
+ rubygems_version: 3.1.6
415
460
  signing_key:
416
461
  specification_version: 4
417
462
  summary: Object-relational mapper framework (part of Rails).