activerecord 4.2.0 → 6.0.5.1

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 (373) hide show
  1. checksums.yaml +5 -5
  2. data/CHANGELOG.md +852 -801
  3. data/MIT-LICENSE +4 -2
  4. data/README.rdoc +14 -13
  5. data/examples/performance.rb +33 -32
  6. data/examples/simple.rb +5 -4
  7. data/lib/active_record/advisory_lock_base.rb +18 -0
  8. data/lib/active_record/aggregations.rb +267 -249
  9. data/lib/active_record/association_relation.rb +26 -6
  10. data/lib/active_record/associations/alias_tracker.rb +29 -36
  11. data/lib/active_record/associations/association.rb +137 -55
  12. data/lib/active_record/associations/association_scope.rb +110 -132
  13. data/lib/active_record/associations/belongs_to_association.rb +67 -54
  14. data/lib/active_record/associations/belongs_to_polymorphic_association.rb +8 -12
  15. data/lib/active_record/associations/builder/association.rb +27 -40
  16. data/lib/active_record/associations/builder/belongs_to.rb +69 -55
  17. data/lib/active_record/associations/builder/collection_association.rb +10 -29
  18. data/lib/active_record/associations/builder/has_and_belongs_to_many.rb +58 -70
  19. data/lib/active_record/associations/builder/has_many.rb +8 -4
  20. data/lib/active_record/associations/builder/has_one.rb +46 -5
  21. data/lib/active_record/associations/builder/singular_association.rb +16 -10
  22. data/lib/active_record/associations/collection_association.rb +150 -275
  23. data/lib/active_record/associations/collection_proxy.rb +253 -152
  24. data/lib/active_record/associations/foreign_association.rb +20 -0
  25. data/lib/active_record/associations/has_many_association.rb +35 -84
  26. data/lib/active_record/associations/has_many_through_association.rb +62 -80
  27. data/lib/active_record/associations/has_one_association.rb +62 -49
  28. data/lib/active_record/associations/has_one_through_association.rb +20 -11
  29. data/lib/active_record/associations/join_dependency/join_association.rb +43 -78
  30. data/lib/active_record/associations/join_dependency/join_base.rb +10 -9
  31. data/lib/active_record/associations/join_dependency/join_part.rb +14 -14
  32. data/lib/active_record/associations/join_dependency.rb +159 -162
  33. data/lib/active_record/associations/preloader/association.rb +102 -113
  34. data/lib/active_record/associations/preloader/through_association.rb +85 -65
  35. data/lib/active_record/associations/preloader.rb +96 -95
  36. data/lib/active_record/associations/singular_association.rb +18 -45
  37. data/lib/active_record/associations/through_association.rb +49 -24
  38. data/lib/active_record/associations.rb +1737 -1596
  39. data/lib/active_record/attribute_assignment.rb +57 -185
  40. data/lib/active_record/attribute_decorators.rb +39 -17
  41. data/lib/active_record/attribute_methods/before_type_cast.rb +14 -5
  42. data/lib/active_record/attribute_methods/dirty.rb +174 -134
  43. data/lib/active_record/attribute_methods/primary_key.rb +90 -84
  44. data/lib/active_record/attribute_methods/query.rb +6 -5
  45. data/lib/active_record/attribute_methods/read.rb +20 -77
  46. data/lib/active_record/attribute_methods/serialization.rb +40 -21
  47. data/lib/active_record/attribute_methods/time_zone_conversion.rb +61 -37
  48. data/lib/active_record/attribute_methods/write.rb +33 -56
  49. data/lib/active_record/attribute_methods.rb +124 -143
  50. data/lib/active_record/attributes.rb +213 -74
  51. data/lib/active_record/autosave_association.rb +125 -54
  52. data/lib/active_record/base.rb +60 -49
  53. data/lib/active_record/callbacks.rb +101 -76
  54. data/lib/active_record/coders/json.rb +3 -1
  55. data/lib/active_record/coders/yaml_column.rb +36 -13
  56. data/lib/active_record/connection_adapters/abstract/connection_pool.rb +810 -291
  57. data/lib/active_record/connection_adapters/abstract/database_limits.rb +26 -8
  58. data/lib/active_record/connection_adapters/abstract/database_statements.rb +253 -108
  59. data/lib/active_record/connection_adapters/abstract/query_cache.rb +83 -24
  60. data/lib/active_record/connection_adapters/abstract/quoting.rb +171 -53
  61. data/lib/active_record/connection_adapters/abstract/savepoints.rb +6 -4
  62. data/lib/active_record/connection_adapters/abstract/schema_creation.rb +74 -47
  63. data/lib/active_record/connection_adapters/abstract/schema_definitions.rb +383 -239
  64. data/lib/active_record/connection_adapters/abstract/schema_dumper.rb +79 -36
  65. data/lib/active_record/connection_adapters/abstract/schema_statements.rb +736 -235
  66. data/lib/active_record/connection_adapters/abstract/transaction.rb +190 -87
  67. data/lib/active_record/connection_adapters/abstract_adapter.rb +487 -192
  68. data/lib/active_record/connection_adapters/abstract_mysql_adapter.rb +536 -600
  69. data/lib/active_record/connection_adapters/column.rb +56 -43
  70. data/lib/active_record/connection_adapters/connection_specification.rb +174 -153
  71. data/lib/active_record/connection_adapters/determine_if_preparable_visitor.rb +29 -0
  72. data/lib/active_record/connection_adapters/mysql/column.rb +27 -0
  73. data/lib/active_record/connection_adapters/mysql/database_statements.rb +196 -0
  74. data/lib/active_record/connection_adapters/mysql/explain_pretty_printer.rb +71 -0
  75. data/lib/active_record/connection_adapters/mysql/quoting.rb +81 -0
  76. data/lib/active_record/connection_adapters/mysql/schema_creation.rb +71 -0
  77. data/lib/active_record/connection_adapters/mysql/schema_definitions.rb +95 -0
  78. data/lib/active_record/connection_adapters/mysql/schema_dumper.rb +88 -0
  79. data/lib/active_record/connection_adapters/mysql/schema_statements.rb +268 -0
  80. data/lib/active_record/connection_adapters/mysql/type_metadata.rb +31 -0
  81. data/lib/active_record/connection_adapters/mysql2_adapter.rb +59 -196
  82. data/lib/active_record/connection_adapters/postgresql/column.rb +21 -11
  83. data/lib/active_record/connection_adapters/postgresql/database_statements.rb +71 -115
  84. data/lib/active_record/connection_adapters/postgresql/explain_pretty_printer.rb +44 -0
  85. data/lib/active_record/connection_adapters/postgresql/oid/array.rb +49 -57
  86. data/lib/active_record/connection_adapters/postgresql/oid/bit.rb +9 -8
  87. data/lib/active_record/connection_adapters/postgresql/oid/bit_varying.rb +2 -0
  88. data/lib/active_record/connection_adapters/postgresql/oid/bytea.rb +5 -2
  89. data/lib/active_record/connection_adapters/postgresql/oid/cidr.rb +5 -1
  90. data/lib/active_record/connection_adapters/postgresql/oid/date.rb +13 -1
  91. data/lib/active_record/connection_adapters/postgresql/oid/date_time.rb +17 -13
  92. data/lib/active_record/connection_adapters/postgresql/oid/decimal.rb +3 -1
  93. data/lib/active_record/connection_adapters/postgresql/oid/enum.rb +6 -3
  94. data/lib/active_record/connection_adapters/postgresql/oid/hstore.rb +31 -20
  95. data/lib/active_record/connection_adapters/postgresql/oid/inet.rb +2 -0
  96. data/lib/active_record/connection_adapters/postgresql/oid/jsonb.rb +3 -11
  97. data/lib/active_record/connection_adapters/postgresql/oid/legacy_point.rb +44 -0
  98. data/lib/active_record/connection_adapters/postgresql/oid/money.rb +7 -9
  99. data/lib/active_record/connection_adapters/postgresql/oid/{infinity.rb → oid.rb} +5 -3
  100. data/lib/active_record/connection_adapters/postgresql/oid/point.rb +32 -11
  101. data/lib/active_record/connection_adapters/postgresql/oid/range.rb +70 -34
  102. data/lib/active_record/connection_adapters/postgresql/oid/specialized_string.rb +4 -1
  103. data/lib/active_record/connection_adapters/postgresql/oid/type_map_initializer.rb +67 -51
  104. data/lib/active_record/connection_adapters/postgresql/oid/uuid.rb +9 -5
  105. data/lib/active_record/connection_adapters/postgresql/oid/vector.rb +3 -1
  106. data/lib/active_record/connection_adapters/postgresql/oid/xml.rb +3 -1
  107. data/lib/active_record/connection_adapters/postgresql/oid.rb +23 -25
  108. data/lib/active_record/connection_adapters/postgresql/quoting.rb +144 -47
  109. data/lib/active_record/connection_adapters/postgresql/referential_integrity.rb +27 -14
  110. data/lib/active_record/connection_adapters/postgresql/schema_creation.rb +76 -0
  111. data/lib/active_record/connection_adapters/postgresql/schema_definitions.rb +178 -108
  112. data/lib/active_record/connection_adapters/postgresql/schema_dumper.rb +49 -0
  113. data/lib/active_record/connection_adapters/postgresql/schema_statements.rb +465 -291
  114. data/lib/active_record/connection_adapters/postgresql/type_metadata.rb +36 -0
  115. data/lib/active_record/connection_adapters/postgresql/utils.rb +11 -8
  116. data/lib/active_record/connection_adapters/postgresql_adapter.rb +565 -363
  117. data/lib/active_record/connection_adapters/schema_cache.rb +72 -25
  118. data/lib/active_record/connection_adapters/sql_type_metadata.rb +37 -0
  119. data/lib/active_record/connection_adapters/sqlite3/database_statements.rb +119 -0
  120. data/lib/active_record/connection_adapters/sqlite3/explain_pretty_printer.rb +21 -0
  121. data/lib/active_record/connection_adapters/sqlite3/quoting.rb +102 -0
  122. data/lib/active_record/connection_adapters/sqlite3/schema_creation.rb +17 -0
  123. data/lib/active_record/connection_adapters/sqlite3/schema_definitions.rb +19 -0
  124. data/lib/active_record/connection_adapters/sqlite3/schema_dumper.rb +18 -0
  125. data/lib/active_record/connection_adapters/sqlite3/schema_statements.rb +137 -0
  126. data/lib/active_record/connection_adapters/sqlite3_adapter.rb +299 -364
  127. data/lib/active_record/connection_adapters/statement_pool.rb +33 -13
  128. data/lib/active_record/connection_handling.rb +167 -41
  129. data/lib/active_record/core.rb +277 -233
  130. data/lib/active_record/counter_cache.rb +71 -50
  131. data/lib/active_record/database_configurations/database_config.rb +37 -0
  132. data/lib/active_record/database_configurations/hash_config.rb +50 -0
  133. data/lib/active_record/database_configurations/url_config.rb +78 -0
  134. data/lib/active_record/database_configurations.rb +233 -0
  135. data/lib/active_record/define_callbacks.rb +22 -0
  136. data/lib/active_record/dynamic_matchers.rb +87 -106
  137. data/lib/active_record/enum.rb +172 -89
  138. data/lib/active_record/errors.rb +189 -53
  139. data/lib/active_record/explain.rb +22 -11
  140. data/lib/active_record/explain_registry.rb +4 -2
  141. data/lib/active_record/explain_subscriber.rb +11 -6
  142. data/lib/active_record/fixture_set/file.rb +35 -9
  143. data/lib/active_record/fixture_set/model_metadata.rb +33 -0
  144. data/lib/active_record/fixture_set/render_context.rb +17 -0
  145. data/lib/active_record/fixture_set/table_row.rb +152 -0
  146. data/lib/active_record/fixture_set/table_rows.rb +46 -0
  147. data/lib/active_record/fixtures.rb +225 -497
  148. data/lib/active_record/gem_version.rb +6 -4
  149. data/lib/active_record/inheritance.rb +158 -115
  150. data/lib/active_record/insert_all.rb +179 -0
  151. data/lib/active_record/integration.rb +123 -29
  152. data/lib/active_record/internal_metadata.rb +53 -0
  153. data/lib/active_record/legacy_yaml_adapter.rb +48 -0
  154. data/lib/active_record/locale/en.yml +3 -2
  155. data/lib/active_record/locking/optimistic.rb +99 -98
  156. data/lib/active_record/locking/pessimistic.rb +18 -6
  157. data/lib/active_record/log_subscriber.rb +76 -33
  158. data/lib/active_record/middleware/database_selector/resolver/session.rb +45 -0
  159. data/lib/active_record/middleware/database_selector/resolver.rb +87 -0
  160. data/lib/active_record/middleware/database_selector.rb +74 -0
  161. data/lib/active_record/migration/command_recorder.rb +166 -91
  162. data/lib/active_record/migration/compatibility.rb +244 -0
  163. data/lib/active_record/migration/join_table.rb +8 -7
  164. data/lib/active_record/migration.rb +636 -290
  165. data/lib/active_record/model_schema.rb +344 -112
  166. data/lib/active_record/nested_attributes.rb +265 -215
  167. data/lib/active_record/no_touching.rb +15 -2
  168. data/lib/active_record/null_relation.rb +24 -38
  169. data/lib/active_record/persistence.rb +559 -125
  170. data/lib/active_record/query_cache.rb +19 -23
  171. data/lib/active_record/querying.rb +44 -30
  172. data/lib/active_record/railtie.rb +166 -47
  173. data/lib/active_record/railties/collection_cache_association_loading.rb +34 -0
  174. data/lib/active_record/railties/console_sandbox.rb +2 -0
  175. data/lib/active_record/railties/controller_runtime.rb +34 -33
  176. data/lib/active_record/railties/databases.rake +341 -202
  177. data/lib/active_record/readonly_attributes.rb +5 -4
  178. data/lib/active_record/reflection.rb +461 -302
  179. data/lib/active_record/relation/batches/batch_enumerator.rb +69 -0
  180. data/lib/active_record/relation/batches.rb +206 -55
  181. data/lib/active_record/relation/calculations.rb +270 -249
  182. data/lib/active_record/relation/delegation.rb +76 -84
  183. data/lib/active_record/relation/finder_methods.rb +287 -255
  184. data/lib/active_record/relation/from_clause.rb +30 -0
  185. data/lib/active_record/relation/merger.rb +86 -68
  186. data/lib/active_record/relation/predicate_builder/array_handler.rb +27 -25
  187. data/lib/active_record/relation/predicate_builder/association_query_value.rb +43 -0
  188. data/lib/active_record/relation/predicate_builder/base_handler.rb +18 -0
  189. data/lib/active_record/relation/predicate_builder/basic_object_handler.rb +19 -0
  190. data/lib/active_record/relation/predicate_builder/polymorphic_array_value.rb +53 -0
  191. data/lib/active_record/relation/predicate_builder/range_handler.rb +22 -0
  192. data/lib/active_record/relation/predicate_builder/relation_handler.rb +7 -1
  193. data/lib/active_record/relation/predicate_builder.rb +112 -92
  194. data/lib/active_record/relation/query_attribute.rb +50 -0
  195. data/lib/active_record/relation/query_methods.rb +612 -392
  196. data/lib/active_record/relation/record_fetch_warning.rb +51 -0
  197. data/lib/active_record/relation/spawn_methods.rb +18 -17
  198. data/lib/active_record/relation/where_clause.rb +189 -0
  199. data/lib/active_record/relation/where_clause_factory.rb +33 -0
  200. data/lib/active_record/relation.rb +533 -340
  201. data/lib/active_record/result.rb +79 -43
  202. data/lib/active_record/runtime_registry.rb +6 -4
  203. data/lib/active_record/sanitization.rb +144 -121
  204. data/lib/active_record/schema.rb +21 -24
  205. data/lib/active_record/schema_dumper.rb +112 -93
  206. data/lib/active_record/schema_migration.rb +24 -20
  207. data/lib/active_record/scoping/default.rb +98 -82
  208. data/lib/active_record/scoping/named.rb +91 -33
  209. data/lib/active_record/scoping.rb +45 -27
  210. data/lib/active_record/secure_token.rb +40 -0
  211. data/lib/active_record/serialization.rb +5 -5
  212. data/lib/active_record/statement_cache.rb +73 -36
  213. data/lib/active_record/store.rb +127 -42
  214. data/lib/active_record/suppressor.rb +61 -0
  215. data/lib/active_record/table_metadata.rb +90 -0
  216. data/lib/active_record/tasks/database_tasks.rb +309 -99
  217. data/lib/active_record/tasks/mysql_database_tasks.rb +58 -89
  218. data/lib/active_record/tasks/postgresql_database_tasks.rb +81 -31
  219. data/lib/active_record/tasks/sqlite_database_tasks.rb +37 -16
  220. data/lib/active_record/test_databases.rb +23 -0
  221. data/lib/active_record/test_fixtures.rb +243 -0
  222. data/lib/active_record/timestamp.rb +86 -41
  223. data/lib/active_record/touch_later.rb +65 -0
  224. data/lib/active_record/transactions.rb +222 -146
  225. data/lib/active_record/translation.rb +3 -1
  226. data/lib/active_record/type/adapter_specific_registry.rb +126 -0
  227. data/lib/active_record/type/date.rb +4 -41
  228. data/lib/active_record/type/date_time.rb +4 -38
  229. data/lib/active_record/type/decimal_without_scale.rb +6 -2
  230. data/lib/active_record/type/hash_lookup_type_map.rb +12 -5
  231. data/lib/active_record/type/internal/timezone.rb +17 -0
  232. data/lib/active_record/type/json.rb +30 -0
  233. data/lib/active_record/type/serialized.rb +29 -15
  234. data/lib/active_record/type/text.rb +2 -2
  235. data/lib/active_record/type/time.rb +21 -16
  236. data/lib/active_record/type/type_map.rb +16 -19
  237. data/lib/active_record/type/unsigned_integer.rb +9 -8
  238. data/lib/active_record/type.rb +77 -23
  239. data/lib/active_record/type_caster/connection.rb +34 -0
  240. data/lib/active_record/type_caster/map.rb +20 -0
  241. data/lib/active_record/type_caster.rb +9 -0
  242. data/lib/active_record/validations/absence.rb +25 -0
  243. data/lib/active_record/validations/associated.rb +12 -4
  244. data/lib/active_record/validations/length.rb +26 -0
  245. data/lib/active_record/validations/presence.rb +14 -13
  246. data/lib/active_record/validations/uniqueness.rb +43 -46
  247. data/lib/active_record/validations.rb +38 -35
  248. data/lib/active_record/version.rb +3 -1
  249. data/lib/active_record.rb +44 -21
  250. data/lib/arel/alias_predication.rb +9 -0
  251. data/lib/arel/attributes/attribute.rb +37 -0
  252. data/lib/arel/attributes.rb +22 -0
  253. data/lib/arel/collectors/bind.rb +24 -0
  254. data/lib/arel/collectors/composite.rb +31 -0
  255. data/lib/arel/collectors/plain_string.rb +20 -0
  256. data/lib/arel/collectors/sql_string.rb +20 -0
  257. data/lib/arel/collectors/substitute_binds.rb +28 -0
  258. data/lib/arel/crud.rb +42 -0
  259. data/lib/arel/delete_manager.rb +18 -0
  260. data/lib/arel/errors.rb +9 -0
  261. data/lib/arel/expressions.rb +29 -0
  262. data/lib/arel/factory_methods.rb +49 -0
  263. data/lib/arel/insert_manager.rb +49 -0
  264. data/lib/arel/math.rb +45 -0
  265. data/lib/arel/nodes/and.rb +32 -0
  266. data/lib/arel/nodes/ascending.rb +23 -0
  267. data/lib/arel/nodes/binary.rb +52 -0
  268. data/lib/arel/nodes/bind_param.rb +36 -0
  269. data/lib/arel/nodes/case.rb +55 -0
  270. data/lib/arel/nodes/casted.rb +50 -0
  271. data/lib/arel/nodes/comment.rb +29 -0
  272. data/lib/arel/nodes/count.rb +12 -0
  273. data/lib/arel/nodes/delete_statement.rb +45 -0
  274. data/lib/arel/nodes/descending.rb +23 -0
  275. data/lib/arel/nodes/equality.rb +18 -0
  276. data/lib/arel/nodes/extract.rb +24 -0
  277. data/lib/arel/nodes/false.rb +16 -0
  278. data/lib/arel/nodes/full_outer_join.rb +8 -0
  279. data/lib/arel/nodes/function.rb +44 -0
  280. data/lib/arel/nodes/grouping.rb +8 -0
  281. data/lib/arel/nodes/in.rb +8 -0
  282. data/lib/arel/nodes/infix_operation.rb +80 -0
  283. data/lib/arel/nodes/inner_join.rb +8 -0
  284. data/lib/arel/nodes/insert_statement.rb +37 -0
  285. data/lib/arel/nodes/join_source.rb +20 -0
  286. data/lib/arel/nodes/matches.rb +18 -0
  287. data/lib/arel/nodes/named_function.rb +23 -0
  288. data/lib/arel/nodes/node.rb +50 -0
  289. data/lib/arel/nodes/node_expression.rb +13 -0
  290. data/lib/arel/nodes/outer_join.rb +8 -0
  291. data/lib/arel/nodes/over.rb +15 -0
  292. data/lib/arel/nodes/regexp.rb +16 -0
  293. data/lib/arel/nodes/right_outer_join.rb +8 -0
  294. data/lib/arel/nodes/select_core.rb +67 -0
  295. data/lib/arel/nodes/select_statement.rb +41 -0
  296. data/lib/arel/nodes/sql_literal.rb +16 -0
  297. data/lib/arel/nodes/string_join.rb +11 -0
  298. data/lib/arel/nodes/table_alias.rb +27 -0
  299. data/lib/arel/nodes/terminal.rb +16 -0
  300. data/lib/arel/nodes/true.rb +16 -0
  301. data/lib/arel/nodes/unary.rb +45 -0
  302. data/lib/arel/nodes/unary_operation.rb +20 -0
  303. data/lib/arel/nodes/unqualified_column.rb +22 -0
  304. data/lib/arel/nodes/update_statement.rb +41 -0
  305. data/lib/arel/nodes/values_list.rb +9 -0
  306. data/lib/arel/nodes/window.rb +126 -0
  307. data/lib/arel/nodes/with.rb +11 -0
  308. data/lib/arel/nodes.rb +68 -0
  309. data/lib/arel/order_predications.rb +13 -0
  310. data/lib/arel/predications.rb +256 -0
  311. data/lib/arel/select_manager.rb +271 -0
  312. data/lib/arel/table.rb +110 -0
  313. data/lib/arel/tree_manager.rb +72 -0
  314. data/lib/arel/update_manager.rb +34 -0
  315. data/lib/arel/visitors/depth_first.rb +203 -0
  316. data/lib/arel/visitors/dot.rb +296 -0
  317. data/lib/arel/visitors/ibm_db.rb +34 -0
  318. data/lib/arel/visitors/informix.rb +62 -0
  319. data/lib/arel/visitors/mssql.rb +156 -0
  320. data/lib/arel/visitors/mysql.rb +83 -0
  321. data/lib/arel/visitors/oracle.rb +158 -0
  322. data/lib/arel/visitors/oracle12.rb +65 -0
  323. data/lib/arel/visitors/postgresql.rb +109 -0
  324. data/lib/arel/visitors/sqlite.rb +38 -0
  325. data/lib/arel/visitors/to_sql.rb +888 -0
  326. data/lib/arel/visitors/visitor.rb +45 -0
  327. data/lib/arel/visitors/where_sql.rb +22 -0
  328. data/lib/arel/visitors.rb +20 -0
  329. data/lib/arel/window_predications.rb +9 -0
  330. data/lib/arel.rb +62 -0
  331. data/lib/rails/generators/active_record/application_record/application_record_generator.rb +26 -0
  332. data/lib/rails/generators/active_record/application_record/templates/application_record.rb.tt +5 -0
  333. data/lib/rails/generators/active_record/migration/migration_generator.rb +42 -37
  334. data/lib/rails/generators/active_record/migration/templates/create_table_migration.rb.tt +24 -0
  335. data/lib/rails/generators/active_record/migration/templates/{migration.rb → migration.rb.tt} +11 -8
  336. data/lib/rails/generators/active_record/migration.rb +30 -1
  337. data/lib/rails/generators/active_record/model/model_generator.rb +18 -22
  338. data/lib/rails/generators/active_record/model/templates/model.rb.tt +22 -0
  339. data/lib/rails/generators/active_record.rb +7 -5
  340. metadata +174 -63
  341. data/lib/active_record/associations/preloader/belongs_to.rb +0 -17
  342. data/lib/active_record/associations/preloader/collection_association.rb +0 -24
  343. data/lib/active_record/associations/preloader/has_many.rb +0 -17
  344. data/lib/active_record/associations/preloader/has_many_through.rb +0 -19
  345. data/lib/active_record/associations/preloader/has_one.rb +0 -23
  346. data/lib/active_record/associations/preloader/has_one_through.rb +0 -9
  347. data/lib/active_record/associations/preloader/singular_association.rb +0 -21
  348. data/lib/active_record/attribute.rb +0 -149
  349. data/lib/active_record/attribute_set/builder.rb +0 -86
  350. data/lib/active_record/attribute_set.rb +0 -77
  351. data/lib/active_record/connection_adapters/mysql_adapter.rb +0 -491
  352. data/lib/active_record/connection_adapters/postgresql/array_parser.rb +0 -93
  353. data/lib/active_record/connection_adapters/postgresql/oid/float.rb +0 -21
  354. data/lib/active_record/connection_adapters/postgresql/oid/integer.rb +0 -11
  355. data/lib/active_record/connection_adapters/postgresql/oid/json.rb +0 -35
  356. data/lib/active_record/connection_adapters/postgresql/oid/time.rb +0 -11
  357. data/lib/active_record/railties/jdbcmysql_error.rb +0 -16
  358. data/lib/active_record/serializers/xml_serializer.rb +0 -193
  359. data/lib/active_record/type/big_integer.rb +0 -13
  360. data/lib/active_record/type/binary.rb +0 -50
  361. data/lib/active_record/type/boolean.rb +0 -30
  362. data/lib/active_record/type/decimal.rb +0 -40
  363. data/lib/active_record/type/decorator.rb +0 -14
  364. data/lib/active_record/type/float.rb +0 -19
  365. data/lib/active_record/type/integer.rb +0 -55
  366. data/lib/active_record/type/mutable.rb +0 -16
  367. data/lib/active_record/type/numeric.rb +0 -36
  368. data/lib/active_record/type/string.rb +0 -36
  369. data/lib/active_record/type/time_value.rb +0 -38
  370. data/lib/active_record/type/value.rb +0 -101
  371. data/lib/rails/generators/active_record/migration/templates/create_table_migration.rb +0 -22
  372. data/lib/rails/generators/active_record/model/templates/model.rb +0 -10
  373. /data/lib/rails/generators/active_record/model/templates/{module.rb → module.rb.tt} +0 -0
data/CHANGELOG.md CHANGED
@@ -1,1372 +1,1423 @@
1
- * Introduce `force: :cascade` option for `create_table`. Using this option
2
- will recreate tables even if they have dependent objects (like foreign keys).
3
- `db/schema.rb` now uses `force: :cascade`. This makes it possible to
4
- reload the schema when foreign keys are in place.
1
+ ## Rails 6.0.5.1 (July 12, 2022) ##
5
2
 
6
- *Matthew Draper*, *Yves Senn*
3
+ * Change ActiveRecord::Coders::YAMLColumn default to safe_load
7
4
 
8
- * `db:schema:load` and `db:structure:load` no longer purge the database
9
- before loading the schema. This is left for the user to do.
10
- `db:test:prepare` will still purge the database.
5
+ This adds two new configuration options The configuration options are as
6
+ follows:
7
+
8
+ * `config.active_storage.use_yaml_unsafe_load`
9
+
10
+ When set to true, this configuration option tells Rails to use the old
11
+ "unsafe" YAML loading strategy, maintaining the existing behavior but leaving
12
+ the possible escalation vulnerability in place. Setting this option to true
13
+ is *not* recommended, but can aid in upgrading.
14
+
15
+ * `config.active_record.yaml_column_permitted_classes`
16
+
17
+ The "safe YAML" loading method does not allow all classes to be deserialized
18
+ by default. This option allows you to specify classes deemed "safe" in your
19
+ application. For example, if your application uses Symbol and Time in
20
+ serialized data, you can add Symbol and Time to the allowed list as follows:
21
+
22
+ ```
23
+ config.active_record.yaml_column_permitted_classes = [Symbol, Date, Time]
24
+ ```
11
25
 
12
- Closes #17945.
26
+ [CVE-2022-32224]
13
27
 
14
- *Yves Senn*
15
28
 
16
- * Fix undesirable RangeError by Type::Integer. Add Type::UnsignedInteger.
29
+ ## Rails 6.0.5 (May 09, 2022) ##
17
30
 
18
- *Ryuta Kamizono*
31
+ * No changes.
19
32
 
20
- * Add `foreign_type` option to `has_one` and `has_many` association macros.
21
33
 
22
- This option enables to define the column name of associated object's type for polymorphic associations.
34
+ ## Rails 6.0.4.8 (April 26, 2022) ##
23
35
 
24
- *Ulisses Almeida, Kassio Borges*
36
+ * No changes.
25
37
 
26
- * `add_timestamps` and `remove_timestamps` now properly reversible with
27
- options.
28
38
 
29
- *Noam Gagliardi-Rabinovich*
39
+ ## Rails 6.0.4.7 (March 08, 2022) ##
30
40
 
31
- * Bring back `db:test:prepare` to synchronize the test database schema.
41
+ * No changes.
32
42
 
33
- Manual synchronization using `bin/rake db:test:prepare` is required
34
- when a migration is rolled-back, edited and reapplied.
35
43
 
36
- `ActiveRecord::Base.maintain_test_schema` now uses `db:test:prepare`
37
- to synchronize the schema. Plugins can use this task as a hook to
38
- provide custom behavior after the schema has been loaded.
44
+ ## Rails 6.0.4.6 (February 11, 2022) ##
39
45
 
40
- NOTE: `test:prepare` runs before the schema is synchronized.
46
+ * No changes.
41
47
 
42
- Fixes #17171, #15787.
43
48
 
44
- *Yves Senn*
49
+ ## Rails 6.0.4.5 (February 11, 2022) ##
45
50
 
46
- * Change `reflections` public api to return the keys as String objects.
51
+ * No changes.
47
52
 
48
- Fixes #16928.
49
53
 
50
- *arthurnn*
54
+ ## Rails 6.0.4.4 (December 15, 2021) ##
51
55
 
52
- * Renaming a table in pg also renames the primary key index.
56
+ * No changes.
53
57
 
54
- Fixes #12856
55
58
 
56
- *Sean Griffin*
59
+ ## Rails 6.0.4.3 (December 14, 2021) ##
57
60
 
58
- * Make it possible to access fixtures excluded by a `default_scope`.
61
+ * No changes.
59
62
 
60
- *Yves Senn*
61
63
 
62
- * Fix preloading of associations with a scope containing joins along with
63
- conditions on the joined association.
64
+ ## Rails 6.0.4.2 (December 14, 2021) ##
64
65
 
65
- *Siddharth Sharma*
66
+ * No changes.
66
67
 
67
- * Add `Table#name` to match `TableDefinition#name`.
68
68
 
69
- *Cody Cutrer*
69
+ ## Rails 6.0.4.1 (August 19, 2021) ##
70
70
 
71
- * Cache `CollectionAssociation#reader` proxies separately before and after
72
- the owner has been saved so that the proxy is not cached without the
73
- owner's id.
71
+ * No changes.
74
72
 
75
- *Ben Woosley*
76
73
 
77
- * `ActiveRecord::ReadOnlyRecord` now has a descriptive message.
74
+ ## Rails 6.0.4 (June 15, 2021) ##
78
75
 
79
- *Franky W.*
76
+ * Only warn about negative enums if a positive form that would cause conflicts exists.
80
77
 
81
- * Fix preloading of associations which unscope a default scope.
78
+ Fixes #39065.
82
79
 
83
- Fixes #11036.
80
+ *Alex Ghiculescu*
84
81
 
85
- *Byron Bischoff*
82
+ * Allow the inverse of a `has_one` association that was previously autosaved to be loaded.
86
83
 
87
- * Added SchemaDumper support for tables with jsonb columns.
84
+ Fixes #34255.
88
85
 
89
- *Ted O'Meara*
86
+ *Steven Weber*
90
87
 
91
- * Deprecate `sanitize_sql_hash_for_conditions` without replacement. Using a
92
- `Relation` for performing queries and updates is the prefered API.
88
+ * Reset statement cache for association if `table_name` is changed.
93
89
 
94
- *Sean Griffin*
90
+ Fixes #36453.
95
91
 
96
- * Queries now properly type cast values that are part of a join statement,
97
- even when using type decorators such as `serialize`.
92
+ *Ryuta Kamizono*
98
93
 
99
- *Melanie Gilman & Sean Griffin*
94
+ * Type cast extra select for eager loading.
100
95
 
101
- * MySQL enum type lookups, with values matching another type, no longer result
102
- in an endless loop.
96
+ *Ryuta Kamizono*
103
97
 
104
- Fixes #17402.
98
+ * Prevent collection associations from being autosaved multiple times.
105
99
 
106
- *Yves Senn*
100
+ Fixes #39173.
107
101
 
108
- * Raise `ArgumentError` when the body of a scope is not callable.
102
+ *Eugene Kenny*
109
103
 
110
- *Mauro George*
104
+ * Resolve issue with insert_all unique_by option when used with expression index.
111
105
 
112
- * Use type column first in multi-column indexes created with `add-reference`.
106
+ When the `:unique_by` option of `ActiveRecord::Persistence.insert_all` and
107
+ `ActiveRecord::Persistence.upsert_all` was used with the name of an expression index, an error
108
+ was raised. Adding a guard around the formatting behavior for the `:unique_by` corrects this.
113
109
 
114
- *Derek Prior*
110
+ Usage:
115
111
 
116
- * Fix `Relation.rewhere` to work with Range values.
112
+ ```ruby
113
+ create_table :books, id: :integer, force: true do |t|
114
+ t.column :name, :string
115
+ t.index "lower(name)", unique: true
116
+ end
117
117
 
118
- *Dan Olson*
118
+ Book.insert_all [{ name: "MyTest" }], unique_by: :index_books_on_lower_name
119
+ ```
119
120
 
120
- * `AR::UnknownAttributeError` now includes the class name of a record.
121
+ Fixes #39516.
121
122
 
122
- User.new(name: "Yuki Nishijima", project_attributes: {name: "kaminari"})
123
- # => ActiveRecord::UnknownAttributeError: unknown attribute 'name' for User.
123
+ *Austen Madden*
124
124
 
125
- *Yuki Nishijima*
125
+ * Fix preloading for polymorphic association with custom scope.
126
126
 
127
- * Fix a regression causing `after_create` callbacks to run before associated
128
- records are autosaved.
127
+ *Ryuta Kamizono*
129
128
 
130
- Fixes #17209.
129
+ * Allow relations with different SQL comments in the `or` method.
131
130
 
132
- *Agis Anastasopoulos*
131
+ *Takumi Shotoku*
133
132
 
134
- * Honor overridden `rack.test` in Rack environment for the connection
135
- management middleware.
133
+ * Resolve conflict between counter cache and optimistic locking.
136
134
 
137
- *Simon Eskildsen*
135
+ Bump an Active Record instance's lock version after updating its counter
136
+ cache. This avoids raising an unnecessary `ActiveRecord::StaleObjectError`
137
+ upon subsequent transactions by maintaining parity with the corresponding
138
+ database record's `lock_version` column.
138
139
 
139
- * Add a truncate method to the connection.
140
+ Fixes #16449.
140
141
 
141
- *Aaron Patterson*
142
+ *Aaron Lipman*
142
143
 
143
- * Don't autosave unchanged has_one through records.
144
+ * Fix through association with source/through scope which has joins.
144
145
 
145
- *Alan Kennedy*, *Steve Parrington*
146
+ *Ryuta Kamizono*
146
147
 
147
- * Do not dump foreign keys for ignored tables.
148
+ * Fix through association to respect source scope for includes/preload.
148
149
 
149
- *Yves Senn*
150
+ *Ryuta Kamizono*
150
151
 
151
- * PostgreSQL adapter correctly dumps foreign keys targeting tables
152
- outside the schema search path.
152
+ * Fix eager load with Arel joins to maintain the original joins order.
153
153
 
154
- Fixes #16907.
154
+ *Ryuta Kamizono*
155
155
 
156
- *Matthew Draper*, *Yves Senn*
156
+ * Fix group by count with eager loading + order + limit/offset.
157
157
 
158
- * When a thread is killed, rollback the active transaction, instead of
159
- committing it during the stack unwind. Previously, we could commit half-
160
- completed work. This fix only works for Ruby 2.0+; on 1.9, we can't
161
- distinguish a thread kill from an ordinary non-local (block) return, so must
162
- default to committing.
158
+ *Ryuta Kamizono*
163
159
 
164
- *Chris Hanks*
160
+ * Fix left joins order when merging multiple left joins from different associations.
165
161
 
166
- * A `NullRelation` should represent nothing. This fixes a bug where
167
- `Comment.where(post_id: Post.none)` returned a non-empty result.
162
+ *Ryuta Kamizono*
168
163
 
169
- Fixes #15176.
164
+ * Fix index creation to preserve index comment in bulk change table on MySQL.
170
165
 
171
- *Matthew Draper*, *Yves Senn*
166
+ *Ryuta Kamizono*
172
167
 
173
- * Include default column limits in schema.rb. Allows defaults to be changed
174
- in the future without affecting old migrations that assumed old defaults.
168
+ * Change `remove_foreign_key` to not check `:validate` option if database
169
+ doesn't support the feature.
175
170
 
176
- *Jeremy Kemper*
171
+ *Ryuta Kamizono*
177
172
 
178
- * MySQL: schema.rb now includes TEXT and BLOB column limits.
173
+ * Fix the result of aggregations to maintain duplicated "group by" fields.
179
174
 
180
- *Jeremy Kemper*
175
+ *Ryuta Kamizono*
181
176
 
182
- * MySQL: correct LONGTEXT and LONGBLOB limits from 2GB to their true 4GB.
177
+ * Do not return duplicated records when using preload.
183
178
 
184
- *Jeremy Kemper*
179
+ *Bogdan Gusiev*
185
180
 
186
- * SQLite3Adapter now checks for views in `table_exists?`. Fixes #14041.
187
181
 
188
- *Girish Sonawane*
182
+ ## Rails 6.0.3.7 (May 05, 2021) ##
189
183
 
190
- * Introduce `connection.supports_views?` to check whether the current adapter
191
- has support for SQL views. Connection adapters should define this method.
184
+ * No changes.
192
185
 
193
- *Yves Senn*
194
186
 
195
- * Allow included modules to override association methods.
187
+ ## Rails 6.0.3.6 (March 26, 2021) ##
196
188
 
197
- Fixes #16684.
189
+ * No changes.
198
190
 
199
- *Yves Senn*
200
191
 
201
- * Schema loading rake tasks (like `db:schema:load` and `db:setup`) maintain
202
- the database connection to the current environment.
192
+ ## Rails 6.0.3.5 (February 10, 2021) ##
203
193
 
204
- Fixes #16757.
194
+ * Fix possible DoS vector in PostgreSQL money type
205
195
 
206
- *Joshua Cody*, *Yves Senn*
196
+ Carefully crafted input can cause a DoS via the regular expressions used
197
+ for validating the money format in the PostgreSQL adapter. This patch
198
+ fixes the regexp.
207
199
 
208
- * MySQL: set the connection collation along with the charset.
200
+ Thanks to @dee-see from Hackerone for this patch!
209
201
 
210
- Sets the connection collation to the database collation configured in
211
- database.yml. Otherwise, `SET NAMES utf8mb4` will use the default
212
- collation for that charset (utf8mb4_general_ci) when you may have chosen
213
- a different collation, like utf8mb4_unicode_ci.
202
+ [CVE-2021-22880]
214
203
 
215
- This only applies to literal string comparisons, not column values, so it
216
- is unlikely to affect you.
204
+ *Aaron Patterson*
217
205
 
218
- *Jeremy Kemper*
219
206
 
220
- * `default_sequence_name` from the PostgreSQL adapter returns a `String`.
207
+ ## Rails 6.0.3.4 (October 07, 2020) ##
221
208
 
222
- *Yves Senn*
209
+ * No changes.
223
210
 
224
- * Fix a regression where whitespaces were stripped from DISTINCT queries in
225
- PostgreSQL.
226
211
 
227
- *Agis Anastasopoulos*
212
+ ## Rails 6.0.3.3 (September 09, 2020) ##
228
213
 
229
- Fixes #16623.
214
+ * No changes.
230
215
 
231
- * Fix has_many :through relation merging failing when dynamic conditions are
232
- passed as a lambda with an arity of one.
233
216
 
234
- Fixes #16128.
217
+ ## Rails 6.0.3.2 (June 17, 2020) ##
235
218
 
236
- *Agis Anastasopoulos*
219
+ * No changes.
237
220
 
238
- * Fix `Relation#exists?` to work with polymorphic associations.
239
221
 
240
- Fixes #15821.
222
+ ## Rails 6.0.3.1 (May 18, 2020) ##
241
223
 
242
- *Kassio Borges*
224
+ * No changes.
243
225
 
244
- * Currently, Active Record rescues any errors raised within
245
- `after_rollback`/`after_create` callbacks and prints them to the logs.
246
- Future versions of Rails will not rescue these errors anymore and
247
- just bubble them up like the other callbacks.
248
226
 
249
- This commit adds an opt-in flag to enable not rescuing the errors.
227
+ ## Rails 6.0.3 (May 06, 2020) ##
250
228
 
251
- Example:
229
+ * Recommend applications don't use the `database` kwarg in `connected_to`
252
230
 
253
- # Do not swallow errors in after_commit/after_rollback callbacks.
254
- config.active_record.raise_in_transactional_callbacks = true
231
+ The database kwarg in `connected_to` was meant to be used for one-off scripts but is often used in requests. This is really dangerous because it re-establishes a connection every time. It's deprecated in 6.1 and will be removed in 6.2 without replacement. This change soft deprecates it in 6.0 by removing documentation.
255
232
 
256
- Fixes #13460.
233
+ *Eileen M. Uchitelle*
257
234
 
258
- *arthurnn*
235
+ * Fix support for PostgreSQL 11+ partitioned indexes.
259
236
 
260
- * Fix an issue where custom accessor methods (such as those generated by
261
- `enum`) with the same name as a global method are incorrectly overridden
262
- when subclassing.
237
+ *Sebastián Palma*
263
238
 
264
- Fixes #16288.
239
+ * Add support for beginless ranges, introduced in Ruby 2.7.
265
240
 
266
- *Godfrey Chan*
241
+ *Josh Goodall*
267
242
 
268
- * `*_was` and `changes` now work correctly for in-place attribute changes as
269
- well.
243
+ * Fix insert_all with enum values
270
244
 
271
- *Sean Griffin*
245
+ Fixes #38716.
272
246
 
273
- * Fix regression on `after_commit` that did not fire with nested transactions.
247
+ *Joel Blum*
274
248
 
275
- Fixes #16425.
249
+ * Regexp-escape table name for MS SQL
276
250
 
277
- *arthurnn*
251
+ Add `Regexp.escape` to one method in ActiveRecord, so that table names with regular expression characters in them work as expected. Since MS SQL Server uses "[" and "]" to quote table and column names, and those characters are regular expression characters, methods like `pluck` and `select` fail in certain cases when used with the MS SQL Server adapter.
278
252
 
279
- * Do not try to write timestamps when a table has no timestamps columns.
253
+ *Larry Reid*
280
254
 
281
- Fixes #8813.
255
+ * Store advisory locks on their own named connection.
282
256
 
283
- *Sergey Potapov*
257
+ Previously advisory locks were taken out against a connection when a migration started. This works fine in single database applications but doesn't work well when migrations need to open new connections which results in the lock getting dropped.
284
258
 
285
- * `index_exists?` with `:name` option does verify specified columns.
259
+ In order to fix this we are storing the advisory lock on a new connection with the connection specification name `AdisoryLockBase`. The caveat is that we need to maintain at least 2 connections to a database while migrations are running in order to do this.
286
260
 
287
- Example:
261
+ *Eileen M. Uchitelle*, *John Crepezzi*
288
262
 
289
- add_index :articles, :title, name: "idx_title"
263
+ * Ensure `:reading` connections always raise if a write is attempted.
290
264
 
291
- # Before:
292
- index_exists? :articles, :title, name: "idx_title" # => `true`
293
- index_exists? :articles, :body, name: "idx_title" # => `true`
265
+ Now Rails will raise an `ActiveRecord::ReadOnlyError` if any connection on the reading handler attempts to make a write. If your reading role needs to write you should name the role something other than `:reading`.
294
266
 
295
- # After:
296
- index_exists? :articles, :title, name: "idx_title" # => `true`
297
- index_exists? :articles, :body, name: "idx_title" # => `false`
267
+ *Eileen M. Uchitelle*
298
268
 
299
- *Yves Senn*, *Matthew Draper*
269
+ * Enforce fresh ETag header after a collection's contents change by adding
270
+ ActiveRecord::Relation#cache_key_with_version. This method will be used by
271
+ ActionController::ConditionalGet to ensure that when collection cache versioning
272
+ is enabled, requests using ConditionalGet don't return the same ETag header
273
+ after a collection is modified. Fixes #38078.
300
274
 
301
- * `add_timestamps` and `t.timestamps` now require you to pass the `:null` option.
302
- Not passing the option is deprecated but the default is still `null: true`.
303
- With Rails 5 this will change to `null: false`.
275
+ *Aaron Lipman*
304
276
 
305
- *Sean Griffin*
277
+ * A database URL can now contain a querystring value that contains an equal sign. This is needed to support passing PostgresSQL `options`.
306
278
 
307
- * When calling `update_columns` on a record that is not persisted, the error
308
- message now reflects whether that object is a new record or has been
309
- destroyed.
279
+ *Joshua Flanagan*
310
280
 
311
- *Lachlan Sylvester*
281
+ * Retain explicit selections on the base model after applying `includes` and `joins`.
312
282
 
313
- * Define `id_was` to get the previous value of the primary key.
283
+ Resolves #34889.
314
284
 
315
- Currently when we call `id_was` and we have a custom primary key name,
316
- Active Record will return the current value of the primary key. This
317
- makes it impossible to correctly do an update operation if you change the
318
- id.
285
+ *Patrick Rebsch*
319
286
 
320
- Fixes #16413.
321
287
 
322
- *Rafael Mendonça França*
288
+ ## Rails 6.0.2.2 (March 19, 2020) ##
323
289
 
324
- * Deprecate `DatabaseTasks.load_schema` to act on the current connection.
325
- Use `.load_schema_current` instead. In the future `load_schema` will
326
- require the `configuration` to act on as an argument.
290
+ * No changes.
327
291
 
328
- *Yves Senn*
329
292
 
330
- * Fix automatic maintaining test schema to properly handle sql structure
331
- schema format.
293
+ ## Rails 6.0.2.1 (December 18, 2019) ##
332
294
 
333
- Fixes #15394.
295
+ * No changes.
334
296
 
335
- *Wojciech Wnętrzak*
336
297
 
337
- * Fix type casting to Decimal from Float with large precision.
298
+ ## Rails 6.0.2 (December 13, 2019) ##
338
299
 
339
- *Tomohiro Hashidate*
300
+ * Share the same connection pool for primary and replica databases in the
301
+ transactional tests for the same database.
340
302
 
341
- * Deprecate `Reflection#source_macro`
303
+ *Edouard Chin*
342
304
 
343
- `Reflection#source_macro` is no longer needed in Active Record
344
- source so it has been deprecated. Code that used `source_macro`
345
- was removed in #16353.
305
+ * Fix the preloader when one record is fetched using `after_initialize`
306
+ but not the entire collection.
346
307
 
347
- *Eileen M. Uchtitelle*, *Aaron Patterson*
308
+ *Bradley Price*
348
309
 
349
- * No verbose backtrace by `db:drop` when database does not exist.
310
+ * Fix collection callbacks not terminating when `:abort` is thrown.
350
311
 
351
- Fixes #16295.
312
+ *Edouard Chin*, *Ryuta Kamizono*
352
313
 
353
- *Kenn Ejima*
314
+ * Correctly deprecate `where.not` working as NOR for relations.
354
315
 
355
- * Add support for PostgreSQL JSONB.
316
+ 12a9664 deprecated where.not working as NOR, however
317
+ doing a relation query like `where.not(relation: { ... })`
318
+ wouldn't be properly deprecated and `where.not` would work as
319
+ NAND instead.
356
320
 
357
- Example:
321
+ *Edouard Chin*
358
322
 
359
- create_table :posts do |t|
360
- t.jsonb :meta_data
361
- end
323
+ * Fix `db:migrate` task with multiple databases to restore the connection
324
+ to the previous database.
362
325
 
363
- *Philippe Creux*, *Chris Teague*
326
+ The migrate task iterates and establish a connection over each db
327
+ resulting in the last one to be used by subsequent rake tasks.
328
+ We should reestablish a connection to the connection that was
329
+ established before the migrate tasks was run
364
330
 
365
- * `db:purge` with MySQL respects `Rails.env`.
331
+ *Edouard Chin*
366
332
 
367
- *Yves Senn*
333
+ * Fix multi-threaded issue for `AcceptanceValidator`.
368
334
 
369
- * `change_column_default :table, :column, nil` with PostgreSQL will issue a
370
- `DROP DEFAULT` instead of a `DEFAULT NULL` query.
335
+ *Ryuta Kamizono*
371
336
 
372
- Fixes #16261.
373
337
 
374
- *Matthew Draper*, *Yves Senn*
338
+ ## Rails 6.0.1 (November 5, 2019) ##
375
339
 
376
- * Allow to specify a type for the foreign key column in `references`
377
- and `add_reference`.
340
+ * Common Table Expressions are allowed on read-only connections.
378
341
 
379
- Example:
342
+ *Chris Morris*
380
343
 
381
- change_table :vehicle do |t|
382
- t.references :station, type: :uuid
383
- end
344
+ * New record instantiation respects `unscope`.
384
345
 
385
- *Andrey Novikov*, *Łukasz Sarnacki*
346
+ *Ryuta Kamizono*
386
347
 
387
- * `create_join_table` removes a common prefix when generating the join table.
388
- This matches the existing behavior of HABTM associations.
348
+ * Fixed a case where `find_in_batches` could halt too early.
389
349
 
390
- Fixes #13683.
350
+ *Takayuki Nakata*
391
351
 
392
- *Stefan Kanev*
352
+ * Autosaved associations always perform validations when a custom validation
353
+ context is used.
393
354
 
394
- * Do not swallow errors on `compute_type` when having a bad `alias_method` on
395
- a class.
355
+ *Tekin Suleyman*
396
356
 
397
- *arthurnn*
357
+ * `sql.active_record` notifications now include the `:connection` in
358
+ their payloads.
398
359
 
399
- * PostgreSQL invalid `uuid` are convert to nil.
360
+ *Eugene Kenny*
400
361
 
401
- *Abdelkader Boudih*
362
+ * A rollback encountered in an `after_commit` callback does not reset
363
+ previously-committed record state.
402
364
 
403
- * Restore 4.0 behavior for using serialize attributes with `JSON` as coder.
365
+ *Ryuta Kamizono*
404
366
 
405
- With 4.1.x, `serialize` started returning a string when `JSON` was passed as
406
- the second attribute. It will now return a hash as per previous versions.
367
+ * Fixed that join order was lost when eager-loading.
407
368
 
408
- Example:
369
+ *Ryuta Kamizono*
409
370
 
410
- class Post < ActiveRecord::Base
411
- serialize :comment, JSON
412
- end
371
+ * `DESCRIBE` queries are allowed on read-only connections.
413
372
 
414
- class Comment
415
- include ActiveModel::Model
416
- attr_accessor :category, :text
417
- end
373
+ *Dylan Thacker-Smith*
418
374
 
419
- post = Post.create!
420
- post.comment = Comment.new(category: "Animals", text: "This is a comment about squirrels.")
421
- post.save!
375
+ * Fixed that records that had been `inspect`ed could not be marshaled.
422
376
 
423
- # 4.0
424
- post.comment # => {"category"=>"Animals", "text"=>"This is a comment about squirrels."}
377
+ *Eugene Kenny*
425
378
 
426
- # 4.1 before
427
- post.comment # => "#<Comment:0x007f80ab48ff98>"
379
+ * The connection pool reaper thread is respawned in forked processes. This
380
+ fixes that idle connections in forked processes wouldn't be reaped.
428
381
 
429
- # 4.1 after
430
- post.comment # => {"category"=>"Animals", "text"=>"This is a comment about squirrels."}
382
+ *John Hawthorn*
431
383
 
432
- When using `JSON` as the coder in `serialize`, Active Record will use the
433
- new `ActiveRecord::Coders::JSON` coder which delegates its `dump/load` to
434
- `ActiveSupport::JSON.encode/decode`. This ensures special objects are dumped
435
- correctly using the `#as_json` hook.
384
+ * The memoized result of `ActiveRecord::Relation#take` is properly cleared
385
+ when `ActiveRecord::Relation#reset` or `ActiveRecord::Relation#reload`
386
+ is called.
436
387
 
437
- To keep the previous behaviour, supply a custom coder instead
438
- ([example](https://gist.github.com/jenncoop/8c4142bbe59da77daa63)).
388
+ *Anmol Arora*
439
389
 
440
- Fixes #15594.
390
+ * Fixed the performance regression for `primary_keys` introduced MySQL 8.0.
441
391
 
442
- *Jenn Cooper*
392
+ *Hiroyuki Ishii*
443
393
 
444
- * Do not use `RENAME INDEX` syntax for MariaDB 10.0.
394
+ * `insert`, `insert_all`, `upsert`, and `upsert_all` now clear the query cache.
445
395
 
446
- Fixes #15931.
396
+ *Eugene Kenny*
447
397
 
448
- *Jeff Browning*
398
+ * Call `while_preventing_writes` directly from `connected_to`.
449
399
 
450
- * Calling `#empty?` on a `has_many` association would use the value from the
451
- counter cache if one exists.
400
+ In some cases application authors want to use the database switching middleware and make explicit calls with `connected_to`. It's possible for an app to turn off writes and not turn them back on by the time we call `connected_to(role: :writing)`.
452
401
 
453
- *David Verhasselt*
402
+ This change allows apps to fix this by assuming if a role is writing we want to allow writes, except in the case it's explicitly turned off.
454
403
 
455
- * Fix the schema dump generated for tables without constraints and with
456
- primary key with default value of custom PostgreSQL function result.
404
+ *Eileen M. Uchitelle*
457
405
 
458
- Fixes #16111.
406
+ * Improve detection of ActiveRecord::StatementTimeout with mysql2 adapter in the edge case when the query is terminated during filesort.
459
407
 
460
- *Andrey Novikov*
408
+ *Kir Shatrov*
461
409
 
462
- * Fix the SQL generated when a `delete_all` is run on an association to not
463
- produce an `IN` statements.
464
410
 
465
- Before:
411
+ ## Rails 6.0.0 (August 16, 2019) ##
466
412
 
467
- UPDATE "categorizations" SET "category_id" = NULL WHERE
468
- "categorizations"."category_id" = 1 AND "categorizations"."id" IN (1, 2)
413
+ * Preserve user supplied joins order as much as possible.
469
414
 
470
- After:
415
+ Fixes #36761, #34328, #24281, #12953.
471
416
 
472
- UPDATE "categorizations" SET "category_id" = NULL WHERE
473
- "categorizations"."category_id" = 1
417
+ *Ryuta Kamizono*
474
418
 
475
- *Eileen M. Uchitelle, Aaron Patterson*
419
+ * Make the DATABASE_URL env variable only affect the primary connection. Add new env variables for multiple databases.
476
420
 
477
- * Avoid type casting boolean and `ActiveSupport::Duration` values to numeric
478
- values for string columns. Otherwise, in some database, the string column
479
- values will be coerced to a numeric allowing false or 0.seconds match any
480
- string starting with a non-digit.
421
+ *John Crepezzi*, *Eileen Uchitelle*
481
422
 
482
- Example:
423
+ * Add a warning for enum elements with 'not_' prefix.
483
424
 
484
- App.where(apikey: false) # => SELECT * FROM users WHERE apikey = '0'
425
+ class Foo
426
+ enum status: [:sent, :not_sent]
427
+ end
485
428
 
486
- *Dylan Thacker-Smith*
429
+ *Edu Depetris*
487
430
 
488
- * Add a `:required` option to singular associations, providing a nicer
489
- API for presence validations on associations.
431
+ * Make currency symbols optional for money column type in PostgreSQL
490
432
 
491
- *Sean Griffin*
433
+ *Joel Schneider*
492
434
 
493
- * Fix an error in `reset_counters` when associations have `select` scope.
494
- (Call to `count` generated invalid SQL.)
495
435
 
496
- *Cade Truitt*
436
+ ## Rails 6.0.0.rc2 (July 22, 2019) ##
497
437
 
498
- * After a successful `reload`, `new_record?` is always false.
438
+ * Add database_exists? method to connection adapters to check if a database exists.
499
439
 
500
- Fixes #12101.
440
+ *Guilherme Mansur*
501
441
 
502
- *Matthew Draper*
442
+ * PostgreSQL: Fix GROUP BY with ORDER BY virtual count attribute.
503
443
 
504
- * PostgreSQL renaming table doesn't attempt to rename non existent sequences.
444
+ Fixes #36022.
505
445
 
506
- *Abdelkader Boudih*
446
+ *Ryuta Kamizono*
507
447
 
508
- * Move 'dependent: :destroy' handling for `belongs_to`
509
- from `before_destroy` to `after_destroy` callback chain
448
+ * Make ActiveRecord `ConnectionPool.connections` method thread-safe.
510
449
 
511
- Fixes #12380.
450
+ Fixes #36465.
512
451
 
513
- *Ivan Antropov*
452
+ *Jeff Doering*
514
453
 
515
- * Detect in-place modifications on String attributes.
454
+ * Fix sqlite3 collation parsing when using decimal columns.
516
455
 
517
- Before this change, an attribute modified in-place had to be marked as
518
- changed in order for it to be persisted in the database. Now it is no longer
519
- required.
456
+ *Martin R. Schuster*
520
457
 
521
- Before:
458
+ * Fix invalid schema when primary key column has a comment.
522
459
 
523
- user = User.first
524
- user.name << ' Griffin'
525
- user.name_will_change!
526
- user.save
527
- user.reload.name # => "Sean Griffin"
460
+ Fixes #29966.
528
461
 
529
- After:
462
+ *Guilherme Goettems Schneider*
530
463
 
531
- user = User.first
532
- user.name << ' Griffin'
533
- user.save
534
- user.reload.name # => "Sean Griffin"
464
+ * Fix table comment also being applied to the primary key column.
535
465
 
536
- *Sean Griffin*
466
+ *Guilherme Goettems Schneider*
537
467
 
538
- * Add `ActiveRecord::Base#validate!` that raises `RecordInvalid` if the record
539
- is invalid.
468
+ * Fix merging left_joins to maintain its own `join_type` context.
540
469
 
541
- *Bogdan Gusiev*, *Marc Schütz*
470
+ Fixes #36103.
542
471
 
543
- * Support for adding and removing foreign keys. Foreign keys are now
544
- a part of `schema.rb`. This is supported by Mysql2Adapter, MysqlAdapter
545
- and PostgreSQLAdapter.
472
+ *Ryuta Kamizono*
546
473
 
547
- Many thanks to *Matthew Higgins* for laying the foundation with his work on
548
- [foreigner](https://github.com/matthuhiggins/foreigner).
549
474
 
550
- Example:
475
+ ## Rails 6.0.0.rc1 (April 24, 2019) ##
551
476
 
552
- # within your migrations:
553
- add_foreign_key :articles, :authors
554
- remove_foreign_key :articles, :authors
477
+ * Add `touch` option to `has_one` association.
555
478
 
556
- *Yves Senn*
479
+ *Abhay Nikam*
557
480
 
558
- * Fix subtle bugs regarding attribute assignment on models with no primary
559
- key. `'id'` will no longer be part of the attributes hash.
481
+ * Deprecate `where.not` working as NOR and will be changed to NAND in Rails 6.1.
560
482
 
561
- *Sean Griffin*
483
+ ```ruby
484
+ all = [treasures(:diamond), treasures(:sapphire), cars(:honda), treasures(:sapphire)]
485
+ assert_equal all, PriceEstimate.all.map(&:estimate_of)
486
+ ```
562
487
 
563
- * Deprecate automatic counter caches on `has_many :through`. The behavior was
564
- broken and inconsistent.
488
+ In Rails 6.0:
565
489
 
566
- *Sean Griffin*
490
+ ```ruby
491
+ sapphire = treasures(:sapphire)
567
492
 
568
- * `preload` preserves readonly flag for associations.
493
+ nor = all.reject { |e|
494
+ e.estimate_of_type == sapphire.class.polymorphic_name
495
+ }.reject { |e|
496
+ e.estimate_of_id == sapphire.id
497
+ }
498
+ assert_equal [cars(:honda)], nor
569
499
 
570
- See #15853.
500
+ without_sapphire = PriceEstimate.where.not(
501
+ estimate_of_type: sapphire.class.polymorphic_name, estimate_of_id: sapphire.id
502
+ )
503
+ assert_equal nor, without_sapphire.map(&:estimate_of)
504
+ ```
571
505
 
572
- *Yves Senn*
506
+ In Rails 6.1:
573
507
 
574
- * Assume numeric types have changed if they were assigned to a value that
575
- would fail numericality validation, regardless of the old value. Previously
576
- this would only occur if the old value was 0.
508
+ ```ruby
509
+ sapphire = treasures(:sapphire)
577
510
 
578
- Example:
511
+ nand = all - [sapphire]
512
+ assert_equal [treasures(:diamond), cars(:honda)], nand
579
513
 
580
- model = Model.create!(number: 5)
581
- model.number = '5wibble'
582
- model.number_changed? # => true
514
+ without_sapphire = PriceEstimate.where.not(
515
+ estimate_of_type: sapphire.class.polymorphic_name, estimate_of_id: sapphire.id
516
+ )
517
+ assert_equal nand, without_sapphire.map(&:estimate_of)
518
+ ```
583
519
 
584
- Fixes #14731.
520
+ *Ryuta Kamizono*
585
521
 
586
- *Sean Griffin*
522
+ * Fix dirty tracking after rollback.
587
523
 
588
- * `reload` no longer merges with the existing attributes.
589
- The attribute hash is fully replaced. The record is put into the same state
590
- as it would be with `Model.find(model.id)`.
524
+ Fixes #15018, #30167, #33868.
591
525
 
592
- *Sean Griffin*
526
+ *Ryuta Kamizono*
593
527
 
594
- * The object returned from `select_all` must respond to `column_types`.
595
- If this is not the case a `NoMethodError` is raised.
528
+ * Add `ActiveRecord::Relation#cache_version` to support recyclable cache keys via
529
+ the versioned entries in `ActiveSupport::Cache`. This also means that
530
+ `ActiveRecord::Relation#cache_key` will now return a stable key that does not
531
+ include the max timestamp or count any more.
596
532
 
597
- *Sean Griffin*
533
+ NOTE: This feature is turned off by default, and `cache_key` will still return
534
+ cache keys with timestamps until you set `ActiveRecord::Base.collection_cache_versioning = true`.
535
+ That's the setting for all new apps on Rails 6.0+
536
+
537
+ *Lachlan Sylvester*
598
538
 
599
- * Detect in-place modifications of PG array types
539
+ * Fix dirty tracking for `touch` to track saved changes.
600
540
 
601
- *Sean Griffin*
541
+ Fixes #33429.
602
542
 
603
- * Add `bin/rake db:purge` task to empty the current database.
543
+ *Ryuta Kamzono*
604
544
 
605
- *Yves Senn*
545
+ * `change_column_comment` and `change_table_comment` are invertible only if
546
+ `to` and `from` options are specified.
606
547
 
607
- * Deprecate `serialized_attributes` without replacement.
548
+ *Yoshiyuki Kinjo*
608
549
 
609
- *Sean Griffin*
550
+ * Don't call commit/rollback callbacks when a record isn't saved.
610
551
 
611
- * Correctly extract IPv6 addresses from `DATABASE_URI`: the square brackets
612
- are part of the URI structure, not the actual host.
552
+ Fixes #29747.
613
553
 
614
- Fixes #15705.
554
+ *Ryuta Kamizono*
615
555
 
616
- *Andy Bakun*, *Aaron Stone*
556
+ * Fix circular `autosave: true` causes invalid records to be saved.
617
557
 
618
- * Ensure both parent IDs are set on join records when both sides of a
619
- through association are new.
558
+ Prior to the fix, when there was a circular series of `autosave: true`
559
+ associations, the callback for a `has_many` association was run while
560
+ another instance of the same callback on the same association hadn't
561
+ finished running. When control returned to the first instance of the
562
+ callback, the instance variable had changed, and subsequent associated
563
+ records weren't saved correctly. Specifically, the ID field for the
564
+ `belongs_to` corresponding to the `has_many` was `nil`.
620
565
 
621
- *Sean Griffin*
566
+ Fixes #28080.
622
567
 
623
- * `ActiveRecord::Dirty` now detects in-place changes to mutable values.
624
- Serialized attributes on ActiveRecord models will no longer save when
625
- unchanged.
568
+ *Larry Reid*
626
569
 
627
- Fixes #8328.
570
+ * Raise `ArgumentError` for invalid `:limit` and `:precision` like as other options.
628
571
 
629
- *Sean Griffin*
572
+ Before:
630
573
 
631
- * `Pluck` now works when selecting columns from different tables with the same
632
- name.
574
+ ```ruby
575
+ add_column :items, :attr1, :binary, size: 10 # => ArgumentError
576
+ add_column :items, :attr2, :decimal, scale: 10 # => ArgumentError
577
+ add_column :items, :attr3, :integer, limit: 10 # => ActiveRecordError
578
+ add_column :items, :attr4, :datetime, precision: 10 # => ActiveRecordError
579
+ ```
633
580
 
634
- Fixes #15649.
581
+ After:
635
582
 
636
- *Sean Griffin*
583
+ ```ruby
584
+ add_column :items, :attr1, :binary, size: 10 # => ArgumentError
585
+ add_column :items, :attr2, :decimal, scale: 10 # => ArgumentError
586
+ add_column :items, :attr3, :integer, limit: 10 # => ArgumentError
587
+ add_column :items, :attr4, :datetime, precision: 10 # => ArgumentError
588
+ ```
637
589
 
638
- * Remove `cache_attributes` and friends. All attributes are cached.
590
+ *Ryuta Kamizono*
639
591
 
640
- *Sean Griffin*
592
+ * Association loading isn't to be affected by scoping consistently
593
+ whether preloaded / eager loaded or not, with the exception of `unscoped`.
641
594
 
642
- * Remove deprecated method `ActiveRecord::Base.quoted_locking_column`.
595
+ Before:
643
596
 
644
- *Akshay Vishnoi*
597
+ ```ruby
598
+ Post.where("1=0").scoping do
599
+ Comment.find(1).post # => nil
600
+ Comment.preload(:post).find(1).post # => #<Post id: 1, ...>
601
+ Comment.eager_load(:post).find(1).post # => #<Post id: 1, ...>
602
+ end
603
+ ```
645
604
 
646
- * `ActiveRecord::FinderMethods.find` with block can handle proc parameter as
647
- `Enumerable#find` does.
605
+ After:
648
606
 
649
- Fixes #15382.
607
+ ```ruby
608
+ Post.where("1=0").scoping do
609
+ Comment.find(1).post # => #<Post id: 1, ...>
610
+ Comment.preload(:post).find(1).post # => #<Post id: 1, ...>
611
+ Comment.eager_load(:post).find(1).post # => #<Post id: 1, ...>
612
+ end
613
+ ```
650
614
 
651
- *James Yang*
615
+ Fixes #34638, #35398.
652
616
 
653
- * Make timezone aware attributes work with PostgreSQL array columns.
617
+ *Ryuta Kamizono*
654
618
 
655
- Fixes #13402.
619
+ * Add `rails db:prepare` to migrate or setup a database.
656
620
 
657
- *Kuldeep Aggarwal*, *Sean Griffin*
621
+ Runs `db:migrate` if the database exists or `db:setup` if it doesn't.
658
622
 
659
- * `ActiveRecord::SchemaMigration` has no primary key regardless of the
660
- `primary_key_prefix_type` configuration.
623
+ *Roberto Miranda*
661
624
 
662
- Fixes #15051.
625
+ * Add `after_save_commit` callback as shortcut for `after_commit :hook, on: [ :create, :update ]`.
663
626
 
664
- *JoseLuis Torres*, *Yves Senn*
627
+ *DHH*
665
628
 
666
- * `rake db:migrate:status` works with legacy migration numbers like `00018_xyz.rb`.
629
+ * Assign all attributes before calling `build` to ensure the child record is visible in
630
+ `before_add` and `after_add` callbacks for `has_many :through` associations.
667
631
 
668
- Fixes #15538.
632
+ Fixes #33249.
669
633
 
670
- *Yves Senn*
634
+ *Ryan H. Kerr*
671
635
 
672
- * Baseclass becomes! subclass.
636
+ * Add `ActiveRecord::Relation#extract_associated` for extracting associated records from a relation.
673
637
 
674
- Before this change, a record which changed its STI type, could not be
675
- updated.
638
+ ```
639
+ account.memberships.extract_associated(:user)
640
+ # => Returns collection of User records
641
+ ```
676
642
 
677
- Fixes #14785.
643
+ *DHH*
678
644
 
679
- *Matthew Draper*, *Earl St Sauver*, *Edo Balvers*
645
+ * Add `ActiveRecord::Relation#annotate` for adding SQL comments to its queries.
680
646
 
681
- * Remove deprecated `ActiveRecord::Migrator.proper_table_name`. Use the
682
- `proper_table_name` instance method on `ActiveRecord::Migration` instead.
647
+ For example:
683
648
 
684
- *Akshay Vishnoi*
649
+ ```
650
+ Post.where(id: 123).annotate("this is a comment").to_sql
651
+ # SELECT "posts".* FROM "posts" WHERE "posts"."id" = 123 /* this is a comment */
652
+ ```
685
653
 
686
- * Fix regression on eager loading association based on SQL query rather than
687
- existing column.
654
+ This can be useful in instrumentation or other analysis of issued queries.
688
655
 
689
- Fixes #15480.
656
+ *Matt Yoho*
690
657
 
691
- *Lauro Caetano*, *Carlos Antonio da Silva*
658
+ * Support Optimizer Hints.
692
659
 
693
- * Deprecate returning `nil` from `column_for_attribute` when no column exists.
694
- It will return a null object in Rails 5.0
660
+ In most databases, a way to control the optimizer is by using optimizer hints,
661
+ which can be specified within individual statements.
695
662
 
696
- *Sean Griffin*
663
+ Example (for MySQL):
697
664
 
698
- * Implemented `ActiveRecord::Base#pretty_print` to work with PP.
665
+ Topic.optimizer_hints("MAX_EXECUTION_TIME(50000)", "NO_INDEX_MERGE(topics)")
666
+ # SELECT /*+ MAX_EXECUTION_TIME(50000) NO_INDEX_MERGE(topics) */ `topics`.* FROM `topics`
699
667
 
700
- *Ethan*
668
+ Example (for PostgreSQL with pg_hint_plan):
701
669
 
702
- * Preserve type when dumping PostgreSQL point, bit, bit varying and money
703
- columns.
670
+ Topic.optimizer_hints("SeqScan(topics)", "Parallel(topics 8)")
671
+ # SELECT /*+ SeqScan(topics) Parallel(topics 8) */ "topics".* FROM "topics"
704
672
 
705
- *Yves Senn*
673
+ See also:
706
674
 
707
- * New records remain new after YAML serialization.
675
+ * https://dev.mysql.com/doc/refman/8.0/en/optimizer-hints.html
676
+ * https://pghintplan.osdn.jp/pg_hint_plan.html
677
+ * https://docs.oracle.com/en/database/oracle/oracle-database/12.2/tgsql/influencing-the-optimizer.html
678
+ * https://docs.microsoft.com/en-us/sql/t-sql/queries/hints-transact-sql-query?view=sql-server-2017
679
+ * https://www.ibm.com/support/knowledgecenter/en/SSEPGG_11.1.0/com.ibm.db2.luw.admin.perf.doc/doc/c0070117.html
708
680
 
709
- *Sean Griffin*
681
+ *Ryuta Kamizono*
710
682
 
711
- * PostgreSQL support default values for enum types. Fixes #7814.
683
+ * Fix query attribute method on user-defined attribute to be aware of typecasted value.
712
684
 
713
- *Yves Senn*
685
+ For example, the following code no longer return false as casted non-empty string:
714
686
 
715
- * PostgreSQL `default_sequence_name` respects schema. Fixes #7516.
687
+ ```
688
+ class Post < ActiveRecord::Base
689
+ attribute :user_defined_text, :text
690
+ end
716
691
 
717
- *Yves Senn*
692
+ Post.new(user_defined_text: "false").user_defined_text? # => true
693
+ ```
718
694
 
719
- * Fix `columns_for_distinct` of PostgreSQL adapter to work correctly
720
- with orders without sort direction modifiers.
695
+ *Yuji Kamijima*
721
696
 
722
- *Nikolay Kondratyev*
697
+ * Quote empty ranges like other empty enumerables.
723
698
 
724
- * PostgreSQL `reset_pk_sequence!` respects schemas. Fixes #14719.
699
+ *Patrick Rebsch*
725
700
 
726
- *Yves Senn*
701
+ * Add `insert_all`/`insert_all!`/`upsert_all` methods to `ActiveRecord::Persistence`,
702
+ allowing bulk inserts akin to the bulk updates provided by `update_all` and
703
+ bulk deletes by `delete_all`.
727
704
 
728
- * Keep PostgreSQL `hstore` and `json` attributes as `Hash` in `@attributes`.
729
- Fixes duplication in combination with `store_accessor`.
705
+ Supports skipping or upserting duplicates through the `ON CONFLICT` syntax
706
+ for PostgreSQL (9.5+) and SQLite (3.24+) and `ON DUPLICATE KEY UPDATE` syntax
707
+ for MySQL.
730
708
 
731
- Fixes #15369.
709
+ *Bob Lail*
732
710
 
733
- *Yves Senn*
711
+ * Add `rails db:seed:replant` that truncates tables of each database
712
+ for current environment and loads the seeds.
734
713
 
735
- * `rake railties:install:migrations` respects the order of railties.
714
+ *bogdanvlviv*, *DHH*
736
715
 
737
- *Arun Agrawal*
716
+ * Add `ActiveRecord::Base.connection.truncate` for SQLite3 adapter.
738
717
 
739
- * Fix redefine a `has_and_belongs_to_many` inside inherited class
740
- Fixing regression case, where redefining the same `has_and_belongs_to_many`
741
- definition into a subclass would raise.
718
+ *bogdanvlviv*
742
719
 
743
- Fixes #14983.
720
+ * Deprecate mismatched collation comparison for uniqueness validator.
744
721
 
745
- *arthurnn*
722
+ Uniqueness validator will no longer enforce case sensitive comparison in Rails 6.1.
723
+ To continue case sensitive comparison on the case insensitive column,
724
+ pass `case_sensitive: true` option explicitly to the uniqueness validator.
746
725
 
747
- * Fix `has_and_belongs_to_many` public reflection.
748
- When defining a `has_and_belongs_to_many`, internally we convert that to two has_many.
749
- But as `reflections` is a public API, people expect to see the right macro.
726
+ *Ryuta Kamizono*
750
727
 
751
- Fixes #14682.
728
+ * Add `reselect` method. This is a short-hand for `unscope(:select).select(fields)`.
752
729
 
753
- *arthurnn*
730
+ Fixes #27340.
754
731
 
755
- * Fix serialization for records with an attribute named `format`.
732
+ *Willian Gustavo Veiga*
756
733
 
757
- Fixes #15188.
734
+ * Add negative scopes for all enum values.
758
735
 
759
- *Godfrey Chan*
736
+ Example:
760
737
 
761
- * When a `group` is set, `sum`, `size`, `average`, `minimum` and `maximum`
762
- on a NullRelation should return a Hash.
738
+ class Post < ActiveRecord::Base
739
+ enum status: %i[ drafted active trashed ]
740
+ end
763
741
 
764
- *Kuldeep Aggarwal*
742
+ Post.not_drafted # => where.not(status: :drafted)
743
+ Post.not_active # => where.not(status: :active)
744
+ Post.not_trashed # => where.not(status: :trashed)
765
745
 
766
- * Fix serialized fields returning serialized data after being updated with
767
- `update_column`.
746
+ *DHH*
768
747
 
769
- *Simon Hørup Eskildsen*
748
+ * Fix different `count` calculation when using `size` with manual `select` with DISTINCT.
770
749
 
771
- * Fix polymorphic eager loading when using a String as foreign key.
750
+ Fixes #35214.
772
751
 
773
- Fixes #14734.
752
+ *Juani Villarejo*
774
753
 
775
- *Lauro Caetano*
776
754
 
777
- * Change belongs_to touch to be consistent with timestamp updates
755
+ ## Rails 6.0.0.beta3 (March 11, 2019) ##
778
756
 
779
- If a model is set up with a belongs_to: touch relationship the parent
780
- record will only be touched if the record was modified. This makes it
781
- consistent with timestamp updating on the record itself.
757
+ * No changes.
782
758
 
783
- *Brock Trappitt*
784
759
 
785
- * Fix the inferred table name of a `has_and_belongs_to_many` auxiliary
786
- table inside a schema.
760
+ ## Rails 6.0.0.beta2 (February 25, 2019) ##
787
761
 
788
- Fixes #14824.
762
+ * Fix prepared statements caching to be enabled even when query caching is enabled.
789
763
 
790
- *Eric Chahin*
764
+ *Ryuta Kamizono*
791
765
 
792
- * Remove unused `:timestamp` type. Transparently alias it to `:datetime`
793
- in all cases. Fixes inconsistencies when column types are sent outside of
794
- `ActiveRecord`, such as for XML Serialization.
766
+ * Ensure `update_all` series cares about optimistic locking.
795
767
 
796
- *Sean Griffin*
768
+ *Ryuta Kamizono*
797
769
 
798
- * Fix bug that added `table_name_prefix` and `table_name_suffix` to
799
- extension names in PostgreSQL when migrating.
770
+ * Don't allow `where` with non numeric string matches to 0 values.
800
771
 
801
- *Joao Carlos*
772
+ *Ryuta Kamizono*
802
773
 
803
- * The `:index` option in migrations, which previously was only available for
804
- `references`, now works with any column types.
774
+ * Introduce `ActiveRecord::Relation#destroy_by` and `ActiveRecord::Relation#delete_by`.
805
775
 
806
- *Marc Schütz*
776
+ `destroy_by` allows relation to find all the records matching the condition and perform
777
+ `destroy_all` on the matched records.
807
778
 
808
- * Add support for counter name to be passed as parameter on `CounterCache::ClassMethods#reset_counters`.
779
+ Example:
809
780
 
810
- *jnormore*
781
+ Person.destroy_by(name: 'David')
782
+ Person.destroy_by(name: 'David', rating: 4)
811
783
 
812
- * Restrict deletion of record when using `delete_all` with `uniq`, `group`, `having`
813
- or `offset`.
784
+ david = Person.find_by(name: 'David')
785
+ david.posts.destroy_by(id: [1, 2, 3])
814
786
 
815
- In these cases the generated query ignored them and that caused unintended
816
- records to be deleted.
787
+ `delete_by` allows relation to find all the records matching the condition and perform
788
+ `delete_all` on the matched records.
817
789
 
818
- Fixes #11985.
790
+ Example:
819
791
 
820
- *Leandro Facchinetti*
792
+ Person.delete_by(name: 'David')
793
+ Person.delete_by(name: 'David', rating: 4)
821
794
 
822
- * Floats with limit >= 25 that get turned into doubles in MySQL no longer have
823
- their limit dropped from the schema.
795
+ david = Person.find_by(name: 'David')
796
+ david.posts.delete_by(id: [1, 2, 3])
824
797
 
825
- Fixes #14135.
798
+ *Abhay Nikam*
826
799
 
827
- *Aaron Nelson*
800
+ * Don't allow `where` with invalid value matches to nil values.
828
801
 
829
- * Fix how to calculate associated class name when using namespaced `has_and_belongs_to_many`
830
- association.
802
+ Fixes #33624.
831
803
 
832
- Fixes #14709.
804
+ *Ryuta Kamizono*
833
805
 
834
- *Kassio Borges*
806
+ * SQLite3: Implement `add_foreign_key` and `remove_foreign_key`.
835
807
 
836
- * `ActiveRecord::Relation::Merger#filter_binds` now compares equivalent symbols and
837
- strings in column names as equal.
808
+ *Ryuta Kamizono*
838
809
 
839
- This fixes a rare case in which more bind values are passed than there are
840
- placeholders for them in the generated SQL statement, which can make PostgreSQL
841
- throw a `StatementInvalid` exception.
810
+ * Deprecate using class level querying methods if the receiver scope
811
+ regarded as leaked. Use `klass.unscoped` to avoid the leaking scope.
842
812
 
843
- *Nat Budin*
813
+ *Ryuta Kamizono*
844
814
 
845
- * Fix `stored_attributes` to correctly merge the details of stored
846
- attributes defined in parent classes.
815
+ * Allow applications to automatically switch connections.
847
816
 
848
- Fixes #14672.
817
+ Adds a middleware and configuration options that can be used in your
818
+ application to automatically switch between the writing and reading
819
+ database connections.
849
820
 
850
- *Brad Bennett*, *Jessica Yao*, *Lakshmi Parthasarathy*
821
+ `GET` and `HEAD` requests will read from the replica unless there was
822
+ a write in the last 2 seconds, otherwise they will read from the primary.
823
+ Non-get requests will always write to the primary. The middleware accepts
824
+ an argument for a Resolver class and an Operations class where you are able
825
+ to change how the auto-switcher works to be most beneficial for your
826
+ application.
851
827
 
852
- * `change_column_default` allows `[]` as argument to `change_column_default`.
828
+ To use the middleware in your application you can use the following
829
+ configuration options:
853
830
 
854
- Fixes #11586.
831
+ ```
832
+ config.active_record.database_selector = { delay: 2.seconds }
833
+ config.active_record.database_resolver = ActiveRecord::Middleware::DatabaseSelector::Resolver
834
+ config.active_record.database_resolver_context = ActiveRecord::Middleware::DatabaseSelector::Resolver::Session
835
+ ```
855
836
 
856
- *Yves Senn*
837
+ To change the database selection strategy, pass a custom class to the
838
+ configuration options:
857
839
 
858
- * Handle `name` and `"char"` column types in the PostgreSQL adapter.
840
+ ```
841
+ config.active_record.database_selector = { delay: 10.seconds }
842
+ config.active_record.database_resolver = MyResolver
843
+ config.active_record.database_resolver_context = MyResolver::MyCookies
844
+ ```
859
845
 
860
- `name` and `"char"` are special character types used internally by
861
- PostgreSQL and are used by internal system catalogs. These field types
862
- can sometimes show up in structure-sniffing queries that feature internal system
863
- structures or with certain PostgreSQL extensions.
846
+ *Eileen M. Uchitelle*
864
847
 
865
- *J Smith*, *Yves Senn*
848
+ * MySQL: Support `:size` option to change text and blob size.
866
849
 
867
- * Fix `PostgreSQLAdapter::OID::Float#type_cast` to convert Infinity and
868
- NaN PostgreSQL values into a native Ruby `Float::INFINITY` and `Float::NAN`
850
+ *Ryuta Kamizono*
869
851
 
870
- Before:
852
+ * Make `t.timestamps` with precision by default.
871
853
 
872
- Point.create(value: 1.0/0)
873
- Point.last.value # => 0.0
854
+ *Ryuta Kamizono*
874
855
 
875
- After:
876
856
 
877
- Point.create(value: 1.0/0)
878
- Point.last.value # => Infinity
857
+ ## Rails 6.0.0.beta1 (January 18, 2019) ##
879
858
 
880
- *Innokenty Mikhailov*
859
+ * Remove deprecated `#set_state` from the transaction object.
881
860
 
882
- * Allow the PostgreSQL adapter to handle bigserial primary key types again.
861
+ *Rafael Mendonça França*
883
862
 
884
- Fixes #10410.
863
+ * Remove deprecated `#supports_statement_cache?` from the database adapters.
885
864
 
886
- *Patrick Robertson*
865
+ *Rafael Mendonça França*
887
866
 
888
- * Deprecate joining, eager loading and preloading of instance dependent
889
- associations without replacement. These operations happen before instances
890
- are created. The current behavior is unexpected and can result in broken
891
- behavior.
867
+ * Remove deprecated `#insert_fixtures` from the database adapters.
892
868
 
893
- Fixes #15024.
869
+ *Rafael Mendonça França*
894
870
 
895
- *Yves Senn*
871
+ * Remove deprecated `ActiveRecord::ConnectionAdapters::SQLite3Adapter#valid_alter_table_type?`.
896
872
 
897
- * Fix `has_and_belongs_to_many` CollectionAssociation size calculations.
873
+ *Rafael Mendonça França*
898
874
 
899
- `has_and_belongs_to_many` should fall back to using the normal CollectionAssociation's
900
- size calculation if the collection is not cached or loaded.
875
+ * Do not allow passing the column name to `sum` when a block is passed.
901
876
 
902
- Fixes #14913, #14914.
877
+ *Rafael Mendonça França*
903
878
 
904
- *Fred Wu*
879
+ * Do not allow passing the column name to `count` when a block is passed.
905
880
 
906
- * Return a non zero status when running `rake db:migrate:status` and migration table does
907
- not exist.
881
+ *Rafael Mendonça França*
908
882
 
909
- *Paul B.*
883
+ * Remove delegation of missing methods in a relation to arel.
910
884
 
911
- * Add support for module-level `table_name_suffix` in models.
885
+ *Rafael Mendonça França*
912
886
 
913
- This makes `table_name_suffix` work the same way as `table_name_prefix` when
914
- using namespaced models.
887
+ * Remove delegation of missing methods in a relation to private methods of the class.
915
888
 
916
- *Jenner LaFave*
889
+ *Rafael Mendonça França*
890
+
891
+ * Deprecate `config.active_record.sqlite3.represent_boolean_as_integer`.
917
892
 
918
- * Revert the behaviour of `ActiveRecord::Relation#join` changed through 4.0 => 4.1 to 4.0.
893
+ *Rafael Mendonça França*
919
894
 
920
- In 4.1.0 `Relation#join` is delegated to `Arel#SelectManager`.
921
- In 4.0 series it is delegated to `Array#join`.
895
+ * Change `SQLite3Adapter` to always represent boolean values as integers.
922
896
 
923
- *Bogdan Gusiev*
897
+ *Rafael Mendonça França*
924
898
 
925
- * Log nil binary column values correctly.
899
+ * Remove ability to specify a timestamp name for `#cache_key`.
926
900
 
927
- When an object with a binary column is updated with a nil value
928
- in that column, the SQL logger would throw an exception when trying
929
- to log that nil value. This only occurs when updating a record
930
- that already has a non-nil value in that column since an initial nil
931
- value isn't included in the SQL anyway (at least, when dirty checking
932
- is enabled.) The column's new value will now be logged as `<NULL binary data>`
933
- to parallel the existing `<N bytes of binary data>` for non-nil values.
901
+ *Rafael Mendonça França*
934
902
 
935
- *James Coleman*
903
+ * Remove deprecated `ActiveRecord::Migrator.migrations_path=`.
936
904
 
937
- * Rails will now pass a custom validation context through to autosave associations
938
- in order to validate child associations with the same context.
905
+ *Rafael Mendonça França*
939
906
 
940
- Fixes #13854.
907
+ * Remove deprecated `expand_hash_conditions_for_aggregates`.
941
908
 
942
- *Eric Chahin*, *Aaron Nelson*, *Kevin Casey*
909
+ *Rafael Mendonça França*
943
910
 
944
- * Stringify all variables keys of MySQL connection configuration.
911
+ * Set polymorphic type column to NULL on `dependent: :nullify` strategy.
945
912
 
946
- When `sql_mode` variable for MySQL adapters set in configuration as `String`
947
- was ignored and overwritten by strict mode option.
913
+ On polymorphic associations both the foreign key and the foreign type columns will be set to NULL.
948
914
 
949
- Fixes #14895.
915
+ *Laerti Papa*
950
916
 
951
- *Paul Nikitochkin*
917
+ * Allow permitted instance of `ActionController::Parameters` as argument of `ActiveRecord::Relation#exists?`.
952
918
 
953
- * Ensure SQLite3 statements are closed on errors.
919
+ *Gannon McGibbon*
954
920
 
955
- Fixes #13631.
921
+ * Add support for endless ranges introduces in Ruby 2.6.
956
922
 
957
- *Timur Alperovich*
923
+ *Greg Navis*
958
924
 
959
- * Give `ActiveRecord::PredicateBuilder` private methods the privacy they deserve.
925
+ * Deprecate passing `migrations_paths` to `connection.assume_migrated_upto_version`.
960
926
 
961
- *Hector Satre*
927
+ *Ryuta Kamizono*
962
928
 
963
- * When using a custom `join_table` name on a `habtm`, rails was not saving it
964
- on Reflections. This causes a problem when rails loads fixtures, because it
965
- uses the reflections to set database with fixtures.
929
+ * MySQL: `ROW_FORMAT=DYNAMIC` create table option by default.
966
930
 
967
- Fixes #14845.
931
+ Since MySQL 5.7.9, the `innodb_default_row_format` option defines the default row
932
+ format for InnoDB tables. The default setting is `DYNAMIC`.
933
+ The row format is required for indexing on `varchar(255)` with `utf8mb4` columns.
968
934
 
969
- *Kassio Borges*
935
+ *Ryuta Kamizono*
970
936
 
971
- * Reset the cache when modifying a Relation with cached Arel.
972
- Additionally display a warning message to make the user aware.
937
+ * Fix join table column quoting with SQLite.
973
938
 
974
- *Yves Senn*
939
+ *Gannon McGibbon*
975
940
 
976
- * PostgreSQL should internally use `:datetime` consistently for TimeStamp. Assures
977
- different spellings of timestamps are treated the same.
941
+ * Allow disabling scopes generated by `ActiveRecord.enum`.
978
942
 
979
- Example:
943
+ *Alfred Dominic*
980
944
 
981
- mytimestamp.simplified_type('timestamp without time zone')
982
- # => :datetime
983
- mytimestamp.simplified_type('timestamp(6) without time zone')
984
- # => also :datetime (previously would be :timestamp)
945
+ * Ensure that `delete_all` on collection proxy returns affected count.
946
+
947
+ *Ryuta Kamizono*
985
948
 
986
- See #14513.
949
+ * Reset scope after delete on collection association to clear stale offsets of removed records.
987
950
 
988
- *Jefferson Lai*
951
+ *Gannon McGibbon*
989
952
 
990
- * `ActiveRecord::Base.no_touching` no longer triggers callbacks or start empty transactions.
953
+ * Add the ability to prevent writes to a database for the duration of a block.
991
954
 
992
- Fixes #14841.
955
+ Allows the application to prevent writes to a database. This can be useful when
956
+ you're building out multiple databases and want to make sure you're not sending
957
+ writes when you want a read.
993
958
 
994
- *Lucas Mazza*
959
+ If `while_preventing_writes` is called and the query is considered a write
960
+ query the database will raise an exception regardless of whether the database
961
+ user is able to write.
995
962
 
996
- * Fix name collision with `Array#select!` with `Relation#select!`.
963
+ This is not meant to be a catch-all for write queries but rather a way to enforce
964
+ read-only queries without opening a second connection. One purpose of this is to
965
+ catch accidental writes, not all writes.
997
966
 
998
- Fixes #14752.
967
+ *Eileen M. Uchitelle*
999
968
 
1000
- *Earl St Sauver*
969
+ * Allow aliased attributes to be used in `#update_columns` and `#update`.
1001
970
 
1002
- * Fix unexpected behavior for `has_many :through` associations going through
1003
- a scoped `has_many`.
971
+ *Gannon McGibbon*
1004
972
 
1005
- If a `has_many` association is adjusted using a scope, and another
1006
- `has_many :through` uses this association, then the scope adjustment is
1007
- unexpectedly neglected.
973
+ * Allow spaces in postgres table names.
1008
974
 
1009
- Fixes #14537.
975
+ Fixes issue where "user post" is misinterpreted as "\"user\".\"post\"" when quoting table names with the postgres adapter.
1010
976
 
1011
- *Jan Habermann*
977
+ *Gannon McGibbon*
1012
978
 
1013
- * `@destroyed` should always be set to `false` when an object is duped.
979
+ * Cached `columns_hash` fields should be excluded from `ResultSet#column_types`.
1014
980
 
1015
- *Kuldeep Aggarwal*
981
+ PR #34528 addresses the inconsistent behaviour when attribute is defined for an ignored column. The following test
982
+ was passing for SQLite and MySQL, but failed for PostgreSQL:
1016
983
 
1017
- * Enable `has_many` associations to support irregular inflections.
984
+ ```ruby
985
+ class DeveloperName < ActiveRecord::Type::String
986
+ def deserialize(value)
987
+ "Developer: #{value}"
988
+ end
989
+ end
1018
990
 
1019
- Fixes #8928.
991
+ class AttributedDeveloper < ActiveRecord::Base
992
+ self.table_name = "developers"
1020
993
 
1021
- *arthurnn*, *Javier Goizueta*
994
+ attribute :name, DeveloperName.new
1022
995
 
1023
- * Fix `count` used with a grouping not returning a Hash.
996
+ self.ignored_columns += ["name"]
997
+ end
1024
998
 
1025
- Fixes #14721.
999
+ developer = AttributedDeveloper.create
1000
+ developer.update_column :name, "name"
1026
1001
 
1027
- *Eric Chahin*
1002
+ loaded_developer = AttributedDeveloper.where(id: developer.id).select("*").first
1003
+ puts loaded_developer.name # should be "Developer: name" but it's just "name"
1004
+ ```
1028
1005
 
1029
- * `sanitize_sql_like` helper method to escape a string for safe use in an SQL
1030
- LIKE statement.
1006
+ *Dmitry Tsepelev*
1007
+
1008
+ * Make the implicit order column configurable.
1009
+
1010
+ When calling ordered finder methods such as `first` or `last` without an
1011
+ explicit order clause, ActiveRecord sorts records by primary key. This can
1012
+ result in unpredictable and surprising behaviour when the primary key is
1013
+ not an auto-incrementing integer, for example when it's a UUID. This change
1014
+ makes it possible to override the column used for implicit ordering such
1015
+ that `first` and `last` will return more predictable results.
1031
1016
 
1032
1017
  Example:
1033
1018
 
1034
- class Article
1035
- def self.search(term)
1036
- where("title LIKE ?", sanitize_sql_like(term))
1037
- end
1019
+ class Project < ActiveRecord::Base
1020
+ self.implicit_order_column = "created_at"
1038
1021
  end
1039
1022
 
1040
- Article.search("20% _reduction_")
1041
- # => Query looks like "... title LIKE '20\% \_reduction\_' ..."
1023
+ *Tekin Suleyman*
1024
+
1025
+ * Bump minimum PostgreSQL version to 9.3.
1026
+
1027
+ *Yasuo Honda*
1028
+
1029
+ * Values of enum are frozen, raising an error when attempting to modify them.
1042
1030
 
1043
- *Rob Gilson*, *Yves Senn*
1031
+ *Emmanuel Byrd*
1044
1032
 
1045
- * Do not quote uuid default value on `change_column`.
1033
+ * Move `ActiveRecord::StatementInvalid` SQL to error property and include binds as separate error property.
1046
1034
 
1047
- Fixes #14604.
1035
+ `ActiveRecord::ConnectionAdapters::AbstractAdapter#translate_exception_class` now requires `binds` to be passed as the last argument.
1048
1036
 
1049
- *Eric Chahin*
1037
+ `ActiveRecord::ConnectionAdapters::AbstractAdapter#translate_exception` now requires `message`, `sql`, and `binds` to be passed as keyword arguments.
1050
1038
 
1051
- * The comparison between `Relation` and `CollectionProxy` should be consistent.
1039
+ Subclasses of `ActiveRecord::StatementInvalid` must now provide `sql:` and `binds:` arguments to `super`.
1052
1040
 
1053
1041
  Example:
1054
1042
 
1055
- author.posts == Post.where(author_id: author.id)
1056
- # => true
1057
- Post.where(author_id: author.id) == author.posts
1058
- # => true
1043
+ ```
1044
+ class MySubclassedError < ActiveRecord::StatementInvalid
1045
+ def initialize(message, sql:, binds:)
1046
+ super(message, sql: sql, binds: binds)
1047
+ end
1048
+ end
1049
+ ```
1059
1050
 
1060
- Fixes #13506.
1051
+ *Gannon McGibbon*
1061
1052
 
1062
- *Lauro Caetano*
1053
+ * Add an `:if_not_exists` option to `create_table`.
1063
1054
 
1064
- * Calling `delete_all` on an unloaded `CollectionProxy` no longer
1065
- generates an SQL statement containing each id of the collection:
1055
+ Example:
1066
1056
 
1067
- Before:
1057
+ create_table :posts, if_not_exists: true do |t|
1058
+ t.string :title
1059
+ end
1068
1060
 
1069
- DELETE FROM `model` WHERE `model`.`parent_id` = 1
1070
- AND `model`.`id` IN (1, 2, 3...)
1061
+ That would execute:
1071
1062
 
1072
- After:
1063
+ CREATE TABLE IF NOT EXISTS posts (
1064
+ ...
1065
+ )
1073
1066
 
1074
- DELETE FROM `model` WHERE `model`.`parent_id` = 1
1067
+ If the table already exists, `if_not_exists: false` (the default) raises an
1068
+ exception whereas `if_not_exists: true` does nothing.
1075
1069
 
1076
- *Eileen M. Uchitelle*, *Aaron Patterson*
1070
+ *fatkodima*, *Stefan Kanev*
1077
1071
 
1078
- * Fix invalid SQL when aggregate methods (`empty?`, `any?`, `count`) used
1079
- with `select`.
1072
+ * Defining an Enum as a Hash with blank key, or as an Array with a blank value, now raises an `ArgumentError`.
1080
1073
 
1081
- Fixes #13648.
1074
+ *Christophe Maximin*
1082
1075
 
1083
- *Simon Woker*
1076
+ * Adds support for multiple databases to `rails db:schema:cache:dump` and `rails db:schema:cache:clear`.
1084
1077
 
1085
- * PostgreSQL adapter only warns once for every missing OID per connection.
1078
+ *Gannon McGibbon*
1086
1079
 
1087
- Fixes #14275.
1080
+ * `update_columns` now correctly raises `ActiveModel::MissingAttributeError`
1081
+ if the attribute does not exist.
1088
1082
 
1089
- *Matthew Draper*, *Yves Senn*
1083
+ *Sean Griffin*
1090
1084
 
1091
- * PostgreSQL adapter automatically reloads it's type map when encountering
1092
- unknown OIDs.
1085
+ * Add support for hash and URL configs in database hash of `ActiveRecord::Base.connected_to`.
1093
1086
 
1094
- Fixes #14678.
1087
+ ````
1088
+ User.connected_to(database: { writing: "postgres://foo" }) do
1089
+ User.create!(name: "Gannon")
1090
+ end
1095
1091
 
1096
- *Matthew Draper*, *Yves Senn*
1092
+ config = { "adapter" => "sqlite3", "database" => "db/readonly.sqlite3" }
1093
+ User.connected_to(database: { reading: config }) do
1094
+ User.count
1095
+ end
1096
+ ````
1097
1097
 
1098
- * Fix insertion of records via `has_many :through` association with scope.
1098
+ *Gannon McGibbon*
1099
1099
 
1100
- Fixes #3548.
1100
+ * Support default expression for MySQL.
1101
1101
 
1102
- *Ivan Antropov*
1102
+ MySQL 8.0.13 and higher supports default value to be a function or expression.
1103
1103
 
1104
- * Auto-generate stable fixture UUIDs on PostgreSQL.
1104
+ https://dev.mysql.com/doc/refman/8.0/en/create-table.html
1105
1105
 
1106
- Fixes #11524.
1106
+ *Ryuta Kamizono*
1107
1107
 
1108
- *Roderick van Domburg*
1108
+ * Support expression indexes for MySQL.
1109
1109
 
1110
- * Fix a problem where an enum would overwrite values of another enum with the
1111
- same name in an unrelated class.
1110
+ MySQL 8.0.13 and higher supports functional key parts that index
1111
+ expression values rather than column or column prefix values.
1112
1112
 
1113
- Fixes #14607.
1113
+ https://dev.mysql.com/doc/refman/8.0/en/create-index.html
1114
+
1115
+ *Ryuta Kamizono*
1114
1116
 
1115
- *Evan Whalen*
1117
+ * Fix collection cache key with limit and custom select to avoid ambiguous timestamp column error.
1116
1118
 
1117
- * PostgreSQL and SQLite string columns no longer have a default limit of 255.
1119
+ Fixes #33056.
1118
1120
 
1119
- Fixes #13435, #9153.
1121
+ *Federico Martinez*
1120
1122
 
1121
- *Vladimir Sazhin*, *Toms Mikoss*, *Yves Senn*
1123
+ * Add basic API for connection switching to support multiple databases.
1122
1124
 
1123
- * Make possible to have an association called `records`.
1125
+ 1) Adds a `connects_to` method for models to connect to multiple databases. Example:
1124
1126
 
1125
- Fixes #11645.
1127
+ ```
1128
+ class AnimalsModel < ApplicationRecord
1129
+ self.abstract_class = true
1126
1130
 
1127
- *prathamesh-sonpatki*
1131
+ connects_to database: { writing: :animals_primary, reading: :animals_replica }
1132
+ end
1128
1133
 
1129
- * `to_sql` on an association now matches the query that is actually executed, where it
1130
- could previously have incorrectly accrued additional conditions (e.g. as a result of
1131
- a previous query). `CollectionProxy` now always defers to the association scope's
1132
- `arel` method so the (incorrect) inherited one should be entirely concealed.
1134
+ class Dog < AnimalsModel
1135
+ # connected to both the animals_primary db for writing and the animals_replica for reading
1136
+ end
1137
+ ```
1133
1138
 
1134
- Fixes #14003.
1139
+ 2) Adds a `connected_to` block method for switching connection roles or connecting to
1140
+ a database that the model didn't connect to. Connecting to the database in this block is
1141
+ useful when you have another defined connection, for example `slow_replica` that you don't
1142
+ want to connect to by default but need in the console, or a specific code block.
1135
1143
 
1136
- *Jefferson Lai*
1144
+ ```
1145
+ ActiveRecord::Base.connected_to(role: :reading) do
1146
+ Dog.first # finds dog from replica connected to AnimalsBase
1147
+ Book.first # doesn't have a reading connection, will raise an error
1148
+ end
1149
+ ```
1137
1150
 
1138
- * Block a few default Class methods as scope name.
1151
+ ```
1152
+ ActiveRecord::Base.connected_to(database: :slow_replica) do
1153
+ SlowReplicaModel.first # if the db config has a slow_replica configuration this will be used to do the lookup, otherwise this will throw an exception
1154
+ end
1155
+ ```
1139
1156
 
1140
- For instance, this will raise:
1157
+ *Eileen M. Uchitelle*
1141
1158
 
1142
- scope :public, -> { where(status: 1) }
1159
+ * Enum raises on invalid definition values
1143
1160
 
1144
- *arthurnn*
1161
+ When defining a Hash enum it can be easy to use `[]` instead of `{}`. This
1162
+ commit checks that only valid definition values are provided, those can
1163
+ be a Hash, an array of Symbols or an array of Strings. Otherwise it
1164
+ raises an `ArgumentError`.
1145
1165
 
1146
- * Fix error when using `with_options` with lambda.
1166
+ Fixes #33961
1147
1167
 
1148
- Fixes #9805.
1168
+ *Alberto Almagro*
1149
1169
 
1150
- *Lauro Caetano*
1170
+ * Reloading associations now clears the Query Cache like `Persistence#reload` does.
1151
1171
 
1152
- * Switch `sqlite3:///` URLs (which were temporarily
1153
- deprecated in 4.1) from relative to absolute.
1172
+ ```
1173
+ class Post < ActiveRecord::Base
1174
+ has_one :category
1175
+ belongs_to :author
1176
+ has_many :comments
1177
+ end
1154
1178
 
1155
- If you still want the previous interpretation, you should replace
1156
- `sqlite3:///my/path` with `sqlite3:my/path`.
1179
+ # Each of the following will now clear the query cache.
1180
+ post.reload_category
1181
+ post.reload_author
1182
+ post.comments.reload
1183
+ ```
1157
1184
 
1158
- *Matthew Draper*
1185
+ *Christophe Maximin*
1159
1186
 
1160
- * Treat blank UUID values as `nil`.
1187
+ * Added `index` option for `change_table` migration helpers.
1188
+ With this change you can create indexes while adding new
1189
+ columns into the existing tables.
1161
1190
 
1162
1191
  Example:
1163
1192
 
1164
- Sample.new(uuid_field: '') #=> <Sample id: nil, uuid_field: nil>
1193
+ change_table(:languages) do |t|
1194
+ t.string :country_code, index: true
1195
+ end
1165
1196
 
1166
- *Dmitry Lavrov*
1197
+ *Mehmet Emin İNAÇ*
1167
1198
 
1168
- * Enable support for materialized views on PostgreSQL >= 9.3.
1199
+ * Fix `transaction` reverting for migrations.
1169
1200
 
1170
- *Dave Lee*
1201
+ Before: Commands inside a `transaction` in a reverted migration ran uninverted.
1202
+ Now: This change fixes that by reverting commands inside `transaction` block.
1171
1203
 
1172
- * The PostgreSQL adapter supports custom domains. Fixes #14305.
1204
+ *fatkodima*, *David Verhasselt*
1173
1205
 
1174
- *Yves Senn*
1206
+ * Raise an error instead of scanning the filesystem root when `fixture_path` is blank.
1175
1207
 
1176
- * PostgreSQL `Column#type` is now determined through the corresponding OID.
1177
- The column types stay the same except for enum columns. They no longer have
1178
- `nil` as type but `enum`.
1208
+ *Gannon McGibbon*, *Max Albrecht*
1179
1209
 
1180
- See #7814.
1210
+ * Allow `ActiveRecord::Base.configurations=` to be set with a symbolized hash.
1181
1211
 
1182
- *Yves Senn*
1212
+ *Gannon McGibbon*
1183
1213
 
1184
- * Fix error when specifying a non-empty default value on a PostgreSQL array
1185
- column.
1214
+ * Don't update counter cache unless the record is actually saved.
1186
1215
 
1187
- Fixes #10613.
1216
+ Fixes #31493, #33113, #33117.
1188
1217
 
1189
- *Luke Steensen*
1218
+ *Ryuta Kamizono*
1190
1219
 
1191
- * Fix error where `.persisted?` throws SystemStackError for an unsaved model with a
1192
- custom primary key that did not save due to validation error.
1220
+ * Deprecate `ActiveRecord::Result#to_hash` in favor of `ActiveRecord::Result#to_a`.
1193
1221
 
1194
- Fixes #14393.
1222
+ *Gannon McGibbon*, *Kevin Cheng*
1195
1223
 
1196
- *Chris Finne*
1224
+ * SQLite3 adapter supports expression indexes.
1197
1225
 
1198
- * Introduce `validate` as an alias for `valid?`.
1226
+ ```
1227
+ create_table :users do |t|
1228
+ t.string :email
1229
+ end
1199
1230
 
1200
- This is more intuitive when you want to run validations but don't care about the return value.
1231
+ add_index :users, 'lower(email)', name: 'index_users_on_email', unique: true
1232
+ ```
1201
1233
 
1202
- *Henrik Nyh*
1234
+ *Gray Kemmey*
1203
1235
 
1204
- * Create indexes inline in CREATE TABLE for MySQL.
1236
+ * Allow subclasses to redefine autosave callbacks for associated records.
1205
1237
 
1206
- This is important, because adding an index on a temporary table after it has been created
1207
- would commit the transaction.
1238
+ Fixes #33305.
1208
1239
 
1209
- It also allows creating and dropping indexed tables with fewer queries and fewer permissions
1210
- required.
1240
+ *Andrey Subbota*
1211
1241
 
1212
- Example:
1242
+ * Bump minimum MySQL version to 5.5.8.
1213
1243
 
1214
- create_table :temp, temporary: true, as: "SELECT id, name, zip FROM a_really_complicated_query" do |t|
1215
- t.index :zip
1216
- end
1217
- # => CREATE TEMPORARY TABLE temp (INDEX (zip)) AS SELECT id, name, zip FROM a_really_complicated_query
1244
+ *Yasuo Honda*
1218
1245
 
1219
- *Cody Cutrer*, *Steve Rice*, *Rafael Mendonça Franca*
1246
+ * Use MySQL utf8mb4 character set by default.
1220
1247
 
1221
- * Use singular table name in generated migrations when
1222
- `ActiveRecord::Base.pluralize_table_names` is `false`.
1248
+ `utf8mb4` character set with 4-Byte encoding supports supplementary characters including emoji.
1249
+ The previous default 3-Byte encoding character set `utf8` is not enough to support them.
1223
1250
 
1224
- Fixes #13426.
1251
+ *Yasuo Honda*
1225
1252
 
1226
- *Kuldeep Aggarwal*
1253
+ * Fix duplicated record creation when using nested attributes with `create_with`.
1227
1254
 
1228
- * `touch` accepts many attributes to be touched at once.
1255
+ *Darwin Wu*
1229
1256
 
1230
- Example:
1257
+ * Configuration item `config.filter_parameters` could also filter out
1258
+ sensitive values of database columns when calling `#inspect`.
1259
+ We also added `ActiveRecord::Base::filter_attributes`/`=` in order to
1260
+ specify sensitive attributes to specific model.
1231
1261
 
1232
- # touches :signed_at, :sealed_at, and :updated_at/on attributes.
1233
- Photo.last.touch(:signed_at, :sealed_at)
1262
+ ```
1263
+ Rails.application.config.filter_parameters += [:credit_card_number, /phone/]
1264
+ Account.last.inspect # => #<Account id: 123, name: "DHH", credit_card_number: [FILTERED], telephone_number: [FILTERED] ...>
1265
+ SecureAccount.filter_attributes += [:name]
1266
+ SecureAccount.last.inspect # => #<SecureAccount id: 42, name: [FILTERED], credit_card_number: [FILTERED] ...>
1267
+ ```
1234
1268
 
1235
- *James Pinto*
1269
+ *Zhang Kang*, *Yoshiyuki Kinjo*
1236
1270
 
1237
- * `rake db:structure:dump` only dumps schema information if the schema
1238
- migration table exists.
1271
+ * Deprecate `column_name_length`, `table_name_length`, `columns_per_table`,
1272
+ `indexes_per_table`, `columns_per_multicolumn_index`, `sql_query_length`,
1273
+ and `joins_per_query` methods in `DatabaseLimits`.
1239
1274
 
1240
- Fixes #14217.
1275
+ *Ryuta Kamizono*
1241
1276
 
1242
- *Yves Senn*
1277
+ * `ActiveRecord::Base.configurations` now returns an object.
1243
1278
 
1244
- * Reap connections that were checked out by now-dead threads, instead
1245
- of waiting until they disconnect by themselves. Before this change,
1246
- a suitably constructed series of short-lived threads could starve
1247
- the connection pool, without ever having more than a couple alive at
1248
- the same time.
1279
+ `ActiveRecord::Base.configurations` used to return a hash, but this
1280
+ is an inflexible data model. In order to improve multiple-database
1281
+ handling in Rails, we've changed this to return an object. Some methods
1282
+ are provided to make the object behave hash-like in order to ease the
1283
+ transition process. Since most applications don't manipulate the hash
1284
+ we've decided to add backwards-compatible functionality that will throw
1285
+ a deprecation warning if used, however calling `ActiveRecord::Base.configurations`
1286
+ will use the new version internally and externally.
1249
1287
 
1250
- *Matthew Draper*
1288
+ For example, the following `database.yml`:
1251
1289
 
1252
- * `pk_and_sequence_for` now ensures that only the pg_depend entries
1253
- pointing to pg_class, and thus only sequence objects, are considered.
1290
+ ```
1291
+ development:
1292
+ adapter: sqlite3
1293
+ database: db/development.sqlite3
1294
+ ```
1254
1295
 
1255
- *Josh Williams*
1296
+ Used to become a hash:
1256
1297
 
1257
- * `where.not` adds `references` for `includes` like normal `where` calls do.
1298
+ ```
1299
+ { "development" => { "adapter" => "sqlite3", "database" => "db/development.sqlite3" } }
1300
+ ```
1258
1301
 
1259
- Fixes #14406.
1302
+ Is now converted into the following object:
1260
1303
 
1261
- *Yves Senn*
1304
+ ```
1305
+ #<ActiveRecord::DatabaseConfigurations:0x00007fd1acbdf800 @configurations=[
1306
+ #<ActiveRecord::DatabaseConfigurations::HashConfig:0x00007fd1acbded10 @env_name="development",
1307
+ @spec_name="primary", @config={"adapter"=>"sqlite3", "database"=>"db/development.sqlite3"}>
1308
+ ]
1309
+ ```
1262
1310
 
1263
- * Extend fixture `$LABEL` replacement to allow string interpolation.
1311
+ Iterating over the database configurations has also changed. Instead of
1312
+ calling hash methods on the `configurations` hash directly, a new method `configs_for` has
1313
+ been provided that allows you to select the correct configuration. `env_name` and
1314
+ `spec_name` arguments are optional. For example, these return an array of
1315
+ database config objects for the requested environment and a single database config object
1316
+ will be returned for the requested environment and specification name respectively.
1264
1317
 
1265
- Example:
1318
+ ```
1319
+ ActiveRecord::Base.configurations.configs_for(env_name: "development")
1320
+ ActiveRecord::Base.configurations.configs_for(env_name: "development", spec_name: "primary")
1321
+ ```
1266
1322
 
1267
- martin:
1268
- email: $LABEL@email.com
1323
+ *Eileen M. Uchitelle*, *Aaron Patterson*
1269
1324
 
1270
- users(:martin).email # => martin@email.com
1325
+ * Add database configuration to disable advisory locks.
1271
1326
 
1272
- *Eric Steele*
1327
+ ```
1328
+ production:
1329
+ adapter: postgresql
1330
+ advisory_locks: false
1331
+ ```
1273
1332
 
1274
- * Add support for `Relation` be passed as parameter on `QueryCache#select_all`.
1333
+ *Guo Xiang*
1275
1334
 
1276
- Fixes #14361.
1335
+ * SQLite3 adapter `alter_table` method restores foreign keys.
1277
1336
 
1278
- *arthurnn*
1337
+ *Yasuo Honda*
1279
1338
 
1280
- * Passing an Active Record object to `find` or `exists?` is now deprecated.
1281
- Call `.id` on the object first.
1339
+ * Allow `:to_table` option to `invert_remove_foreign_key`.
1282
1340
 
1283
- *Aaron Patterson*
1341
+ Example:
1284
1342
 
1285
- * Only use BINARY for MySQL case sensitive uniqueness check when column
1286
- has a case insensitive collation.
1343
+ remove_foreign_key :accounts, to_table: :owners
1287
1344
 
1288
- *Ryuta Kamizono*
1345
+ *Nikolay Epifanov*, *Rich Chen*
1346
+
1347
+ * Add environment & load_config dependency to `bin/rake db:seed` to enable
1348
+ seed load in environments without Rails and custom DB configuration
1349
+
1350
+ *Tobias Bielohlawek*
1289
1351
 
1290
- * Support for MySQL 5.6 fractional seconds.
1352
+ * Fix default value for mysql time types with specified precision.
1291
1353
 
1292
- *arthurnn*, *Tatsuhiko Miyagawa*
1354
+ *Nikolay Kondratyev*
1293
1355
 
1294
- * Support for PostgreSQL `citext` data type enabling case-insensitive
1295
- `where` values without needing to wrap in UPPER/LOWER sql functions.
1356
+ * Fix `touch` option to behave consistently with `Persistence#touch` method.
1296
1357
 
1297
- *Troy Kruthoff*, *Lachlan Sylvester*
1358
+ *Ryuta Kamizono*
1298
1359
 
1299
- * Only save has_one associations if record has changes.
1300
- Previously after save related callbacks, such as `#after_commit`, were triggered when the has_one
1301
- object did not get saved to the db.
1360
+ * Migrations raise when duplicate column definition.
1302
1361
 
1303
- *Alan Kennedy*
1362
+ Fixes #33024.
1304
1363
 
1305
- * Allow strings to specify the `#order` value.
1364
+ *Federico Martinez*
1306
1365
 
1307
- Example:
1366
+ * Bump minimum SQLite version to 3.8
1308
1367
 
1309
- Model.order(id: 'asc').to_sql == Model.order(id: :asc).to_sql
1368
+ *Yasuo Honda*
1310
1369
 
1311
- *Marcelo Casiraghi*, *Robin Dupret*
1370
+ * Fix parent record should not get saved with duplicate children records.
1312
1371
 
1313
- * Dynamically register PostgreSQL enum OIDs. This prevents "unknown OID"
1314
- warnings on enum columns.
1372
+ Fixes #32940.
1315
1373
 
1316
- *Dieter Komendera*
1374
+ *Santosh Wadghule*
1317
1375
 
1318
- * `includes` is able to detect the right preloading strategy when string
1319
- joins are involved.
1376
+ * Fix logic on disabling commit callbacks so they are not called unexpectedly when errors occur.
1320
1377
 
1321
- Fixes #14109.
1378
+ *Brian Durand*
1322
1379
 
1323
- *Aaron Patterson*, *Yves Senn*
1380
+ * Ensure `Associations::CollectionAssociation#size` and `Associations::CollectionAssociation#empty?`
1381
+ use loaded association ids if present.
1324
1382
 
1325
- * Fix error with validation with enum fields for records where the value for
1326
- any enum attribute is always evaluated as 0 during uniqueness validation.
1383
+ *Graham Turner*
1327
1384
 
1328
- Fixes #14172.
1385
+ * Add support to preload associations of polymorphic associations when not all the records have the requested associations.
1329
1386
 
1330
- *Vilius Luneckas* *Ahmed AbouElhamayed*
1387
+ *Dana Sherson*
1331
1388
 
1332
- * `before_add` callbacks are fired before the record is saved on
1333
- `has_and_belongs_to_many` associations *and* on `has_many :through`
1334
- associations. Before this change, `before_add` callbacks would be fired
1335
- before the record was saved on `has_and_belongs_to_many` associations, but
1336
- *not* on `has_many :through` associations.
1389
+ * Add `touch_all` method to `ActiveRecord::Relation`.
1337
1390
 
1338
- Fixes #14144.
1391
+ Example:
1339
1392
 
1340
- * Fix STI classes not defining an attribute method if there is a conflicting
1341
- private method defined on its ancestors.
1393
+ Person.where(name: "David").touch_all(time: Time.new(2020, 5, 16, 0, 0, 0))
1342
1394
 
1343
- Fixes #11569.
1395
+ *fatkodima*, *duggiefresh*
1344
1396
 
1345
- *Godfrey Chan*
1397
+ * Add `ActiveRecord::Base.base_class?` predicate.
1346
1398
 
1347
- * Coerce strings when reading attributes. Fixes #10485.
1399
+ *Bogdan Gusiev*
1348
1400
 
1349
- Example:
1401
+ * Add custom prefix/suffix options to `ActiveRecord::Store.store_accessor`.
1402
+
1403
+ *Tan Huynh*, *Yukio Mizuta*
1404
+
1405
+ * Rails 6 requires Ruby 2.5.0 or newer.
1406
+
1407
+ *Jeremy Daer*, *Kasper Timm Hansen*
1350
1408
 
1351
- book = Book.new(title: 12345)
1352
- book.save!
1353
- book.title # => "12345"
1409
+ * Deprecate `update_attributes`/`!` in favor of `update`/`!`.
1354
1410
 
1355
- *Yves Senn*
1411
+ *Eddie Lebow*
1356
1412
 
1357
- * Deprecate half-baked support for PostgreSQL range values with excluding beginnings.
1358
- We currently map PostgreSQL ranges to Ruby ranges. This conversion is not fully
1359
- possible because the Ruby range does not support excluded beginnings.
1413
+ * Add `ActiveRecord::Base.create_or_find_by`/`!` to deal with the SELECT/INSERT race condition in
1414
+ `ActiveRecord::Base.find_or_create_by`/`!` by leaning on unique constraints in the database.
1360
1415
 
1361
- The current solution of incrementing the beginning is not correct and is now
1362
- deprecated. For subtypes where we don't know how to increment (e.g. `#succ`
1363
- is not defined) it will raise an `ArgumentException` for ranges with excluding
1364
- beginnings.
1416
+ *DHH*
1365
1417
 
1366
- *Yves Senn*
1418
+ * Add `Relation#pick` as short-hand for single-value plucks.
1367
1419
 
1368
- * Support for user created range types in PostgreSQL.
1420
+ *DHH*
1369
1421
 
1370
- *Yves Senn*
1371
1422
 
1372
- Please check [4-1-stable](https://github.com/rails/rails/blob/4-1-stable/activerecord/CHANGELOG.md) for previous changes.
1423
+ Please check [5-2-stable](https://github.com/rails/rails/blob/5-2-stable/activerecord/CHANGELOG.md) for previous changes.