activerecord 5.2.8 → 7.0.2

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 (364) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +1393 -587
  3. data/MIT-LICENSE +3 -1
  4. data/README.rdoc +7 -5
  5. data/examples/performance.rb +1 -1
  6. data/lib/active_record/aggregations.rb +10 -9
  7. data/lib/active_record/association_relation.rb +22 -12
  8. data/lib/active_record/associations/alias_tracker.rb +19 -16
  9. data/lib/active_record/associations/association.rb +122 -47
  10. data/lib/active_record/associations/association_scope.rb +24 -24
  11. data/lib/active_record/associations/belongs_to_association.rb +67 -49
  12. data/lib/active_record/associations/belongs_to_polymorphic_association.rb +16 -7
  13. data/lib/active_record/associations/builder/association.rb +52 -23
  14. data/lib/active_record/associations/builder/belongs_to.rb +44 -61
  15. data/lib/active_record/associations/builder/collection_association.rb +17 -19
  16. data/lib/active_record/associations/builder/has_and_belongs_to_many.rb +17 -41
  17. data/lib/active_record/associations/builder/has_many.rb +10 -3
  18. data/lib/active_record/associations/builder/has_one.rb +35 -3
  19. data/lib/active_record/associations/builder/singular_association.rb +5 -3
  20. data/lib/active_record/associations/collection_association.rb +59 -50
  21. data/lib/active_record/associations/collection_proxy.rb +32 -23
  22. data/lib/active_record/associations/disable_joins_association_scope.rb +59 -0
  23. data/lib/active_record/associations/foreign_association.rb +20 -0
  24. data/lib/active_record/associations/has_many_association.rb +27 -14
  25. data/lib/active_record/associations/has_many_through_association.rb +26 -19
  26. data/lib/active_record/associations/has_one_association.rb +52 -37
  27. data/lib/active_record/associations/has_one_through_association.rb +6 -6
  28. data/lib/active_record/associations/join_dependency/join_association.rb +44 -22
  29. data/lib/active_record/associations/join_dependency/join_part.rb +5 -5
  30. data/lib/active_record/associations/join_dependency.rb +97 -62
  31. data/lib/active_record/associations/preloader/association.rb +220 -60
  32. data/lib/active_record/associations/preloader/batch.rb +48 -0
  33. data/lib/active_record/associations/preloader/branch.rb +147 -0
  34. data/lib/active_record/associations/preloader/through_association.rb +85 -40
  35. data/lib/active_record/associations/preloader.rb +44 -105
  36. data/lib/active_record/associations/singular_association.rb +9 -17
  37. data/lib/active_record/associations/through_association.rb +4 -4
  38. data/lib/active_record/associations.rb +207 -66
  39. data/lib/active_record/asynchronous_queries_tracker.rb +60 -0
  40. data/lib/active_record/attribute_assignment.rb +17 -19
  41. data/lib/active_record/attribute_methods/before_type_cast.rb +19 -8
  42. data/lib/active_record/attribute_methods/dirty.rb +141 -47
  43. data/lib/active_record/attribute_methods/primary_key.rb +22 -27
  44. data/lib/active_record/attribute_methods/query.rb +6 -10
  45. data/lib/active_record/attribute_methods/read.rb +15 -55
  46. data/lib/active_record/attribute_methods/serialization.rb +77 -18
  47. data/lib/active_record/attribute_methods/time_zone_conversion.rb +16 -18
  48. data/lib/active_record/attribute_methods/write.rb +18 -37
  49. data/lib/active_record/attribute_methods.rb +90 -153
  50. data/lib/active_record/attributes.rb +38 -12
  51. data/lib/active_record/autosave_association.rb +50 -50
  52. data/lib/active_record/base.rb +23 -18
  53. data/lib/active_record/callbacks.rb +159 -44
  54. data/lib/active_record/coders/yaml_column.rb +12 -3
  55. data/lib/active_record/connection_adapters/abstract/connection_handler.rb +292 -0
  56. data/lib/active_record/connection_adapters/abstract/connection_pool/queue.rb +209 -0
  57. data/lib/active_record/connection_adapters/abstract/connection_pool/reaper.rb +76 -0
  58. data/lib/active_record/connection_adapters/abstract/connection_pool.rb +92 -464
  59. data/lib/active_record/connection_adapters/abstract/database_limits.rb +5 -51
  60. data/lib/active_record/connection_adapters/abstract/database_statements.rb +209 -164
  61. data/lib/active_record/connection_adapters/abstract/query_cache.rb +38 -22
  62. data/lib/active_record/connection_adapters/abstract/quoting.rb +103 -82
  63. data/lib/active_record/connection_adapters/abstract/savepoints.rb +3 -3
  64. data/lib/active_record/connection_adapters/abstract/schema_creation.rb +140 -110
  65. data/lib/active_record/connection_adapters/abstract/schema_definitions.rb +236 -94
  66. data/lib/active_record/connection_adapters/abstract/schema_dumper.rb +16 -5
  67. data/lib/active_record/connection_adapters/abstract/schema_statements.rb +456 -159
  68. data/lib/active_record/connection_adapters/abstract/transaction.rb +169 -78
  69. data/lib/active_record/connection_adapters/abstract_adapter.rb +367 -162
  70. data/lib/active_record/connection_adapters/abstract_mysql_adapter.rb +311 -327
  71. data/lib/active_record/connection_adapters/column.rb +33 -11
  72. data/lib/active_record/connection_adapters/deduplicable.rb +29 -0
  73. data/lib/active_record/connection_adapters/legacy_pool_manager.rb +35 -0
  74. data/lib/active_record/connection_adapters/mysql/column.rb +1 -1
  75. data/lib/active_record/connection_adapters/mysql/database_statements.rb +113 -45
  76. data/lib/active_record/connection_adapters/mysql/explain_pretty_printer.rb +1 -2
  77. data/lib/active_record/connection_adapters/mysql/quoting.rb +71 -5
  78. data/lib/active_record/connection_adapters/mysql/schema_creation.rb +34 -10
  79. data/lib/active_record/connection_adapters/mysql/schema_definitions.rb +48 -32
  80. data/lib/active_record/connection_adapters/mysql/schema_dumper.rb +25 -8
  81. data/lib/active_record/connection_adapters/mysql/schema_statements.rb +143 -19
  82. data/lib/active_record/connection_adapters/mysql/type_metadata.rb +14 -9
  83. data/lib/active_record/connection_adapters/mysql2_adapter.rb +63 -22
  84. data/lib/active_record/connection_adapters/pool_config.rb +73 -0
  85. data/lib/active_record/connection_adapters/pool_manager.rb +47 -0
  86. data/lib/active_record/connection_adapters/postgresql/column.rb +53 -28
  87. data/lib/active_record/connection_adapters/postgresql/database_statements.rb +56 -63
  88. data/lib/active_record/connection_adapters/postgresql/oid/array.rb +1 -2
  89. data/lib/active_record/connection_adapters/postgresql/oid/bit.rb +1 -4
  90. data/lib/active_record/connection_adapters/postgresql/oid/cidr.rb +3 -5
  91. data/lib/active_record/connection_adapters/postgresql/oid/date.rb +10 -2
  92. data/lib/active_record/connection_adapters/postgresql/oid/date_time.rb +15 -2
  93. data/lib/active_record/connection_adapters/postgresql/oid/enum.rb +0 -1
  94. data/lib/active_record/connection_adapters/postgresql/oid/hstore.rb +54 -16
  95. data/lib/active_record/connection_adapters/postgresql/oid/interval.rb +49 -0
  96. data/lib/active_record/connection_adapters/postgresql/oid/legacy_point.rb +3 -4
  97. data/lib/active_record/connection_adapters/postgresql/oid/macaddr.rb +25 -0
  98. data/lib/active_record/connection_adapters/postgresql/oid/oid.rb +1 -1
  99. data/lib/active_record/connection_adapters/postgresql/oid/point.rb +3 -4
  100. data/lib/active_record/connection_adapters/postgresql/oid/range.rb +25 -7
  101. data/lib/active_record/connection_adapters/postgresql/oid/specialized_string.rb +1 -1
  102. data/lib/active_record/connection_adapters/postgresql/oid/timestamp.rb +15 -0
  103. data/lib/active_record/connection_adapters/postgresql/oid/timestamp_with_time_zone.rb +30 -0
  104. data/lib/active_record/connection_adapters/postgresql/oid/type_map_initializer.rb +26 -12
  105. data/lib/active_record/connection_adapters/postgresql/oid/uuid.rb +15 -3
  106. data/lib/active_record/connection_adapters/postgresql/oid.rb +4 -0
  107. data/lib/active_record/connection_adapters/postgresql/quoting.rb +89 -52
  108. data/lib/active_record/connection_adapters/postgresql/referential_integrity.rb +34 -2
  109. data/lib/active_record/connection_adapters/postgresql/schema_creation.rb +39 -4
  110. data/lib/active_record/connection_adapters/postgresql/schema_definitions.rb +128 -91
  111. data/lib/active_record/connection_adapters/postgresql/schema_dumper.rb +25 -1
  112. data/lib/active_record/connection_adapters/postgresql/schema_statements.rb +149 -113
  113. data/lib/active_record/connection_adapters/postgresql/type_metadata.rb +31 -26
  114. data/lib/active_record/connection_adapters/postgresql/utils.rb +0 -1
  115. data/lib/active_record/connection_adapters/postgresql_adapter.rb +386 -182
  116. data/lib/active_record/connection_adapters/schema_cache.rb +161 -22
  117. data/lib/active_record/connection_adapters/sql_type_metadata.rb +17 -6
  118. data/lib/active_record/connection_adapters/sqlite3/database_statements.rb +152 -0
  119. data/lib/active_record/connection_adapters/sqlite3/quoting.rb +65 -18
  120. data/lib/active_record/connection_adapters/sqlite3/schema_creation.rb +5 -1
  121. data/lib/active_record/connection_adapters/sqlite3/schema_statements.rb +92 -26
  122. data/lib/active_record/connection_adapters/sqlite3_adapter.rb +251 -204
  123. data/lib/active_record/connection_adapters/statement_pool.rb +0 -1
  124. data/lib/active_record/connection_adapters.rb +53 -0
  125. data/lib/active_record/connection_handling.rb +292 -38
  126. data/lib/active_record/core.rb +385 -158
  127. data/lib/active_record/counter_cache.rb +8 -30
  128. data/lib/active_record/database_configurations/connection_url_resolver.rb +100 -0
  129. data/lib/active_record/database_configurations/database_config.rb +83 -0
  130. data/lib/active_record/database_configurations/hash_config.rb +154 -0
  131. data/lib/active_record/database_configurations/url_config.rb +53 -0
  132. data/lib/active_record/database_configurations.rb +256 -0
  133. data/lib/active_record/delegated_type.rb +250 -0
  134. data/lib/active_record/destroy_association_async_job.rb +36 -0
  135. data/lib/active_record/disable_joins_association_relation.rb +39 -0
  136. data/lib/active_record/dynamic_matchers.rb +4 -5
  137. data/lib/active_record/encryption/cipher/aes256_gcm.rb +98 -0
  138. data/lib/active_record/encryption/cipher.rb +53 -0
  139. data/lib/active_record/encryption/config.rb +44 -0
  140. data/lib/active_record/encryption/configurable.rb +61 -0
  141. data/lib/active_record/encryption/context.rb +35 -0
  142. data/lib/active_record/encryption/contexts.rb +72 -0
  143. data/lib/active_record/encryption/derived_secret_key_provider.rb +12 -0
  144. data/lib/active_record/encryption/deterministic_key_provider.rb +14 -0
  145. data/lib/active_record/encryption/encryptable_record.rb +208 -0
  146. data/lib/active_record/encryption/encrypted_attribute_type.rb +140 -0
  147. data/lib/active_record/encryption/encrypted_fixtures.rb +38 -0
  148. data/lib/active_record/encryption/encrypting_only_encryptor.rb +12 -0
  149. data/lib/active_record/encryption/encryptor.rb +155 -0
  150. data/lib/active_record/encryption/envelope_encryption_key_provider.rb +55 -0
  151. data/lib/active_record/encryption/errors.rb +15 -0
  152. data/lib/active_record/encryption/extended_deterministic_queries.rb +160 -0
  153. data/lib/active_record/encryption/extended_deterministic_uniqueness_validator.rb +28 -0
  154. data/lib/active_record/encryption/key.rb +28 -0
  155. data/lib/active_record/encryption/key_generator.rb +42 -0
  156. data/lib/active_record/encryption/key_provider.rb +46 -0
  157. data/lib/active_record/encryption/message.rb +33 -0
  158. data/lib/active_record/encryption/message_serializer.rb +90 -0
  159. data/lib/active_record/encryption/null_encryptor.rb +21 -0
  160. data/lib/active_record/encryption/properties.rb +76 -0
  161. data/lib/active_record/encryption/read_only_null_encryptor.rb +24 -0
  162. data/lib/active_record/encryption/scheme.rb +99 -0
  163. data/lib/active_record/encryption.rb +55 -0
  164. data/lib/active_record/enum.rb +130 -51
  165. data/lib/active_record/errors.rb +129 -23
  166. data/lib/active_record/explain.rb +10 -6
  167. data/lib/active_record/explain_registry.rb +11 -6
  168. data/lib/active_record/explain_subscriber.rb +1 -1
  169. data/lib/active_record/fixture_set/file.rb +22 -15
  170. data/lib/active_record/fixture_set/model_metadata.rb +32 -0
  171. data/lib/active_record/fixture_set/render_context.rb +17 -0
  172. data/lib/active_record/fixture_set/table_row.rb +187 -0
  173. data/lib/active_record/fixture_set/table_rows.rb +46 -0
  174. data/lib/active_record/fixtures.rb +206 -490
  175. data/lib/active_record/future_result.rb +139 -0
  176. data/lib/active_record/gem_version.rb +3 -3
  177. data/lib/active_record/inheritance.rb +104 -37
  178. data/lib/active_record/insert_all.rb +278 -0
  179. data/lib/active_record/integration.rb +69 -18
  180. data/lib/active_record/internal_metadata.rb +24 -9
  181. data/lib/active_record/legacy_yaml_adapter.rb +3 -36
  182. data/lib/active_record/locking/optimistic.rb +41 -26
  183. data/lib/active_record/locking/pessimistic.rb +18 -8
  184. data/lib/active_record/log_subscriber.rb +46 -35
  185. data/lib/active_record/middleware/database_selector/resolver/session.rb +48 -0
  186. data/lib/active_record/middleware/database_selector/resolver.rb +88 -0
  187. data/lib/active_record/middleware/database_selector.rb +82 -0
  188. data/lib/active_record/middleware/shard_selector.rb +60 -0
  189. data/lib/active_record/migration/command_recorder.rb +96 -44
  190. data/lib/active_record/migration/compatibility.rb +246 -64
  191. data/lib/active_record/migration/join_table.rb +1 -2
  192. data/lib/active_record/migration.rb +266 -187
  193. data/lib/active_record/model_schema.rb +165 -52
  194. data/lib/active_record/nested_attributes.rb +17 -19
  195. data/lib/active_record/no_touching.rb +11 -4
  196. data/lib/active_record/null_relation.rb +2 -7
  197. data/lib/active_record/persistence.rb +467 -92
  198. data/lib/active_record/query_cache.rb +21 -4
  199. data/lib/active_record/query_logs.rb +138 -0
  200. data/lib/active_record/querying.rb +51 -24
  201. data/lib/active_record/railtie.rb +224 -57
  202. data/lib/active_record/railties/console_sandbox.rb +2 -4
  203. data/lib/active_record/railties/controller_runtime.rb +31 -36
  204. data/lib/active_record/railties/databases.rake +369 -101
  205. data/lib/active_record/readonly_attributes.rb +15 -0
  206. data/lib/active_record/reflection.rb +170 -137
  207. data/lib/active_record/relation/batches/batch_enumerator.rb +44 -14
  208. data/lib/active_record/relation/batches.rb +46 -37
  209. data/lib/active_record/relation/calculations.rb +168 -96
  210. data/lib/active_record/relation/delegation.rb +37 -52
  211. data/lib/active_record/relation/finder_methods.rb +79 -58
  212. data/lib/active_record/relation/from_clause.rb +5 -1
  213. data/lib/active_record/relation/merger.rb +50 -51
  214. data/lib/active_record/relation/predicate_builder/array_handler.rb +13 -13
  215. data/lib/active_record/relation/predicate_builder/association_query_value.rb +5 -9
  216. data/lib/active_record/relation/predicate_builder/basic_object_handler.rb +1 -2
  217. data/lib/active_record/relation/predicate_builder/polymorphic_array_value.rb +11 -10
  218. data/lib/active_record/relation/predicate_builder/range_handler.rb +3 -23
  219. data/lib/active_record/relation/predicate_builder/relation_handler.rb +1 -1
  220. data/lib/active_record/relation/predicate_builder.rb +58 -46
  221. data/lib/active_record/relation/query_attribute.rb +9 -10
  222. data/lib/active_record/relation/query_methods.rb +685 -208
  223. data/lib/active_record/relation/record_fetch_warning.rb +9 -11
  224. data/lib/active_record/relation/spawn_methods.rb +10 -10
  225. data/lib/active_record/relation/where_clause.rb +108 -64
  226. data/lib/active_record/relation.rb +515 -151
  227. data/lib/active_record/result.rb +78 -42
  228. data/lib/active_record/runtime_registry.rb +9 -13
  229. data/lib/active_record/sanitization.rb +29 -44
  230. data/lib/active_record/schema.rb +37 -31
  231. data/lib/active_record/schema_dumper.rb +74 -23
  232. data/lib/active_record/schema_migration.rb +7 -9
  233. data/lib/active_record/scoping/default.rb +62 -17
  234. data/lib/active_record/scoping/named.rb +17 -32
  235. data/lib/active_record/scoping.rb +70 -41
  236. data/lib/active_record/secure_token.rb +16 -8
  237. data/lib/active_record/serialization.rb +6 -4
  238. data/lib/active_record/signed_id.rb +116 -0
  239. data/lib/active_record/statement_cache.rb +49 -6
  240. data/lib/active_record/store.rb +88 -9
  241. data/lib/active_record/suppressor.rb +13 -17
  242. data/lib/active_record/table_metadata.rb +42 -43
  243. data/lib/active_record/tasks/database_tasks.rb +352 -94
  244. data/lib/active_record/tasks/mysql_database_tasks.rb +37 -39
  245. data/lib/active_record/tasks/postgresql_database_tasks.rb +41 -39
  246. data/lib/active_record/tasks/sqlite_database_tasks.rb +14 -17
  247. data/lib/active_record/test_databases.rb +24 -0
  248. data/lib/active_record/test_fixtures.rb +287 -0
  249. data/lib/active_record/timestamp.rb +44 -34
  250. data/lib/active_record/touch_later.rb +23 -22
  251. data/lib/active_record/transactions.rb +67 -128
  252. data/lib/active_record/translation.rb +3 -3
  253. data/lib/active_record/type/adapter_specific_registry.rb +34 -19
  254. data/lib/active_record/type/hash_lookup_type_map.rb +34 -2
  255. data/lib/active_record/type/internal/timezone.rb +2 -2
  256. data/lib/active_record/type/serialized.rb +7 -4
  257. data/lib/active_record/type/time.rb +10 -0
  258. data/lib/active_record/type/type_map.rb +17 -21
  259. data/lib/active_record/type/unsigned_integer.rb +0 -1
  260. data/lib/active_record/type.rb +9 -5
  261. data/lib/active_record/type_caster/connection.rb +15 -15
  262. data/lib/active_record/type_caster/map.rb +8 -8
  263. data/lib/active_record/validations/associated.rb +2 -3
  264. data/lib/active_record/validations/numericality.rb +35 -0
  265. data/lib/active_record/validations/uniqueness.rb +39 -31
  266. data/lib/active_record/validations.rb +4 -3
  267. data/lib/active_record.rb +209 -32
  268. data/lib/arel/alias_predication.rb +9 -0
  269. data/lib/arel/attributes/attribute.rb +33 -0
  270. data/lib/arel/collectors/bind.rb +29 -0
  271. data/lib/arel/collectors/composite.rb +39 -0
  272. data/lib/arel/collectors/plain_string.rb +20 -0
  273. data/lib/arel/collectors/sql_string.rb +27 -0
  274. data/lib/arel/collectors/substitute_binds.rb +35 -0
  275. data/lib/arel/crud.rb +48 -0
  276. data/lib/arel/delete_manager.rb +32 -0
  277. data/lib/arel/errors.rb +9 -0
  278. data/lib/arel/expressions.rb +29 -0
  279. data/lib/arel/factory_methods.rb +49 -0
  280. data/lib/arel/filter_predications.rb +9 -0
  281. data/lib/arel/insert_manager.rb +48 -0
  282. data/lib/arel/math.rb +45 -0
  283. data/lib/arel/nodes/and.rb +32 -0
  284. data/lib/arel/nodes/ascending.rb +23 -0
  285. data/lib/arel/nodes/binary.rb +126 -0
  286. data/lib/arel/nodes/bind_param.rb +44 -0
  287. data/lib/arel/nodes/case.rb +55 -0
  288. data/lib/arel/nodes/casted.rb +62 -0
  289. data/lib/arel/nodes/comment.rb +29 -0
  290. data/lib/arel/nodes/count.rb +12 -0
  291. data/lib/arel/nodes/delete_statement.rb +44 -0
  292. data/lib/arel/nodes/descending.rb +23 -0
  293. data/lib/arel/nodes/equality.rb +15 -0
  294. data/lib/arel/nodes/extract.rb +24 -0
  295. data/lib/arel/nodes/false.rb +16 -0
  296. data/lib/arel/nodes/filter.rb +10 -0
  297. data/lib/arel/nodes/full_outer_join.rb +8 -0
  298. data/lib/arel/nodes/function.rb +45 -0
  299. data/lib/arel/nodes/grouping.rb +11 -0
  300. data/lib/arel/nodes/homogeneous_in.rb +76 -0
  301. data/lib/arel/nodes/in.rb +15 -0
  302. data/lib/arel/nodes/infix_operation.rb +92 -0
  303. data/lib/arel/nodes/inner_join.rb +8 -0
  304. data/lib/arel/nodes/insert_statement.rb +37 -0
  305. data/lib/arel/nodes/join_source.rb +20 -0
  306. data/lib/arel/nodes/matches.rb +18 -0
  307. data/lib/arel/nodes/named_function.rb +23 -0
  308. data/lib/arel/nodes/node.rb +51 -0
  309. data/lib/arel/nodes/node_expression.rb +13 -0
  310. data/lib/arel/nodes/ordering.rb +27 -0
  311. data/lib/arel/nodes/outer_join.rb +8 -0
  312. data/lib/arel/nodes/over.rb +15 -0
  313. data/lib/arel/nodes/regexp.rb +16 -0
  314. data/lib/arel/nodes/right_outer_join.rb +8 -0
  315. data/lib/arel/nodes/select_core.rb +67 -0
  316. data/lib/arel/nodes/select_statement.rb +41 -0
  317. data/lib/arel/nodes/sql_literal.rb +19 -0
  318. data/lib/arel/nodes/string_join.rb +11 -0
  319. data/lib/arel/nodes/table_alias.rb +31 -0
  320. data/lib/arel/nodes/terminal.rb +16 -0
  321. data/lib/arel/nodes/true.rb +16 -0
  322. data/lib/arel/nodes/unary.rb +44 -0
  323. data/lib/arel/nodes/unary_operation.rb +20 -0
  324. data/lib/arel/nodes/unqualified_column.rb +22 -0
  325. data/lib/arel/nodes/update_statement.rb +46 -0
  326. data/lib/arel/nodes/values_list.rb +9 -0
  327. data/lib/arel/nodes/window.rb +126 -0
  328. data/lib/arel/nodes/with.rb +11 -0
  329. data/lib/arel/nodes.rb +71 -0
  330. data/lib/arel/order_predications.rb +13 -0
  331. data/lib/arel/predications.rb +258 -0
  332. data/lib/arel/select_manager.rb +276 -0
  333. data/lib/arel/table.rb +117 -0
  334. data/lib/arel/tree_manager.rb +60 -0
  335. data/lib/arel/update_manager.rb +48 -0
  336. data/lib/arel/visitors/dot.rb +298 -0
  337. data/lib/arel/visitors/mysql.rb +99 -0
  338. data/lib/arel/visitors/postgresql.rb +110 -0
  339. data/lib/arel/visitors/sqlite.rb +38 -0
  340. data/lib/arel/visitors/to_sql.rb +955 -0
  341. data/lib/arel/visitors/visitor.rb +45 -0
  342. data/lib/arel/visitors.rb +13 -0
  343. data/lib/arel/window_predications.rb +9 -0
  344. data/lib/arel.rb +55 -0
  345. data/lib/rails/generators/active_record/application_record/application_record_generator.rb +0 -1
  346. data/lib/rails/generators/active_record/application_record/templates/application_record.rb.tt +1 -1
  347. data/lib/rails/generators/active_record/migration/migration_generator.rb +3 -5
  348. data/lib/rails/generators/active_record/migration/templates/create_table_migration.rb.tt +3 -1
  349. data/lib/rails/generators/active_record/migration/templates/migration.rb.tt +7 -5
  350. data/lib/rails/generators/active_record/migration.rb +19 -2
  351. data/lib/rails/generators/active_record/model/model_generator.rb +39 -2
  352. data/lib/rails/generators/active_record/model/templates/abstract_base_class.rb.tt +7 -0
  353. data/lib/rails/generators/active_record/model/templates/model.rb.tt +10 -1
  354. data/lib/rails/generators/active_record/model/templates/module.rb.tt +2 -2
  355. data/lib/rails/generators/active_record/multi_db/multi_db_generator.rb +16 -0
  356. data/lib/rails/generators/active_record/multi_db/templates/multi_db.rb.tt +44 -0
  357. metadata +162 -32
  358. data/lib/active_record/attribute_decorators.rb +0 -90
  359. data/lib/active_record/collection_cache_key.rb +0 -53
  360. data/lib/active_record/connection_adapters/connection_specification.rb +0 -287
  361. data/lib/active_record/connection_adapters/determine_if_preparable_visitor.rb +0 -33
  362. data/lib/active_record/define_callbacks.rb +0 -22
  363. data/lib/active_record/relation/predicate_builder/base_handler.rb +0 -19
  364. data/lib/active_record/relation/where_clause_factory.rb +0 -34
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: 5.2.8
4
+ version: 7.0.2
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: 2022-05-09 00:00:00.000000000 Z
11
+ date: 2022-02-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -16,42 +16,28 @@ dependencies:
16
16
  requirements:
17
17
  - - '='
18
18
  - !ruby/object:Gem::Version
19
- version: 5.2.8
19
+ version: 7.0.2
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: 5.2.8
26
+ version: 7.0.2
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: 5.2.8
33
+ version: 7.0.2
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: 5.2.8
41
- - !ruby/object:Gem::Dependency
42
- name: arel
43
- requirement: !ruby/object:Gem::Requirement
44
- requirements:
45
- - - ">="
46
- - !ruby/object:Gem::Version
47
- version: '9.0'
48
- type: :runtime
49
- prerelease: false
50
- version_requirements: !ruby/object:Gem::Requirement
51
- requirements:
52
- - - ">="
53
- - !ruby/object:Gem::Version
54
- version: '9.0'
40
+ version: 7.0.2
55
41
  description: Databases on Rails. Build a persistent domain model by mapping database
56
42
  tables to Ruby classes. Strong conventions for associations, validations, aggregations,
57
43
  migrations, and testing come baked-in.
@@ -84,6 +70,7 @@ files:
84
70
  - lib/active_record/associations/builder/singular_association.rb
85
71
  - lib/active_record/associations/collection_association.rb
86
72
  - lib/active_record/associations/collection_proxy.rb
73
+ - lib/active_record/associations/disable_joins_association_scope.rb
87
74
  - lib/active_record/associations/foreign_association.rb
88
75
  - lib/active_record/associations/has_many_association.rb
89
76
  - lib/active_record/associations/has_many_through_association.rb
@@ -95,11 +82,13 @@ files:
95
82
  - lib/active_record/associations/join_dependency/join_part.rb
96
83
  - lib/active_record/associations/preloader.rb
97
84
  - lib/active_record/associations/preloader/association.rb
85
+ - lib/active_record/associations/preloader/batch.rb
86
+ - lib/active_record/associations/preloader/branch.rb
98
87
  - lib/active_record/associations/preloader/through_association.rb
99
88
  - lib/active_record/associations/singular_association.rb
100
89
  - lib/active_record/associations/through_association.rb
90
+ - lib/active_record/asynchronous_queries_tracker.rb
101
91
  - lib/active_record/attribute_assignment.rb
102
- - lib/active_record/attribute_decorators.rb
103
92
  - lib/active_record/attribute_methods.rb
104
93
  - lib/active_record/attribute_methods/before_type_cast.rb
105
94
  - lib/active_record/attribute_methods/dirty.rb
@@ -115,8 +104,11 @@ files:
115
104
  - lib/active_record/callbacks.rb
116
105
  - lib/active_record/coders/json.rb
117
106
  - lib/active_record/coders/yaml_column.rb
118
- - lib/active_record/collection_cache_key.rb
107
+ - lib/active_record/connection_adapters.rb
108
+ - lib/active_record/connection_adapters/abstract/connection_handler.rb
119
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
120
112
  - lib/active_record/connection_adapters/abstract/database_limits.rb
121
113
  - lib/active_record/connection_adapters/abstract/database_statements.rb
122
114
  - lib/active_record/connection_adapters/abstract/query_cache.rb
@@ -130,8 +122,8 @@ files:
130
122
  - lib/active_record/connection_adapters/abstract_adapter.rb
131
123
  - lib/active_record/connection_adapters/abstract_mysql_adapter.rb
132
124
  - lib/active_record/connection_adapters/column.rb
133
- - lib/active_record/connection_adapters/connection_specification.rb
134
- - lib/active_record/connection_adapters/determine_if_preparable_visitor.rb
125
+ - lib/active_record/connection_adapters/deduplicable.rb
126
+ - lib/active_record/connection_adapters/legacy_pool_manager.rb
135
127
  - lib/active_record/connection_adapters/mysql/column.rb
136
128
  - lib/active_record/connection_adapters/mysql/database_statements.rb
137
129
  - lib/active_record/connection_adapters/mysql/explain_pretty_printer.rb
@@ -142,6 +134,8 @@ files:
142
134
  - lib/active_record/connection_adapters/mysql/schema_statements.rb
143
135
  - lib/active_record/connection_adapters/mysql/type_metadata.rb
144
136
  - lib/active_record/connection_adapters/mysql2_adapter.rb
137
+ - lib/active_record/connection_adapters/pool_config.rb
138
+ - lib/active_record/connection_adapters/pool_manager.rb
145
139
  - lib/active_record/connection_adapters/postgresql/column.rb
146
140
  - lib/active_record/connection_adapters/postgresql/database_statements.rb
147
141
  - lib/active_record/connection_adapters/postgresql/explain_pretty_printer.rb
@@ -157,13 +151,17 @@ files:
157
151
  - lib/active_record/connection_adapters/postgresql/oid/enum.rb
158
152
  - lib/active_record/connection_adapters/postgresql/oid/hstore.rb
159
153
  - lib/active_record/connection_adapters/postgresql/oid/inet.rb
154
+ - lib/active_record/connection_adapters/postgresql/oid/interval.rb
160
155
  - lib/active_record/connection_adapters/postgresql/oid/jsonb.rb
161
156
  - lib/active_record/connection_adapters/postgresql/oid/legacy_point.rb
157
+ - lib/active_record/connection_adapters/postgresql/oid/macaddr.rb
162
158
  - lib/active_record/connection_adapters/postgresql/oid/money.rb
163
159
  - lib/active_record/connection_adapters/postgresql/oid/oid.rb
164
160
  - lib/active_record/connection_adapters/postgresql/oid/point.rb
165
161
  - lib/active_record/connection_adapters/postgresql/oid/range.rb
166
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
167
165
  - lib/active_record/connection_adapters/postgresql/oid/type_map_initializer.rb
168
166
  - lib/active_record/connection_adapters/postgresql/oid/uuid.rb
169
167
  - lib/active_record/connection_adapters/postgresql/oid/vector.rb
@@ -179,6 +177,7 @@ files:
179
177
  - lib/active_record/connection_adapters/postgresql_adapter.rb
180
178
  - lib/active_record/connection_adapters/schema_cache.rb
181
179
  - lib/active_record/connection_adapters/sql_type_metadata.rb
180
+ - lib/active_record/connection_adapters/sqlite3/database_statements.rb
182
181
  - lib/active_record/connection_adapters/sqlite3/explain_pretty_printer.rb
183
182
  - lib/active_record/connection_adapters/sqlite3/quoting.rb
184
183
  - lib/active_record/connection_adapters/sqlite3/schema_creation.rb
@@ -190,17 +189,57 @@ files:
190
189
  - lib/active_record/connection_handling.rb
191
190
  - lib/active_record/core.rb
192
191
  - lib/active_record/counter_cache.rb
193
- - lib/active_record/define_callbacks.rb
192
+ - lib/active_record/database_configurations.rb
193
+ - lib/active_record/database_configurations/connection_url_resolver.rb
194
+ - lib/active_record/database_configurations/database_config.rb
195
+ - lib/active_record/database_configurations/hash_config.rb
196
+ - lib/active_record/database_configurations/url_config.rb
197
+ - lib/active_record/delegated_type.rb
198
+ - lib/active_record/destroy_association_async_job.rb
199
+ - lib/active_record/disable_joins_association_relation.rb
194
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
195
228
  - lib/active_record/enum.rb
196
229
  - lib/active_record/errors.rb
197
230
  - lib/active_record/explain.rb
198
231
  - lib/active_record/explain_registry.rb
199
232
  - lib/active_record/explain_subscriber.rb
200
233
  - lib/active_record/fixture_set/file.rb
234
+ - lib/active_record/fixture_set/model_metadata.rb
235
+ - lib/active_record/fixture_set/render_context.rb
236
+ - lib/active_record/fixture_set/table_row.rb
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
242
+ - lib/active_record/insert_all.rb
204
243
  - lib/active_record/integration.rb
205
244
  - lib/active_record/internal_metadata.rb
206
245
  - lib/active_record/legacy_yaml_adapter.rb
@@ -208,6 +247,10 @@ files:
208
247
  - lib/active_record/locking/optimistic.rb
209
248
  - lib/active_record/locking/pessimistic.rb
210
249
  - lib/active_record/log_subscriber.rb
250
+ - lib/active_record/middleware/database_selector.rb
251
+ - lib/active_record/middleware/database_selector/resolver.rb
252
+ - lib/active_record/middleware/database_selector/resolver/session.rb
253
+ - lib/active_record/middleware/shard_selector.rb
211
254
  - lib/active_record/migration.rb
212
255
  - lib/active_record/migration/command_recorder.rb
213
256
  - lib/active_record/migration/compatibility.rb
@@ -218,6 +261,7 @@ files:
218
261
  - lib/active_record/null_relation.rb
219
262
  - lib/active_record/persistence.rb
220
263
  - lib/active_record/query_cache.rb
264
+ - lib/active_record/query_logs.rb
221
265
  - lib/active_record/querying.rb
222
266
  - lib/active_record/railtie.rb
223
267
  - lib/active_record/railties/console_sandbox.rb
@@ -236,7 +280,6 @@ files:
236
280
  - lib/active_record/relation/predicate_builder.rb
237
281
  - lib/active_record/relation/predicate_builder/array_handler.rb
238
282
  - lib/active_record/relation/predicate_builder/association_query_value.rb
239
- - lib/active_record/relation/predicate_builder/base_handler.rb
240
283
  - lib/active_record/relation/predicate_builder/basic_object_handler.rb
241
284
  - lib/active_record/relation/predicate_builder/polymorphic_array_value.rb
242
285
  - lib/active_record/relation/predicate_builder/range_handler.rb
@@ -246,7 +289,6 @@ files:
246
289
  - lib/active_record/relation/record_fetch_warning.rb
247
290
  - lib/active_record/relation/spawn_methods.rb
248
291
  - lib/active_record/relation/where_clause.rb
249
- - lib/active_record/relation/where_clause_factory.rb
250
292
  - lib/active_record/result.rb
251
293
  - lib/active_record/runtime_registry.rb
252
294
  - lib/active_record/sanitization.rb
@@ -258,6 +300,7 @@ files:
258
300
  - lib/active_record/scoping/named.rb
259
301
  - lib/active_record/secure_token.rb
260
302
  - lib/active_record/serialization.rb
303
+ - lib/active_record/signed_id.rb
261
304
  - lib/active_record/statement_cache.rb
262
305
  - lib/active_record/store.rb
263
306
  - lib/active_record/suppressor.rb
@@ -266,6 +309,8 @@ files:
266
309
  - lib/active_record/tasks/mysql_database_tasks.rb
267
310
  - lib/active_record/tasks/postgresql_database_tasks.rb
268
311
  - lib/active_record/tasks/sqlite_database_tasks.rb
312
+ - lib/active_record/test_databases.rb
313
+ - lib/active_record/test_fixtures.rb
269
314
  - lib/active_record/timestamp.rb
270
315
  - lib/active_record/touch_later.rb
271
316
  - lib/active_record/transactions.rb
@@ -290,9 +335,87 @@ files:
290
335
  - lib/active_record/validations/absence.rb
291
336
  - lib/active_record/validations/associated.rb
292
337
  - lib/active_record/validations/length.rb
338
+ - lib/active_record/validations/numericality.rb
293
339
  - lib/active_record/validations/presence.rb
294
340
  - lib/active_record/validations/uniqueness.rb
295
341
  - lib/active_record/version.rb
342
+ - lib/arel.rb
343
+ - lib/arel/alias_predication.rb
344
+ - lib/arel/attributes/attribute.rb
345
+ - lib/arel/collectors/bind.rb
346
+ - lib/arel/collectors/composite.rb
347
+ - lib/arel/collectors/plain_string.rb
348
+ - lib/arel/collectors/sql_string.rb
349
+ - lib/arel/collectors/substitute_binds.rb
350
+ - lib/arel/crud.rb
351
+ - lib/arel/delete_manager.rb
352
+ - lib/arel/errors.rb
353
+ - lib/arel/expressions.rb
354
+ - lib/arel/factory_methods.rb
355
+ - lib/arel/filter_predications.rb
356
+ - lib/arel/insert_manager.rb
357
+ - lib/arel/math.rb
358
+ - lib/arel/nodes.rb
359
+ - lib/arel/nodes/and.rb
360
+ - lib/arel/nodes/ascending.rb
361
+ - lib/arel/nodes/binary.rb
362
+ - lib/arel/nodes/bind_param.rb
363
+ - lib/arel/nodes/case.rb
364
+ - lib/arel/nodes/casted.rb
365
+ - lib/arel/nodes/comment.rb
366
+ - lib/arel/nodes/count.rb
367
+ - lib/arel/nodes/delete_statement.rb
368
+ - lib/arel/nodes/descending.rb
369
+ - lib/arel/nodes/equality.rb
370
+ - lib/arel/nodes/extract.rb
371
+ - lib/arel/nodes/false.rb
372
+ - lib/arel/nodes/filter.rb
373
+ - lib/arel/nodes/full_outer_join.rb
374
+ - lib/arel/nodes/function.rb
375
+ - lib/arel/nodes/grouping.rb
376
+ - lib/arel/nodes/homogeneous_in.rb
377
+ - lib/arel/nodes/in.rb
378
+ - lib/arel/nodes/infix_operation.rb
379
+ - lib/arel/nodes/inner_join.rb
380
+ - lib/arel/nodes/insert_statement.rb
381
+ - lib/arel/nodes/join_source.rb
382
+ - lib/arel/nodes/matches.rb
383
+ - lib/arel/nodes/named_function.rb
384
+ - lib/arel/nodes/node.rb
385
+ - lib/arel/nodes/node_expression.rb
386
+ - lib/arel/nodes/ordering.rb
387
+ - lib/arel/nodes/outer_join.rb
388
+ - lib/arel/nodes/over.rb
389
+ - lib/arel/nodes/regexp.rb
390
+ - lib/arel/nodes/right_outer_join.rb
391
+ - lib/arel/nodes/select_core.rb
392
+ - lib/arel/nodes/select_statement.rb
393
+ - lib/arel/nodes/sql_literal.rb
394
+ - lib/arel/nodes/string_join.rb
395
+ - lib/arel/nodes/table_alias.rb
396
+ - lib/arel/nodes/terminal.rb
397
+ - lib/arel/nodes/true.rb
398
+ - lib/arel/nodes/unary.rb
399
+ - lib/arel/nodes/unary_operation.rb
400
+ - lib/arel/nodes/unqualified_column.rb
401
+ - lib/arel/nodes/update_statement.rb
402
+ - lib/arel/nodes/values_list.rb
403
+ - lib/arel/nodes/window.rb
404
+ - lib/arel/nodes/with.rb
405
+ - lib/arel/order_predications.rb
406
+ - lib/arel/predications.rb
407
+ - lib/arel/select_manager.rb
408
+ - lib/arel/table.rb
409
+ - lib/arel/tree_manager.rb
410
+ - lib/arel/update_manager.rb
411
+ - lib/arel/visitors.rb
412
+ - lib/arel/visitors/dot.rb
413
+ - lib/arel/visitors/mysql.rb
414
+ - lib/arel/visitors/postgresql.rb
415
+ - lib/arel/visitors/sqlite.rb
416
+ - lib/arel/visitors/to_sql.rb
417
+ - lib/arel/visitors/visitor.rb
418
+ - lib/arel/window_predications.rb
296
419
  - lib/rails/generators/active_record.rb
297
420
  - lib/rails/generators/active_record/application_record/application_record_generator.rb
298
421
  - lib/rails/generators/active_record/application_record/templates/application_record.rb.tt
@@ -301,14 +424,21 @@ files:
301
424
  - lib/rails/generators/active_record/migration/templates/create_table_migration.rb.tt
302
425
  - lib/rails/generators/active_record/migration/templates/migration.rb.tt
303
426
  - lib/rails/generators/active_record/model/model_generator.rb
427
+ - lib/rails/generators/active_record/model/templates/abstract_base_class.rb.tt
304
428
  - lib/rails/generators/active_record/model/templates/model.rb.tt
305
429
  - lib/rails/generators/active_record/model/templates/module.rb.tt
306
- homepage: http://rubyonrails.org
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
432
+ homepage: https://rubyonrails.org
307
433
  licenses:
308
434
  - MIT
309
435
  metadata:
310
- source_code_uri: https://github.com/rails/rails/tree/v5.2.8/activerecord
311
- changelog_uri: https://github.com/rails/rails/blob/v5.2.8/activerecord/CHANGELOG.md
436
+ bug_tracker_uri: https://github.com/rails/rails/issues
437
+ changelog_uri: https://github.com/rails/rails/blob/v7.0.2/activerecord/CHANGELOG.md
438
+ documentation_uri: https://api.rubyonrails.org/v7.0.2/
439
+ mailing_list_uri: https://discuss.rubyonrails.org/c/rubyonrails-talk
440
+ source_code_uri: https://github.com/rails/rails/tree/v7.0.2/activerecord
441
+ rubygems_mfa_required: 'true'
312
442
  post_install_message:
313
443
  rdoc_options:
314
444
  - "--main"
@@ -319,14 +449,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
319
449
  requirements:
320
450
  - - ">="
321
451
  - !ruby/object:Gem::Version
322
- version: 2.2.2
452
+ version: 2.7.0
323
453
  required_rubygems_version: !ruby/object:Gem::Requirement
324
454
  requirements:
325
455
  - - ">="
326
456
  - !ruby/object:Gem::Version
327
457
  version: '0'
328
458
  requirements: []
329
- rubygems_version: 3.1.6
459
+ rubygems_version: 3.2.32
330
460
  signing_key:
331
461
  specification_version: 4
332
462
  summary: Object-relational mapper framework (part of Rails).
@@ -1,90 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module ActiveRecord
4
- module AttributeDecorators # :nodoc:
5
- extend ActiveSupport::Concern
6
-
7
- included do
8
- class_attribute :attribute_type_decorations, instance_accessor: false, default: TypeDecorator.new # :internal:
9
- end
10
-
11
- module ClassMethods # :nodoc:
12
- # This method is an internal API used to create class macros such as
13
- # +serialize+, and features like time zone aware attributes.
14
- #
15
- # Used to wrap the type of an attribute in a new type.
16
- # When the schema for a model is loaded, attributes with the same name as
17
- # +column_name+ will have their type yielded to the given block. The
18
- # return value of that block will be used instead.
19
- #
20
- # Subsequent calls where +column_name+ and +decorator_name+ are the same
21
- # will override the previous decorator, not decorate twice. This can be
22
- # used to create idempotent class macros like +serialize+
23
- def decorate_attribute_type(column_name, decorator_name, &block)
24
- matcher = ->(name, _) { name == column_name.to_s }
25
- key = "_#{column_name}_#{decorator_name}"
26
- decorate_matching_attribute_types(matcher, key, &block)
27
- end
28
-
29
- # This method is an internal API used to create higher level features like
30
- # time zone aware attributes.
31
- #
32
- # When the schema for a model is loaded, +matcher+ will be called for each
33
- # attribute with its name and type. If the matcher returns a truthy value,
34
- # the type will then be yielded to the given block, and the return value
35
- # of that block will replace the type.
36
- #
37
- # Subsequent calls to this method with the same value for +decorator_name+
38
- # will replace the previous decorator, not decorate twice. This can be
39
- # used to ensure that class macros are idempotent.
40
- def decorate_matching_attribute_types(matcher, decorator_name, &block)
41
- reload_schema_from_cache
42
- decorator_name = decorator_name.to_s
43
-
44
- # Create new hashes so we don't modify parent classes
45
- self.attribute_type_decorations = attribute_type_decorations.merge(decorator_name => [matcher, block])
46
- end
47
-
48
- private
49
-
50
- def load_schema!
51
- super
52
- attribute_types.each do |name, type|
53
- decorated_type = attribute_type_decorations.apply(name, type)
54
- define_attribute(name, decorated_type)
55
- end
56
- end
57
- end
58
-
59
- class TypeDecorator # :nodoc:
60
- delegate :clear, to: :@decorations
61
-
62
- def initialize(decorations = {})
63
- @decorations = decorations
64
- end
65
-
66
- def merge(*args)
67
- TypeDecorator.new(@decorations.merge(*args))
68
- end
69
-
70
- def apply(name, type)
71
- decorations = decorators_for(name, type)
72
- decorations.inject(type) do |new_type, block|
73
- block.call(new_type)
74
- end
75
- end
76
-
77
- private
78
-
79
- def decorators_for(name, type)
80
- matching(name, type).map(&:last)
81
- end
82
-
83
- def matching(name, type)
84
- @decorations.values.select do |(matcher, _)|
85
- matcher.call(name, type)
86
- end
87
- end
88
- end
89
- end
90
- end
@@ -1,53 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module ActiveRecord
4
- module CollectionCacheKey
5
- def collection_cache_key(collection = all, timestamp_column = :updated_at) # :nodoc:
6
- query_signature = ActiveSupport::Digest.hexdigest(collection.to_sql)
7
- key = "#{collection.model_name.cache_key}/query-#{query_signature}"
8
-
9
- if collection.loaded? || collection.distinct_value
10
- size = collection.records.size
11
- if size > 0
12
- timestamp = collection.max_by(&timestamp_column)._read_attribute(timestamp_column)
13
- end
14
- else
15
- if collection.eager_loading?
16
- collection = collection.send(:apply_join_dependency)
17
- end
18
- column_type = type_for_attribute(timestamp_column)
19
- column = connection.column_name_from_arel_node(collection.arel_attribute(timestamp_column))
20
- select_values = "COUNT(*) AS #{connection.quote_column_name("size")}, MAX(%s) AS timestamp"
21
-
22
- if collection.has_limit_or_offset?
23
- query = collection.select("#{column} AS collection_cache_key_timestamp")
24
- subquery_alias = "subquery_for_cache_key"
25
- subquery_column = "#{subquery_alias}.collection_cache_key_timestamp"
26
- subquery = query.arel.as(subquery_alias)
27
- arel = Arel::SelectManager.new(subquery).project(select_values % subquery_column)
28
- else
29
- query = collection.unscope(:order)
30
- query.select_values = [select_values % column]
31
- arel = query.arel
32
- end
33
-
34
- result = connection.select_one(arel, nil)
35
-
36
- if result.blank?
37
- size = 0
38
- timestamp = nil
39
- else
40
- size = result["size"]
41
- timestamp = column_type.deserialize(result["timestamp"])
42
- end
43
-
44
- end
45
-
46
- if timestamp
47
- "#{key}-#{size}-#{timestamp.utc.to_s(cache_timestamp_format)}"
48
- else
49
- "#{key}-#{size}"
50
- end
51
- end
52
- end
53
- end