activerecord 5.0.6 → 6.0.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 (358) hide show
  1. checksums.yaml +5 -5
  2. data/CHANGELOG.md +638 -2023
  3. data/MIT-LICENSE +3 -1
  4. data/README.rdoc +8 -6
  5. data/examples/performance.rb +31 -29
  6. data/examples/simple.rb +5 -3
  7. data/lib/active_record/aggregations.rb +249 -246
  8. data/lib/active_record/association_relation.rb +24 -13
  9. data/lib/active_record/associations/alias_tracker.rb +24 -33
  10. data/lib/active_record/associations/association.rb +119 -56
  11. data/lib/active_record/associations/association_scope.rb +94 -94
  12. data/lib/active_record/associations/belongs_to_association.rb +58 -42
  13. data/lib/active_record/associations/belongs_to_polymorphic_association.rb +8 -12
  14. data/lib/active_record/associations/builder/association.rb +18 -25
  15. data/lib/active_record/associations/builder/belongs_to.rb +43 -54
  16. data/lib/active_record/associations/builder/collection_association.rb +7 -18
  17. data/lib/active_record/associations/builder/has_and_belongs_to_many.rb +42 -61
  18. data/lib/active_record/associations/builder/has_many.rb +4 -0
  19. data/lib/active_record/associations/builder/has_one.rb +37 -1
  20. data/lib/active_record/associations/builder/singular_association.rb +4 -0
  21. data/lib/active_record/associations/collection_association.rb +80 -252
  22. data/lib/active_record/associations/collection_proxy.rb +158 -121
  23. data/lib/active_record/associations/foreign_association.rb +9 -0
  24. data/lib/active_record/associations/has_many_association.rb +23 -29
  25. data/lib/active_record/associations/has_many_through_association.rb +58 -44
  26. data/lib/active_record/associations/has_one_association.rb +59 -54
  27. data/lib/active_record/associations/has_one_through_association.rb +20 -11
  28. data/lib/active_record/associations/join_dependency/join_association.rb +38 -90
  29. data/lib/active_record/associations/join_dependency/join_base.rb +10 -9
  30. data/lib/active_record/associations/join_dependency/join_part.rb +12 -12
  31. data/lib/active_record/associations/join_dependency.rb +134 -176
  32. data/lib/active_record/associations/preloader/association.rb +84 -125
  33. data/lib/active_record/associations/preloader/through_association.rb +82 -75
  34. data/lib/active_record/associations/preloader.rb +90 -102
  35. data/lib/active_record/associations/singular_association.rb +12 -45
  36. data/lib/active_record/associations/through_association.rb +26 -14
  37. data/lib/active_record/associations.rb +1603 -1592
  38. data/lib/active_record/attribute_assignment.rb +54 -60
  39. data/lib/active_record/attribute_decorators.rb +38 -15
  40. data/lib/active_record/attribute_methods/before_type_cast.rb +12 -7
  41. data/lib/active_record/attribute_methods/dirty.rb +179 -109
  42. data/lib/active_record/attribute_methods/primary_key.rb +86 -91
  43. data/lib/active_record/attribute_methods/query.rb +4 -3
  44. data/lib/active_record/attribute_methods/read.rb +21 -49
  45. data/lib/active_record/attribute_methods/serialization.rb +30 -7
  46. data/lib/active_record/attribute_methods/time_zone_conversion.rb +39 -64
  47. data/lib/active_record/attribute_methods/write.rb +35 -33
  48. data/lib/active_record/attribute_methods.rb +66 -106
  49. data/lib/active_record/attributes.rb +38 -24
  50. data/lib/active_record/autosave_association.rb +53 -32
  51. data/lib/active_record/base.rb +27 -24
  52. data/lib/active_record/callbacks.rb +63 -33
  53. data/lib/active_record/coders/json.rb +2 -0
  54. data/lib/active_record/coders/yaml_column.rb +11 -11
  55. data/lib/active_record/connection_adapters/abstract/connection_pool.rb +553 -321
  56. data/lib/active_record/connection_adapters/abstract/database_limits.rb +23 -5
  57. data/lib/active_record/connection_adapters/abstract/database_statements.rb +213 -94
  58. data/lib/active_record/connection_adapters/abstract/query_cache.rb +59 -28
  59. data/lib/active_record/connection_adapters/abstract/quoting.rb +119 -75
  60. data/lib/active_record/connection_adapters/abstract/savepoints.rb +2 -0
  61. data/lib/active_record/connection_adapters/abstract/schema_creation.rb +33 -27
  62. data/lib/active_record/connection_adapters/abstract/schema_definitions.rb +207 -126
  63. data/lib/active_record/connection_adapters/abstract/schema_dumper.rb +68 -80
  64. data/lib/active_record/connection_adapters/abstract/schema_statements.rb +369 -199
  65. data/lib/active_record/connection_adapters/abstract/transaction.rb +169 -78
  66. data/lib/active_record/connection_adapters/abstract_adapter.rb +363 -202
  67. data/lib/active_record/connection_adapters/abstract_mysql_adapter.rb +405 -551
  68. data/lib/active_record/connection_adapters/column.rb +41 -13
  69. data/lib/active_record/connection_adapters/connection_specification.rb +172 -138
  70. data/lib/active_record/connection_adapters/determine_if_preparable_visitor.rb +11 -4
  71. data/lib/active_record/connection_adapters/mysql/column.rb +8 -31
  72. data/lib/active_record/connection_adapters/mysql/database_statements.rb +143 -49
  73. data/lib/active_record/connection_adapters/mysql/explain_pretty_printer.rb +24 -22
  74. data/lib/active_record/connection_adapters/mysql/quoting.rb +50 -20
  75. data/lib/active_record/connection_adapters/mysql/schema_creation.rb +50 -45
  76. data/lib/active_record/connection_adapters/mysql/schema_definitions.rb +58 -56
  77. data/lib/active_record/connection_adapters/mysql/schema_dumper.rb +70 -36
  78. data/lib/active_record/connection_adapters/mysql/schema_statements.rb +264 -0
  79. data/lib/active_record/connection_adapters/mysql/type_metadata.rb +12 -13
  80. data/lib/active_record/connection_adapters/mysql2_adapter.rb +49 -30
  81. data/lib/active_record/connection_adapters/postgresql/column.rb +22 -7
  82. data/lib/active_record/connection_adapters/postgresql/database_statements.rb +60 -54
  83. data/lib/active_record/connection_adapters/postgresql/explain_pretty_printer.rb +5 -3
  84. data/lib/active_record/connection_adapters/postgresql/oid/array.rb +22 -10
  85. data/lib/active_record/connection_adapters/postgresql/oid/bit.rb +6 -5
  86. data/lib/active_record/connection_adapters/postgresql/oid/bit_varying.rb +2 -0
  87. data/lib/active_record/connection_adapters/postgresql/oid/bytea.rb +2 -0
  88. data/lib/active_record/connection_adapters/postgresql/oid/cidr.rb +3 -1
  89. data/lib/active_record/connection_adapters/postgresql/oid/date.rb +23 -0
  90. data/lib/active_record/connection_adapters/postgresql/oid/date_time.rb +4 -2
  91. data/lib/active_record/connection_adapters/postgresql/oid/decimal.rb +3 -1
  92. data/lib/active_record/connection_adapters/postgresql/oid/enum.rb +5 -3
  93. data/lib/active_record/connection_adapters/postgresql/oid/hstore.rb +19 -17
  94. data/lib/active_record/connection_adapters/postgresql/oid/inet.rb +2 -0
  95. data/lib/active_record/connection_adapters/postgresql/oid/jsonb.rb +3 -11
  96. data/lib/active_record/connection_adapters/postgresql/oid/legacy_point.rb +45 -0
  97. data/lib/active_record/connection_adapters/postgresql/oid/money.rb +7 -5
  98. data/lib/active_record/connection_adapters/postgresql/oid/{json.rb → oid.rb} +6 -1
  99. data/lib/active_record/connection_adapters/postgresql/oid/point.rb +31 -9
  100. data/lib/active_record/connection_adapters/postgresql/oid/range.rb +34 -30
  101. data/lib/active_record/connection_adapters/postgresql/oid/specialized_string.rb +4 -1
  102. data/lib/active_record/connection_adapters/postgresql/oid/type_map_initializer.rb +58 -54
  103. data/lib/active_record/connection_adapters/postgresql/oid/uuid.rb +9 -4
  104. data/lib/active_record/connection_adapters/postgresql/oid/vector.rb +2 -0
  105. data/lib/active_record/connection_adapters/postgresql/oid/xml.rb +2 -0
  106. data/lib/active_record/connection_adapters/postgresql/oid.rb +24 -21
  107. data/lib/active_record/connection_adapters/postgresql/quoting.rb +95 -35
  108. data/lib/active_record/connection_adapters/postgresql/referential_integrity.rb +19 -25
  109. data/lib/active_record/connection_adapters/postgresql/schema_creation.rb +76 -0
  110. data/lib/active_record/connection_adapters/postgresql/schema_definitions.rb +147 -105
  111. data/lib/active_record/connection_adapters/postgresql/schema_dumper.rb +35 -32
  112. data/lib/active_record/connection_adapters/postgresql/schema_statements.rb +380 -300
  113. data/lib/active_record/connection_adapters/postgresql/type_metadata.rb +26 -25
  114. data/lib/active_record/connection_adapters/postgresql/utils.rb +10 -6
  115. data/lib/active_record/connection_adapters/postgresql_adapter.rb +382 -275
  116. data/lib/active_record/connection_adapters/schema_cache.rb +46 -12
  117. data/lib/active_record/connection_adapters/sql_type_metadata.rb +13 -8
  118. data/lib/active_record/connection_adapters/sqlite3/database_statements.rb +120 -0
  119. data/lib/active_record/connection_adapters/sqlite3/explain_pretty_printer.rb +3 -1
  120. data/lib/active_record/connection_adapters/sqlite3/quoting.rb +74 -19
  121. data/lib/active_record/connection_adapters/sqlite3/schema_creation.rb +3 -8
  122. data/lib/active_record/connection_adapters/sqlite3/schema_definitions.rb +19 -0
  123. data/lib/active_record/connection_adapters/sqlite3/schema_dumper.rb +18 -0
  124. data/lib/active_record/connection_adapters/sqlite3/schema_statements.rb +137 -0
  125. data/lib/active_record/connection_adapters/sqlite3_adapter.rb +254 -262
  126. data/lib/active_record/connection_adapters/statement_pool.rb +9 -7
  127. data/lib/active_record/connection_handling.rb +159 -40
  128. data/lib/active_record/core.rb +202 -162
  129. data/lib/active_record/counter_cache.rb +57 -28
  130. data/lib/active_record/database_configurations/database_config.rb +37 -0
  131. data/lib/active_record/database_configurations/hash_config.rb +50 -0
  132. data/lib/active_record/database_configurations/url_config.rb +79 -0
  133. data/lib/active_record/database_configurations.rb +233 -0
  134. data/lib/active_record/define_callbacks.rb +22 -0
  135. data/lib/active_record/dynamic_matchers.rb +87 -86
  136. data/lib/active_record/enum.rb +60 -23
  137. data/lib/active_record/errors.rb +114 -18
  138. data/lib/active_record/explain.rb +4 -3
  139. data/lib/active_record/explain_registry.rb +3 -1
  140. data/lib/active_record/explain_subscriber.rb +9 -4
  141. data/lib/active_record/fixture_set/file.rb +13 -8
  142. data/lib/active_record/fixture_set/model_metadata.rb +33 -0
  143. data/lib/active_record/fixture_set/render_context.rb +17 -0
  144. data/lib/active_record/fixture_set/table_row.rb +153 -0
  145. data/lib/active_record/fixture_set/table_rows.rb +47 -0
  146. data/lib/active_record/fixtures.rb +195 -502
  147. data/lib/active_record/gem_version.rb +4 -2
  148. data/lib/active_record/inheritance.rb +151 -97
  149. data/lib/active_record/insert_all.rb +179 -0
  150. data/lib/active_record/integration.rb +116 -25
  151. data/lib/active_record/internal_metadata.rb +15 -18
  152. data/lib/active_record/legacy_yaml_adapter.rb +4 -2
  153. data/lib/active_record/locking/optimistic.rb +78 -87
  154. data/lib/active_record/locking/pessimistic.rb +18 -6
  155. data/lib/active_record/log_subscriber.rb +48 -29
  156. data/lib/active_record/middleware/database_selector/resolver/session.rb +45 -0
  157. data/lib/active_record/middleware/database_selector/resolver.rb +88 -0
  158. data/lib/active_record/middleware/database_selector.rb +75 -0
  159. data/lib/active_record/migration/command_recorder.rb +143 -97
  160. data/lib/active_record/migration/compatibility.rb +174 -56
  161. data/lib/active_record/migration/join_table.rb +8 -6
  162. data/lib/active_record/migration.rb +367 -300
  163. data/lib/active_record/model_schema.rb +145 -139
  164. data/lib/active_record/nested_attributes.rb +214 -201
  165. data/lib/active_record/no_touching.rb +10 -1
  166. data/lib/active_record/null_relation.rb +13 -34
  167. data/lib/active_record/persistence.rb +442 -72
  168. data/lib/active_record/query_cache.rb +15 -14
  169. data/lib/active_record/querying.rb +36 -23
  170. data/lib/active_record/railtie.rb +128 -36
  171. data/lib/active_record/railties/collection_cache_association_loading.rb +34 -0
  172. data/lib/active_record/railties/console_sandbox.rb +2 -0
  173. data/lib/active_record/railties/controller_runtime.rb +34 -33
  174. data/lib/active_record/railties/databases.rake +309 -177
  175. data/lib/active_record/readonly_attributes.rb +5 -4
  176. data/lib/active_record/reflection.rb +211 -249
  177. data/lib/active_record/relation/batches/batch_enumerator.rb +3 -1
  178. data/lib/active_record/relation/batches.rb +99 -52
  179. data/lib/active_record/relation/calculations.rb +211 -172
  180. data/lib/active_record/relation/delegation.rb +67 -65
  181. data/lib/active_record/relation/finder_methods.rb +208 -247
  182. data/lib/active_record/relation/from_clause.rb +2 -8
  183. data/lib/active_record/relation/merger.rb +78 -61
  184. data/lib/active_record/relation/predicate_builder/array_handler.rb +20 -14
  185. data/lib/active_record/relation/predicate_builder/association_query_value.rb +43 -0
  186. data/lib/active_record/relation/predicate_builder/base_handler.rb +4 -3
  187. data/lib/active_record/relation/predicate_builder/basic_object_handler.rb +6 -4
  188. data/lib/active_record/relation/predicate_builder/polymorphic_array_value.rb +53 -0
  189. data/lib/active_record/relation/predicate_builder/range_handler.rb +7 -18
  190. data/lib/active_record/relation/predicate_builder/relation_handler.rb +6 -0
  191. data/lib/active_record/relation/predicate_builder.rb +86 -104
  192. data/lib/active_record/relation/query_attribute.rb +33 -2
  193. data/lib/active_record/relation/query_methods.rb +458 -329
  194. data/lib/active_record/relation/record_fetch_warning.rb +5 -3
  195. data/lib/active_record/relation/spawn_methods.rb +8 -7
  196. data/lib/active_record/relation/where_clause.rb +111 -95
  197. data/lib/active_record/relation/where_clause_factory.rb +6 -11
  198. data/lib/active_record/relation.rb +429 -318
  199. data/lib/active_record/result.rb +69 -39
  200. data/lib/active_record/runtime_registry.rb +5 -3
  201. data/lib/active_record/sanitization.rb +83 -99
  202. data/lib/active_record/schema.rb +7 -14
  203. data/lib/active_record/schema_dumper.rb +71 -69
  204. data/lib/active_record/schema_migration.rb +15 -5
  205. data/lib/active_record/scoping/default.rb +93 -95
  206. data/lib/active_record/scoping/named.rb +45 -25
  207. data/lib/active_record/scoping.rb +20 -19
  208. data/lib/active_record/secure_token.rb +4 -2
  209. data/lib/active_record/serialization.rb +2 -0
  210. data/lib/active_record/statement_cache.rb +63 -28
  211. data/lib/active_record/store.rb +121 -41
  212. data/lib/active_record/suppressor.rb +4 -1
  213. data/lib/active_record/table_metadata.rb +26 -20
  214. data/lib/active_record/tasks/database_tasks.rb +276 -85
  215. data/lib/active_record/tasks/mysql_database_tasks.rb +54 -90
  216. data/lib/active_record/tasks/postgresql_database_tasks.rb +78 -47
  217. data/lib/active_record/tasks/sqlite_database_tasks.rb +34 -16
  218. data/lib/active_record/test_databases.rb +23 -0
  219. data/lib/active_record/test_fixtures.rb +224 -0
  220. data/lib/active_record/timestamp.rb +70 -35
  221. data/lib/active_record/touch_later.rb +7 -4
  222. data/lib/active_record/transactions.rb +133 -149
  223. data/lib/active_record/translation.rb +3 -1
  224. data/lib/active_record/type/adapter_specific_registry.rb +44 -45
  225. data/lib/active_record/type/date.rb +2 -0
  226. data/lib/active_record/type/date_time.rb +2 -0
  227. data/lib/active_record/type/decimal_without_scale.rb +15 -0
  228. data/lib/active_record/type/hash_lookup_type_map.rb +5 -3
  229. data/lib/active_record/type/internal/timezone.rb +2 -0
  230. data/lib/active_record/type/json.rb +30 -0
  231. data/lib/active_record/type/serialized.rb +16 -8
  232. data/lib/active_record/type/text.rb +11 -0
  233. data/lib/active_record/type/time.rb +2 -1
  234. data/lib/active_record/type/type_map.rb +13 -15
  235. data/lib/active_record/type/unsigned_integer.rb +17 -0
  236. data/lib/active_record/type.rb +23 -17
  237. data/lib/active_record/type_caster/connection.rb +17 -12
  238. data/lib/active_record/type_caster/map.rb +5 -4
  239. data/lib/active_record/type_caster.rb +4 -2
  240. data/lib/active_record/validations/absence.rb +2 -0
  241. data/lib/active_record/validations/associated.rb +3 -1
  242. data/lib/active_record/validations/length.rb +2 -0
  243. data/lib/active_record/validations/presence.rb +4 -2
  244. data/lib/active_record/validations/uniqueness.rb +29 -42
  245. data/lib/active_record/validations.rb +7 -4
  246. data/lib/active_record/version.rb +3 -1
  247. data/lib/active_record.rb +36 -22
  248. data/lib/arel/alias_predication.rb +9 -0
  249. data/lib/arel/attributes/attribute.rb +37 -0
  250. data/lib/arel/attributes.rb +22 -0
  251. data/lib/arel/collectors/bind.rb +24 -0
  252. data/lib/arel/collectors/composite.rb +31 -0
  253. data/lib/arel/collectors/plain_string.rb +20 -0
  254. data/lib/arel/collectors/sql_string.rb +20 -0
  255. data/lib/arel/collectors/substitute_binds.rb +28 -0
  256. data/lib/arel/crud.rb +42 -0
  257. data/lib/arel/delete_manager.rb +18 -0
  258. data/lib/arel/errors.rb +9 -0
  259. data/lib/arel/expressions.rb +29 -0
  260. data/lib/arel/factory_methods.rb +49 -0
  261. data/lib/arel/insert_manager.rb +49 -0
  262. data/lib/arel/math.rb +45 -0
  263. data/lib/arel/nodes/and.rb +32 -0
  264. data/lib/arel/nodes/ascending.rb +23 -0
  265. data/lib/arel/nodes/binary.rb +52 -0
  266. data/lib/arel/nodes/bind_param.rb +36 -0
  267. data/lib/arel/nodes/case.rb +55 -0
  268. data/lib/arel/nodes/casted.rb +50 -0
  269. data/lib/arel/nodes/comment.rb +29 -0
  270. data/lib/arel/nodes/count.rb +12 -0
  271. data/lib/arel/nodes/delete_statement.rb +45 -0
  272. data/lib/arel/nodes/descending.rb +23 -0
  273. data/lib/arel/nodes/equality.rb +18 -0
  274. data/lib/arel/nodes/extract.rb +24 -0
  275. data/lib/arel/nodes/false.rb +16 -0
  276. data/lib/arel/nodes/full_outer_join.rb +8 -0
  277. data/lib/arel/nodes/function.rb +44 -0
  278. data/lib/arel/nodes/grouping.rb +8 -0
  279. data/lib/arel/nodes/in.rb +8 -0
  280. data/lib/arel/nodes/infix_operation.rb +80 -0
  281. data/lib/arel/nodes/inner_join.rb +8 -0
  282. data/lib/arel/nodes/insert_statement.rb +37 -0
  283. data/lib/arel/nodes/join_source.rb +20 -0
  284. data/lib/arel/nodes/matches.rb +18 -0
  285. data/lib/arel/nodes/named_function.rb +23 -0
  286. data/lib/arel/nodes/node.rb +50 -0
  287. data/lib/arel/nodes/node_expression.rb +13 -0
  288. data/lib/arel/nodes/outer_join.rb +8 -0
  289. data/lib/arel/nodes/over.rb +15 -0
  290. data/lib/arel/nodes/regexp.rb +16 -0
  291. data/lib/arel/nodes/right_outer_join.rb +8 -0
  292. data/lib/arel/nodes/select_core.rb +67 -0
  293. data/lib/arel/nodes/select_statement.rb +41 -0
  294. data/lib/arel/nodes/sql_literal.rb +16 -0
  295. data/lib/arel/nodes/string_join.rb +11 -0
  296. data/lib/arel/nodes/table_alias.rb +27 -0
  297. data/lib/arel/nodes/terminal.rb +16 -0
  298. data/lib/arel/nodes/true.rb +16 -0
  299. data/lib/arel/nodes/unary.rb +45 -0
  300. data/lib/arel/nodes/unary_operation.rb +20 -0
  301. data/lib/arel/nodes/unqualified_column.rb +22 -0
  302. data/lib/arel/nodes/update_statement.rb +41 -0
  303. data/lib/arel/nodes/values_list.rb +9 -0
  304. data/lib/arel/nodes/window.rb +126 -0
  305. data/lib/arel/nodes/with.rb +11 -0
  306. data/lib/arel/nodes.rb +68 -0
  307. data/lib/arel/order_predications.rb +13 -0
  308. data/lib/arel/predications.rb +257 -0
  309. data/lib/arel/select_manager.rb +271 -0
  310. data/lib/arel/table.rb +110 -0
  311. data/lib/arel/tree_manager.rb +72 -0
  312. data/lib/arel/update_manager.rb +34 -0
  313. data/lib/arel/visitors/depth_first.rb +204 -0
  314. data/lib/arel/visitors/dot.rb +297 -0
  315. data/lib/arel/visitors/ibm_db.rb +34 -0
  316. data/lib/arel/visitors/informix.rb +62 -0
  317. data/lib/arel/visitors/mssql.rb +157 -0
  318. data/lib/arel/visitors/mysql.rb +83 -0
  319. data/lib/arel/visitors/oracle.rb +159 -0
  320. data/lib/arel/visitors/oracle12.rb +66 -0
  321. data/lib/arel/visitors/postgresql.rb +110 -0
  322. data/lib/arel/visitors/sqlite.rb +39 -0
  323. data/lib/arel/visitors/to_sql.rb +889 -0
  324. data/lib/arel/visitors/visitor.rb +46 -0
  325. data/lib/arel/visitors/where_sql.rb +23 -0
  326. data/lib/arel/visitors.rb +20 -0
  327. data/lib/arel/window_predications.rb +9 -0
  328. data/lib/arel.rb +58 -0
  329. data/lib/rails/generators/active_record/application_record/application_record_generator.rb +27 -0
  330. data/lib/rails/generators/active_record/{model/templates/application_record.rb → application_record/templates/application_record.rb.tt} +0 -0
  331. data/lib/rails/generators/active_record/migration/migration_generator.rb +37 -35
  332. data/lib/rails/generators/active_record/migration/templates/{create_table_migration.rb → create_table_migration.rb.tt} +1 -1
  333. data/lib/rails/generators/active_record/migration/templates/{migration.rb → migration.rb.tt} +4 -2
  334. data/lib/rails/generators/active_record/migration.rb +17 -2
  335. data/lib/rails/generators/active_record/model/model_generator.rb +9 -29
  336. data/lib/rails/generators/active_record/model/templates/{model.rb → model.rb.tt} +10 -1
  337. data/lib/rails/generators/active_record/model/templates/{module.rb → module.rb.tt} +0 -0
  338. data/lib/rails/generators/active_record.rb +7 -5
  339. metadata +133 -50
  340. data/lib/active_record/associations/preloader/belongs_to.rb +0 -17
  341. data/lib/active_record/associations/preloader/collection_association.rb +0 -17
  342. data/lib/active_record/associations/preloader/has_many.rb +0 -17
  343. data/lib/active_record/associations/preloader/has_many_through.rb +0 -19
  344. data/lib/active_record/associations/preloader/has_one.rb +0 -15
  345. data/lib/active_record/associations/preloader/has_one_through.rb +0 -9
  346. data/lib/active_record/associations/preloader/singular_association.rb +0 -20
  347. data/lib/active_record/attribute/user_provided_default.rb +0 -28
  348. data/lib/active_record/attribute.rb +0 -213
  349. data/lib/active_record/attribute_mutation_tracker.rb +0 -70
  350. data/lib/active_record/attribute_set/builder.rb +0 -130
  351. data/lib/active_record/attribute_set.rb +0 -110
  352. data/lib/active_record/collection_cache_key.rb +0 -50
  353. data/lib/active_record/connection_adapters/postgresql/oid/rails_5_1_point.rb +0 -50
  354. data/lib/active_record/railties/jdbcmysql_error.rb +0 -16
  355. data/lib/active_record/relation/predicate_builder/association_query_handler.rb +0 -88
  356. data/lib/active_record/relation/predicate_builder/class_handler.rb +0 -27
  357. data/lib/active_record/relation/predicate_builder/polymorphic_array_handler.rb +0 -57
  358. data/lib/active_record/type/internal/abstract_json.rb +0 -33
data/CHANGELOG.md CHANGED
@@ -1,2471 +1,1086 @@
1
- ## Rails 5.0.6 (September 07, 2017) ##
2
-
3
- * No changes.
1
+ ## Rails 6.0.1 (November 5, 2019) ##
4
2
 
3
+ * Common Table Expressions are allowed on read-only connections.
5
4
 
6
- ## Rails 5.0.6.rc1 (August 24, 2017) ##
5
+ *Chris Morris*
7
6
 
8
- * Ensure `sum` honors `distinct` on `has_many :through` associations
7
+ * New record instantiation respects `unscope`.
9
8
 
10
- Fixes #16791
9
+ *Ryuta Kamizono*
11
10
 
12
- *Aaron Wortham
11
+ * Fixed a case where `find_in_batches` could halt too early.
13
12
 
13
+ *Takayuki Nakata*
14
14
 
15
- ## Rails 5.0.5 (July 31, 2017) ##
16
-
17
- * No changes.
15
+ * Autosaved associations always perform validations when a custom validation
16
+ context is used.
18
17
 
18
+ *Tekin Suleyman*
19
19
 
20
- ## Rails 5.0.5.rc2 (July 25, 2017) ##
20
+ * `sql.active_record` notifications now include the `:connection` in
21
+ their payloads.
21
22
 
22
- * No changes.
23
+ *Eugene Kenny*
23
24
 
25
+ * A rollback encountered in an `after_commit` callback does not reset
26
+ previously-committed record state.
24
27
 
25
- ## Rails 5.0.5.rc1 (July 19, 2017) ##
28
+ *Ryuta Kamizono*
26
29
 
27
- * `Relation#joins` is no longer affected by the target model's
28
- `current_scope`, with the exception of `unscoped`.
30
+ * Fixed that join order was lost when eager-loading.
29
31
 
30
- Fixes #29338.
32
+ *Ryuta Kamizono*
31
33
 
32
- *Sean Griffin*
34
+ * `DESCRIBE` queries are allowed on read-only connections.
33
35
 
36
+ *Dylan Thacker-Smith*
34
37
 
35
- ## Rails 5.0.4 (June 19, 2017) ##
38
+ * Fixed that records that had been `inspect`ed could not be marshaled.
36
39
 
37
- * Restore previous behavior of collection proxies: their values can have
38
- methods stubbed, and they respect extension modules applied by a default
39
- scope.
40
+ *Eugene Kenny*
40
41
 
41
- *Ryuta Kamizono*
42
+ * The connection pool reaper thread is respawned in forked processes. This
43
+ fixes that idle connections in forked processes wouldn't be reaped.
42
44
 
43
- * Loading model schema from database is now thread-safe.
45
+ *John Hawthorn*
44
46
 
45
- Fixes #28589.
47
+ * The memoized result of `ActiveRecord::Relation#take` is properly cleared
48
+ when `ActiveRecord::Relation#reset` or `ActiveRecord::Relation#reload`
49
+ is called.
46
50
 
47
- *Vikrant Chaudhary*, *David Abdemoulaie*
51
+ *Anmol Arora*
48
52
 
53
+ * Fixed the performance regression for `primary_keys` introduced MySQL 8.0.
49
54
 
50
- ## Rails 5.0.3 (May 12, 2017) ##
55
+ *Hiroyuki Ishii*
51
56
 
52
- * Check whether `Rails.application` defined before calling it
57
+ * `insert`, `insert_all`, `upsert`, and `upsert_all` now clear the query cache.
53
58
 
54
- In #27674 we changed the migration generator to generate migrations at the
55
- path defined in `Rails.application.config.paths` however the code checked
56
- for the presence of the `Rails` constant but not the `Rails.application`
57
- method which caused problems when using Active Record and generators outside
58
- of the context of a Rails application.
59
+ *Eugene Kenny*
59
60
 
60
- Fixes #28325.
61
+ * Call `while_preventing_writes` directly from `connected_to`.
61
62
 
62
- * Fix `deserialize` with JSON array.
63
+ 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)`.
63
64
 
64
- Fixes #28285.
65
+ 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.
65
66
 
66
- *Ryuta Kamizono*
67
+ *Eileen M. Uchitelle*
67
68
 
68
- * Fix `rake db:schema:load` with subdirectories.
69
+ * Improve detection of ActiveRecord::StatementTimeout with mysql2 adapter in the edge case when the query is terminated during filesort.
69
70
 
70
- *Ryuta Kamizono*
71
+ *Kir Shatrov*
71
72
 
72
- * Fix `rake db:migrate:status` with subdirectories.
73
73
 
74
- *Ryuta Kamizono*
74
+ ## Rails 6.0.0 (August 16, 2019) ##
75
75
 
76
- * Don't share options between reference id and type columns
76
+ * Preserve user supplied joins order as much as possible.
77
77
 
78
- When using a polymorphic reference column in a migration, sharing options
79
- between the two columns doesn't make sense since they are different types.
80
- The `reference_id` column is usually an integer and the `reference_type`
81
- column a string so options like `unsigned: true` will result in an invalid
82
- table definition.
78
+ Fixes #36761, #34328, #24281, #12953.
83
79
 
84
80
  *Ryuta Kamizono*
85
81
 
86
- * Fix regression of #1969 with SELECT aliases in HAVING clause.
87
-
88
- *Eugene Kenny*
89
-
90
-
91
- ## Rails 5.0.2 (March 01, 2017) ##
92
-
93
- * Fix `wait_timeout` to configurable for mysql2 adapter.
82
+ * Make the DATABASE_URL env variable only affect the primary connection. Add new env variables for multiple databases.
94
83
 
95
- Fixes #26556.
84
+ *John Crepezzi*, *Eileen Uchitelle*
96
85
 
97
- *Ryuta Kamizono*
86
+ * Add a warning for enum elements with 'not_' prefix.
98
87
 
99
- * Make `table_name=` reset current statement cache,
100
- so queries are not run against the previous table name.
88
+ class Foo
89
+ enum status: [:sent, :not_sent]
90
+ end
101
91
 
102
- *namusyaka*
92
+ *Edu Depetris*
103
93
 
104
- * Allow ActiveRecord::Base#as_json to be passed a frozen Hash.
94
+ * Make currency symbols optional for money column type in PostgreSQL
105
95
 
106
- *Isaac Betesh*
96
+ *Joel Schneider*
107
97
 
108
- * Fix inspection behavior when the :id column is not primary key.
109
98
 
110
- *namusyaka*
99
+ ## Rails 6.0.0.rc2 (July 22, 2019) ##
111
100
 
112
- * Fix `association_primary_key_type` for reflections with symbol primary key
101
+ * Add database_exists? method to connection adapters to check if a database exists.
113
102
 
114
- Fixes #27864
103
+ *Guilherme Mansur*
115
104
 
116
- *Daniel Colson*
105
+ * PostgreSQL: Fix GROUP BY with ORDER BY virtual count attribute.
117
106
 
118
- * Place generated migrations into the path set by `config.paths["db/migrate"]`
107
+ Fixes #36022.
119
108
 
120
- *Kevin Glowacz*
109
+ *Ryuta Kamizono*
121
110
 
122
- * Compare deserialized values for `PostgreSQL::OID::Hstore` types when
123
- calling `ActiveRecord::Dirty#changed_in_place?`
111
+ * Make ActiveRecord `ConnectionPool.connections` method thread-safe.
124
112
 
125
- Fixes #27502.
113
+ Fixes #36465.
126
114
 
127
- *Jon Moss*
115
+ *Jeff Doering*
128
116
 
129
- * Respect precision option for arrays of timestamps.
117
+ * Fix sqlite3 collation parsing when using decimal columns.
130
118
 
131
- Fixes #27514.
119
+ *Martin R. Schuster*
132
120
 
133
- *Sean Griffin*
121
+ * Fix invalid schema when primary key column has a comment.
134
122
 
123
+ Fixes #29966.
135
124
 
136
- ## Rails 5.0.1 (December 21, 2016) ##
125
+ *Guilherme Goettems Schneider*
137
126
 
138
- * No changes.
127
+ * Fix table comment also being applied to the primary key column.
139
128
 
129
+ *Guilherme Goettems Schneider*
140
130
 
141
- ## Rails 5.0.1.rc2 (December 10, 2016) ##
131
+ * Fix merging left_joins to maintain its own `join_type` context.
142
132
 
143
- * Correct resolution of associated class in `has_many :through`
144
- associations' `*_ids` setters.
133
+ Fixes #36103.
145
134
 
146
- Fixes #27297.
135
+ *Ryuta Kamizono*
147
136
 
148
- *Matthew Draper*
149
137
 
150
- * Support index length and order options using both string and symbol
151
- column names.
138
+ ## Rails 6.0.0.rc1 (April 24, 2019) ##
152
139
 
153
- Fixes #27243.
140
+ * Add `touch` option to `has_one` association.
154
141
 
155
- *Ryuta Kamizono*
142
+ *Abhay Nikam*
156
143
 
144
+ * Deprecate `where.not` working as NOR and will be changed to NAND in Rails 6.1.
157
145
 
158
- ## Rails 5.0.1.rc1 (December 01, 2016) ##
146
+ ```ruby
147
+ all = [treasures(:diamond), treasures(:sapphire), cars(:honda), treasures(:sapphire)]
148
+ assert_equal all, PriceEstimate.all.map(&:estimate_of)
149
+ ```
159
150
 
160
- * Fix that unsigned with zerofill is treated as signed.
151
+ In Rails 6.0:
161
152
 
162
- Fixes #27125.
153
+ ```ruby
154
+ sapphire = treasures(:sapphire)
163
155
 
164
- *Ryuta Kamizono*
156
+ nor = all.reject { |e|
157
+ e.estimate_of_type == sapphire.class.polymorphic_name
158
+ }.reject { |e|
159
+ e.estimate_of_id == sapphire.id
160
+ }
161
+ assert_equal [cars(:honda)], nor
165
162
 
166
- * Fix the uniqueness validation scope with a polymorphic association.
163
+ without_sapphire = PriceEstimate.where.not(
164
+ estimate_of_type: sapphire.class.polymorphic_name, estimate_of_id: sapphire.id
165
+ )
166
+ assert_equal nor, without_sapphire.map(&:estimate_of)
167
+ ```
167
168
 
168
- *Sergey Alekseev*
169
+ In Rails 6.1:
169
170
 
170
- * Raise ActiveRecord::RecordNotFound from collection `*_ids` setters
171
- for unknown IDs with a better error message.
171
+ ```ruby
172
+ sapphire = treasures(:sapphire)
172
173
 
173
- Changes the collection `*_ids` setters to cast provided IDs the data
174
- type of the primary key set in the association, not the model
175
- primary key.
174
+ nand = all - [sapphire]
175
+ assert_equal [treasures(:diamond), cars(:honda)], nand
176
176
 
177
- *Dominic Cleal*
177
+ without_sapphire = PriceEstimate.where.not(
178
+ estimate_of_type: sapphire.class.polymorphic_name, estimate_of_id: sapphire.id
179
+ )
180
+ assert_equal nand, without_sapphire.map(&:estimate_of)
181
+ ```
178
182
 
179
- * Introduce `Model#reload_<association>` to bring back the behavior
180
- of `Article.category(true)` where `category` is a singular
181
- association.
183
+ *Ryuta Kamizono*
182
184
 
183
- The force reloading of the association reader was deprecated
184
- in #20888. Unfortunately the suggested alternative of
185
- `article.reload.category` does not expose the same behavior.
185
+ * Fix dirty tracking after rollback.
186
186
 
187
- This patch adds a reader method with the prefix `reload_` for
188
- singular associations. This method has the same semantics as
189
- passing true to the association reader used to have.
187
+ Fixes #15018, #30167, #33868.
190
188
 
191
- *Yves Senn*
189
+ *Ryuta Kamizono*
192
190
 
193
- * Make sure eager loading `ActiveRecord::Associations` also loads
194
- constants defined in `ActiveRecord::Associations::Preloader`.
191
+ * Add `ActiveRecord::Relation#cache_version` to support recyclable cache keys via
192
+ the versioned entries in `ActiveSupport::Cache`. This also means that
193
+ `ActiveRecord::Relation#cache_key` will now return a stable key that does not
194
+ include the max timestamp or count any more.
195
195
 
196
- *Yves Senn*
196
+ NOTE: This feature is turned off by default, and `cache_key` will still return
197
+ cache keys with timestamps until you set `ActiveRecord::Base.collection_cache_versioning = true`.
198
+ That's the setting for all new apps on Rails 6.0+
197
199
 
198
- * Allow `ActionController::Parameters`-like objects to be passed as
199
- values for Postgres HStore columns.
200
+ *Lachlan Sylvester*
200
201
 
201
- Fixes #26904.
202
+ * Fix dirty tracking for `touch` to track saved changes.
202
203
 
203
- *Jon Moss*
204
+ Fixes #33429.
204
205
 
205
- * Configure query caching (per thread) on the connection pool.
206
+ *Ryuta Kamzono*
206
207
 
207
- Moving the configuration to the pool means we don't allocate a connection
208
- until it's actually needed.
208
+ * `change_column_comment` and `change_table_comment` are invertible only if
209
+ `to` and `from` options are specified.
209
210
 
210
- Applications that manually interact with the connection pool and/or query
211
- cache may notice that the connection's cache is now cleared and disabled
212
- when it gets returned to the pool, even if the request is not yet completed.
211
+ *Yoshiyuki Kinjo*
213
212
 
214
- *Samuel Cochran*, *Matthew Draper*
213
+ * Don't call commit/rollback callbacks when a record isn't saved.
215
214
 
216
- * Fixed support for case insensitive comparisons of `text` columns in
217
- PostgreSQL.
215
+ Fixes #29747.
218
216
 
219
- *Edho Arief*
217
+ *Ryuta Kamizono*
220
218
 
221
- * Return `true` from `update_attribute` when the value of the attribute
222
- to be updated is unchanged.
219
+ * Fix circular `autosave: true` causes invalid records to be saved.
223
220
 
224
- Fixes #26593.
221
+ Prior to the fix, when there was a circular series of `autosave: true`
222
+ associations, the callback for a `has_many` association was run while
223
+ another instance of the same callback on the same association hadn't
224
+ finished running. When control returned to the first instance of the
225
+ callback, the instance variable had changed, and subsequent associated
226
+ records weren't saved correctly. Specifically, the ID field for the
227
+ `belongs_to` corresponding to the `has_many` was `nil`.
225
228
 
226
- *Prathamesh Sonpatki*
229
+ Fixes #28080.
227
230
 
228
- * Serialize JSON attribute value `nil` as SQL `NULL`, not JSON `null`
231
+ *Larry Reid*
229
232
 
230
- *Trung Duc Tran*
233
+ * Raise `ArgumentError` for invalid `:limit` and `:precision` like as other options.
231
234
 
232
- * Always store errors details information with symbols.
235
+ Before:
233
236
 
234
- When the association is autosaved we were storing the details with
235
- string keys. This was creating inconsistency with other details that are
236
- added using the `Errors#add` method. It was also inconsistent with the
237
- `Errors#messages` storage.
237
+ ```ruby
238
+ add_column :items, :attr1, :binary, size: 10 # => ArgumentError
239
+ add_column :items, :attr2, :decimal, scale: 10 # => ArgumentError
240
+ add_column :items, :attr3, :integer, limit: 10 # => ActiveRecordError
241
+ add_column :items, :attr4, :datetime, precision: 10 # => ActiveRecordError
242
+ ```
238
243
 
239
- To fix this inconsistency we are always storing with symbols. This will
240
- cause a small breaking change because in those cases the details could
241
- be accessed as strings keys but now it can not.
244
+ After:
242
245
 
243
- Fix #26499.
246
+ ```ruby
247
+ add_column :items, :attr1, :binary, size: 10 # => ArgumentError
248
+ add_column :items, :attr2, :decimal, scale: 10 # => ArgumentError
249
+ add_column :items, :attr3, :integer, limit: 10 # => ArgumentError
250
+ add_column :items, :attr4, :datetime, precision: 10 # => ArgumentError
251
+ ```
244
252
 
245
- *Rafael Mendonça França*, *Marcus Vieira*
253
+ *Ryuta Kamizono*
246
254
 
247
- * Using a mysql2 connection after it fails to reconnect will now have an error message
248
- saying the connection is closed rather than an undefined method error message.
255
+ * Association loading isn't to be affected by scoping consistently
256
+ whether preloaded / eager loaded or not, with the exception of `unscoped`.
249
257
 
250
- *Dylan Thacker-Smith*
258
+ Before:
251
259
 
252
- * Remove unnecessarily association load when a `belongs_to` association has already been
253
- loaded then the foreign key is changed directly and the record saved.
260
+ ```ruby
261
+ Post.where("1=0").scoping do
262
+ Comment.find(1).post # => nil
263
+ Comment.preload(:post).find(1).post # => #<Post id: 1, ...>
264
+ Comment.eager_load(:post).find(1).post # => #<Post id: 1, ...>
265
+ end
266
+ ```
254
267
 
255
- *James Coleman*
268
+ After:
256
269
 
257
- * PostgreSQL array columns will now respect the encoding of strings contained
258
- in the array.
270
+ ```ruby
271
+ Post.where("1=0").scoping do
272
+ Comment.find(1).post # => #<Post id: 1, ...>
273
+ Comment.preload(:post).find(1).post # => #<Post id: 1, ...>
274
+ Comment.eager_load(:post).find(1).post # => #<Post id: 1, ...>
275
+ end
276
+ ```
259
277
 
260
- Fixes #26326.
278
+ Fixes #34638, #35398.
261
279
 
262
- *Sean Griffin*
280
+ *Ryuta Kamizono*
263
281
 
264
- * Inverse association instances will now be set before `after_find` or
265
- `after_initialize` callbacks are run.
282
+ * Add `rails db:prepare` to migrate or setup a database.
266
283
 
267
- Fixes #26320.
284
+ Runs `db:migrate` if the database exists or `db:setup` if it doesn't.
268
285
 
269
- *Sean Griffin*
286
+ *Roberto Miranda*
270
287
 
271
- * Avoid loading records from database when they are already loaded using
272
- the `pluck` method on a collection.
288
+ * Add `after_save_commit` callback as shortcut for `after_commit :hook, on: [ :create, :update ]`.
273
289
 
274
- Fixes #25921.
290
+ *DHH*
275
291
 
276
- *Ryuta Kamizono*
292
+ * Assign all attributes before calling `build` to ensure the child record is visible in
293
+ `before_add` and `after_add` callbacks for `has_many :through` associations.
277
294
 
278
- * Sqlite3 migrations to add a column to an existing table can now be
279
- successfully rolled back when the column was given and invalid column
280
- type.
295
+ Fixes #33249.
281
296
 
282
- Fixes #26087
297
+ *Ryan H. Kerr*
283
298
 
284
- *Travis O'Neill*
299
+ * Add `ActiveRecord::Relation#extract_associated` for extracting associated records from a relation.
285
300
 
286
- * Hashes can once again be passed to setters of `composed_of`, if all of the
287
- mapping methods are methods implemented on `Hash`.
301
+ ```
302
+ account.memberships.extract_associated(:user)
303
+ # => Returns collection of User records
304
+ ```
288
305
 
289
- Fixes #25978.
306
+ *DHH*
290
307
 
291
- *Sean Griffin*
308
+ * Add `ActiveRecord::Relation#annotate` for adding SQL comments to its queries.
292
309
 
293
- * Doing count on relations that contain LEFT OUTER JOIN Arel node no longer
294
- force a DISTINCT. This solves issues when using count after a left_joins.
310
+ For example:
295
311
 
296
- *Maxime Handfield Lapointe*
312
+ ```
313
+ Post.where(id: 123).annotate("this is a comment").to_sql
314
+ # SELECT "posts".* FROM "posts" WHERE "posts"."id" = 123 /* this is a comment */
315
+ ```
297
316
 
298
- * RecordNotFound raised by association.find exposes `id`, `primary_key` and
299
- `model` methods to be consistent with RecordNotFound raised by Record.find.
317
+ This can be useful in instrumentation or other analysis of issued queries.
300
318
 
301
- *Michel Pigassou*
319
+ *Matt Yoho*
302
320
 
303
- * Fix the SELECT statement in `#table_comment` for MySQL.
321
+ * Support Optimizer Hints.
304
322
 
305
- *Takeshi Akima*
323
+ In most databases, a way to control the optimizer is by using optimizer hints,
324
+ which can be specified within individual statements.
306
325
 
307
- * Virtual attributes will no longer raise when read on models loaded from the
308
- database
326
+ Example (for MySQL):
309
327
 
310
- *Sean Griffin*
328
+ Topic.optimizer_hints("MAX_EXECUTION_TIME(50000)", "NO_INDEX_MERGE(topics)")
329
+ # SELECT /*+ MAX_EXECUTION_TIME(50000) NO_INDEX_MERGE(topics) */ `topics`.* FROM `topics`
311
330
 
312
- * Fixes multi-parameter attributes conversion with invalid params.
331
+ Example (for PostgreSQL with pg_hint_plan):
313
332
 
314
- *Hiroyuki Ishii*
333
+ Topic.optimizer_hints("SeqScan(topics)", "Parallel(topics 8)")
334
+ # SELECT /*+ SeqScan(topics) Parallel(topics 8) */ "topics".* FROM "topics"
315
335
 
316
- * Add newline between each migration in `structure.sql`.
336
+ See also:
317
337
 
318
- Keeps schema migration inserts as a single commit, but allows for easier
319
- git diff-ing. Fixes #25504.
338
+ * https://dev.mysql.com/doc/refman/8.0/en/optimizer-hints.html
339
+ * https://pghintplan.osdn.jp/pg_hint_plan.html
340
+ * https://docs.oracle.com/en/database/oracle/oracle-database/12.2/tgsql/influencing-the-optimizer.html
341
+ * https://docs.microsoft.com/en-us/sql/t-sql/queries/hints-transact-sql-query?view=sql-server-2017
342
+ * https://www.ibm.com/support/knowledgecenter/en/SSEPGG_11.1.0/com.ibm.db2.luw.admin.perf.doc/doc/c0070117.html
320
343
 
321
- *Grey Baker*, *Norberto Lopes*
344
+ *Ryuta Kamizono*
322
345
 
323
- * Using `group` with an attribute that has a custom type will properly cast
324
- the hash keys after calling a calculation method like `count`.
346
+ * Fix query attribute method on user-defined attribute to be aware of typecasted value.
325
347
 
326
- Fixes #25595.
348
+ For example, the following code no longer return false as casted non-empty string:
327
349
 
328
- *Sean Griffin*
350
+ ```
351
+ class Post < ActiveRecord::Base
352
+ attribute :user_defined_text, :text
353
+ end
329
354
 
330
- * Ensure concurrent invocations of the connection reaper cannot allocate the
331
- same connection to two threads.
355
+ Post.new(user_defined_text: "false").user_defined_text? # => true
356
+ ```
332
357
 
333
- Fixes #25585.
358
+ *Yuji Kamijima*
334
359
 
335
- *Matthew Draper*
360
+ * Quote empty ranges like other empty enumerables.
336
361
 
337
- * Fixed dumping of foreign key's referential actions when MySQL connection
338
- uses `sql_mode = ANSI_QUOTES`.
362
+ *Patrick Rebsch*
339
363
 
340
- Fixes #25300.
364
+ * Add `insert_all`/`insert_all!`/`upsert_all` methods to `ActiveRecord::Persistence`,
365
+ allowing bulk inserts akin to the bulk updates provided by `update_all` and
366
+ bulk deletes by `delete_all`.
341
367
 
342
- *Ryuta Kamizono*
368
+ Supports skipping or upserting duplicates through the `ON CONFLICT` syntax
369
+ for PostgreSQL (9.5+) and SQLite (3.24+) and `ON DUPLICATE KEY UPDATE` syntax
370
+ for MySQL.
343
371
 
372
+ *Bob Lail*
344
373
 
345
- ## Rails 5.0.0 (June 30, 2016) ##
374
+ * Add `rails db:seed:replant` that truncates tables of each database
375
+ for current environment and loads the seeds.
346
376
 
347
- * Inspecting an object with an associated array of over 10 elements no longer
348
- truncates the array, preventing `inspect` from looping infinitely in some
349
- cases.
377
+ *bogdanvlviv*, *DHH*
350
378
 
351
- *Kevin McPhillips*
379
+ * Add `ActiveRecord::Base.connection.truncate` for SQLite3 adapter.
352
380
 
353
- * Ensure hashes can be assigned to attributes created using `composed_of`.
381
+ *bogdanvlviv*
354
382
 
355
- Fixes #25210.
383
+ * Deprecate mismatched collation comparison for uniqueness validator.
356
384
 
357
- *Sean Griffin*
385
+ Uniqueness validator will no longer enforce case sensitive comparison in Rails 6.1.
386
+ To continue case sensitive comparison on the case insensitive column,
387
+ pass `case_sensitive: true` option explicitly to the uniqueness validator.
358
388
 
359
- * Fix logging edge case where if an attribute was of the binary type and
360
- was provided as a Hash.
389
+ *Ryuta Kamizono*
361
390
 
362
- *Jon Moss*
391
+ * Add `reselect` method. This is a short-hand for `unscope(:select).select(fields)`.
363
392
 
364
- * Handle JSON deserialization correctly if the column default from database
365
- adapter returns `''` instead of `nil`.
393
+ Fixes #27340.
366
394
 
367
- *Johannes Opper*
395
+ *Willian Gustavo Veiga*
368
396
 
369
- * PostgreSQL: Support Expression Indexes and Operator Classes.
397
+ * Add negative scopes for all enum values.
370
398
 
371
399
  Example:
372
400
 
373
- create_table :users do |t|
374
- t.string :name
375
- t.index 'lower(name) varchar_pattern_ops'
401
+ class Post < ActiveRecord::Base
402
+ enum status: %i[ drafted active trashed ]
376
403
  end
377
404
 
378
- Fixes #19090, #21765, #21819, #24359.
379
-
380
- *Ryuta Kamizono*
381
-
382
- * MySQL: Prepared statements support.
405
+ Post.not_drafted # => where.not(status: :drafted)
406
+ Post.not_active # => where.not(status: :active)
407
+ Post.not_trashed # => where.not(status: :trashed)
383
408
 
384
- To enable, set `prepared_statements: true` in config/database.yml.
385
- Requires mysql2 0.4.4+.
409
+ *DHH*
386
410
 
387
- *Ryuta Kamizono*
411
+ * Fix different `count` calculation when using `size` with manual `select` with DISTINCT.
388
412
 
389
- * Schema dumper: Indexes are now included in the `create_table` block
390
- instead of listed afterward as separate `add_index` lines.
413
+ Fixes #35214.
391
414
 
392
- This tidies up schema.rb and makes it easy to read as a list of tables.
415
+ *Juani Villarejo*
393
416
 
394
- Bonus: Allows databases that support it (MySQL) to perform as single
395
- `CREATE TABLE` query, no additional query per index.
396
417
 
397
- *Ryuta Kamizono*
418
+ ## Rails 6.0.0.beta3 (March 11, 2019) ##
398
419
 
399
- * SQLite: Fix uniqueness validation when values exceed the column limit.
420
+ * No changes.
400
421
 
401
- SQLite doesn't impose length restrictions on strings, BLOBs, or numeric
402
- values. It treats them as helpful metadata. When we truncate strings
403
- before checking uniqueness, we'd miss values that exceed the column limit.
404
422
 
405
- Other databases enforce length limits. A large value will pass uniqueness
406
- validation since the column limit guarantees no value that long exists.
407
- When we insert the row, it'll raise `ActiveRecord::ValueTooLong` as we
408
- expect.
423
+ ## Rails 6.0.0.beta2 (February 25, 2019) ##
409
424
 
410
- This fixes edge-case incorrect validation failures for values that exceed
411
- the column limit but are identical to an existing value *when truncated*.
412
- Now these will pass validation and raise an exception.
425
+ * Fix prepared statements caching to be enabled even when query caching is enabled.
413
426
 
414
427
  *Ryuta Kamizono*
415
428
 
416
- * Raise `ActiveRecord::ValueTooLong` when column limits are exceeded.
417
- Supported by MySQL and PostgreSQL adapters.
429
+ * Ensure `update_all` series cares about optimistic locking.
418
430
 
419
431
  *Ryuta Kamizono*
420
432
 
421
- * Migrations: `#foreign_key` respects `table_name_prefix` and `_suffix`.
433
+ * Don't allow `where` with non numeric string matches to 0 values.
422
434
 
423
435
  *Ryuta Kamizono*
424
436
 
425
- * SQLite: Force NOT NULL primary keys.
426
-
427
- From SQLite docs: https://www.sqlite.org/lang_createtable.html
428
- According to the SQL standard, PRIMARY KEY should always imply NOT
429
- NULL. Unfortunately, due to a bug in some early versions, this is not
430
- the case in SQLite. Unless the column is an INTEGER PRIMARY KEY or the
431
- table is a WITHOUT ROWID table or the column is declared NOT NULL,
432
- SQLite allows NULL values in a PRIMARY KEY column. SQLite could be
433
- fixed to conform to the standard, but doing so might break legacy
434
- applications. Hence, it has been decided to merely document the fact
435
- that SQLite allowing NULLs in most PRIMARY KEY columns.
436
-
437
- Now we override column options to explicitly set NOT NULL rather than rely
438
- on implicit NOT NULL like MySQL and PostgreSQL adapters.
439
-
440
- *Ryuta Kamizono*
437
+ * Introduce `ActiveRecord::Relation#destroy_by` and `ActiveRecord::Relation#delete_by`.
441
438
 
442
- * Added notice when a database is successfully created or dropped.
439
+ `destroy_by` allows relation to find all the records matching the condition and perform
440
+ `destroy_all` on the matched records.
443
441
 
444
442
  Example:
445
443
 
446
- $ bin/rails db:create
447
- Created database 'blog_development'
448
- Created database 'blog_test'
449
-
450
- $ bin/rails db:drop
451
- Dropped database 'blog_development'
452
- Dropped database 'blog_test'
453
-
454
- Changed older notices
455
- `blog_development already exists` to `Database 'blog_development' already exists`.
456
- and
457
- `Couldn't drop blog_development` to `Couldn't drop database 'blog_development'`.
458
-
459
- *bogdanvlviv*
460
-
461
- * Database comments. Annotate database objects (tables, columns, indexes)
462
- with comments stored in database metadata. PostgreSQL & MySQL support.
463
-
464
- create_table :pages, force: :cascade, comment: 'CMS content pages' do |t|
465
- t.string :path, comment: 'Path fragment of page URL used for routing'
466
- t.string :locale, comment: 'RFC 3066 locale code of website language section'
467
- t.index [:path, :locale], comment: 'Look up pages by URI'
468
- end
469
-
470
- *Andrey Novikov*
471
-
472
- * Add `quoted_time` for truncating the date part of a TIME column value.
473
- This fixes queries on TIME column on MariaDB, as it doesn't ignore the
474
- date part of the string when it coerces to time.
475
-
476
- *Ryuta Kamizono*
444
+ Person.destroy_by(name: 'David')
445
+ Person.destroy_by(name: 'David', rating: 4)
477
446
 
478
- * Properly accept all valid JSON primitives in the JSON data type.
447
+ david = Person.find_by(name: 'David')
448
+ david.posts.destroy_by(id: [1, 2, 3])
479
449
 
480
- Fixes #24234
481
-
482
- *Sean Griffin*
483
-
484
- * MariaDB 5.3+ supports microsecond datetime precision.
485
-
486
- *Jeremy Daer*
487
-
488
- * Delegate `none?` and `one?`. Now they can be invoked as model class methods.
450
+ `delete_by` allows relation to find all the records matching the condition and perform
451
+ `delete_all` on the matched records.
489
452
 
490
453
  Example:
491
454
 
492
- # When no record is found on the table
493
- Topic.none? # => true
494
-
495
- # When only one record is found on the table
496
- Topic.one? # => true
497
-
498
- *Kenta Shirai*
499
-
500
- * The form builder now properly displays values when passing a proc form
501
- default to the attributes API.
455
+ Person.delete_by(name: 'David')
456
+ Person.delete_by(name: 'David', rating: 4)
502
457
 
503
- Fixes #24249.
458
+ david = Person.find_by(name: 'David')
459
+ david.posts.delete_by(id: [1, 2, 3])
504
460
 
505
- *Sean Griffin*
506
-
507
- * The schema cache is now cleared after the `db:migrate` task is run.
461
+ *Abhay Nikam*
508
462
 
509
- Closes #24273.
463
+ * Don't allow `where` with invalid value matches to nil values.
510
464
 
511
- *Chris Arcand*
512
-
513
- * MySQL: strict mode respects other SQL modes rather than overwriting them.
514
- Setting `strict: true` adds `STRICT_ALL_TABLES` to `sql_mode`. Setting
515
- `strict: false` removes `STRICT_TRANS_TABLES`, `STRICT_ALL_TABLES`, and
516
- `TRADITIONAL` from `sql_mode`.
465
+ Fixes #33624.
517
466
 
518
467
  *Ryuta Kamizono*
519
468
 
520
- * Execute default_scope defined by abstract class in the context of subclass.
521
-
522
- Fixes #23413.
523
- Fixes #10658.
524
-
525
- *Mehmet Emin İNAÇ*
526
-
527
- * Fix an issue when preloading associations with extensions.
528
- Previously every association with extension methods was transformed into an
529
- instance dependent scope. This is no longer the case.
530
-
531
- Fixes #23934.
532
-
533
- *Yves Senn*
534
-
535
- * Deprecate `{insert|update|delete}_sql` in `DatabaseStatements`.
536
- Use the `{insert|update|delete}` public methods instead.
469
+ * SQLite3: Implement `add_foreign_key` and `remove_foreign_key`.
537
470
 
538
471
  *Ryuta Kamizono*
539
472
 
540
- * Added a configuration option to have active record raise an ArgumentError
541
- if the order or limit is ignored in a batch query, rather than logging a
542
- warning message.
473
+ * Deprecate using class level querying methods if the receiver scope
474
+ regarded as leaked. Use `klass.unscoped` to avoid the leaking scope.
543
475
 
544
- *Scott Ringwelski*
545
-
546
- * Honour the order of the joining model in a `has_many :through` association when eager loading.
476
+ *Ryuta Kamizono*
547
477
 
548
- Example:
478
+ * Allow applications to automatically switch connections.
549
479
 
550
- The below will now follow the order of `by_lines` when eager loading `authors`.
480
+ Adds a middleware and configuration options that can be used in your
481
+ application to automatically switch between the writing and reading
482
+ database connections.
551
483
 
552
- class Article < ActiveRecord::Base
553
- has_many :by_lines, -> { order(:position) }
554
- has_many :authors, through: :by_lines
555
- end
484
+ `GET` and `HEAD` requests will read from the replica unless there was
485
+ a write in the last 2 seconds, otherwise they will read from the primary.
486
+ Non-get requests will always write to the primary. The middleware accepts
487
+ an argument for a Resolver class and an Operations class where you are able
488
+ to change how the auto-switcher works to be most beneficial for your
489
+ application.
556
490
 
557
- Fixes #17864.
491
+ To use the middleware in your application you can use the following
492
+ configuration options:
558
493
 
559
- *Yasyf Mohamedali*, *Joel Turkel*
494
+ ```
495
+ config.active_record.database_selector = { delay: 2.seconds }
496
+ config.active_record.database_resolver = ActiveRecord::Middleware::DatabaseSelector::Resolver
497
+ config.active_record.database_resolver_context = ActiveRecord::Middleware::DatabaseSelector::Resolver::Session
498
+ ```
560
499
 
561
- * Ensure that the Suppressor runs before validations.
500
+ To change the database selection strategy, pass a custom class to the
501
+ configuration options:
562
502
 
563
- This moves the suppressor up to be run before validations rather than after
564
- validations. There's no reason to validate a record you aren't planning on saving.
503
+ ```
504
+ config.active_record.database_selector = { delay: 10.seconds }
505
+ config.active_record.database_resolver = MyResolver
506
+ config.active_record.database_resolver_context = MyResolver::MyCookies
507
+ ```
565
508
 
566
509
  *Eileen M. Uchitelle*
567
510
 
568
- * Save many-to-many objects based on association primary key.
569
-
570
- Fixes #20995.
571
-
572
- *himesh-r*
511
+ * MySQL: Support `:size` option to change text and blob size.
573
512
 
574
- * Ensure that mutations of the array returned from `ActiveRecord::Relation#to_a`
575
- do not affect the original relation, by returning a duplicate array each time.
576
-
577
- This brings the behavior in line with `CollectionProxy#to_a`, which was
578
- already more careful.
579
-
580
- *Matthew Draper*
581
-
582
- * Fixed `where` for polymorphic associations when passed an array containing different types.
583
-
584
- Fixes #17011.
585
-
586
- Example:
587
-
588
- PriceEstimate.where(estimate_of: [Treasure.find(1), Car.find(2)])
589
- # => SELECT "price_estimates".* FROM "price_estimates"
590
- WHERE (("price_estimates"."estimate_of_type" = 'Treasure' AND "price_estimates"."estimate_of_id" = 1)
591
- OR ("price_estimates"."estimate_of_type" = 'Car' AND "price_estimates"."estimate_of_id" = 2))
513
+ *Ryuta Kamizono*
592
514
 
593
- *Philippe Huibonhoa*
515
+ * Make `t.timestamps` with precision by default.
594
516
 
595
- * Fix a bug where using `t.foreign_key` twice with the same `to_table` within
596
- the same table definition would only create one foreign key.
517
+ *Ryuta Kamizono*
597
518
 
598
- *George Millo*
599
519
 
600
- * Fix a regression on has many association, where calling a child from parent in child's callback
601
- results in same child records getting added repeatedly to target.
520
+ ## Rails 6.0.0.beta1 (January 18, 2019) ##
602
521
 
603
- Fixes #13387.
522
+ * Remove deprecated `#set_state` from the transaction object.
604
523
 
605
- *Bogdan Gusiev*, *Jon Hinson*
524
+ *Rafael Mendonça França*
606
525
 
607
- * Rework `ActiveRecord::Relation#last`.
526
+ * Remove deprecated `#supports_statement_cache?` from the database adapters.
608
527
 
609
- 1. Never perform additional SQL on loaded relation
610
- 2. Use SQL reverse order instead of loading relation if relation doesn't have limit
611
- 3. Deprecated relation loading when SQL order can not be automatically reversed
528
+ *Rafael Mendonça França*
612
529
 
613
- Topic.order("title").load.last(3)
614
- # before: SELECT ...
615
- # after: No SQL
530
+ * Remove deprecated `#insert_fixtures` from the database adapters.
616
531
 
617
- Topic.order("title").last
618
- # before: SELECT * FROM `topics`
619
- # after: SELECT * FROM `topics` ORDER BY `topics`.`title` DESC LIMIT 1
532
+ *Rafael Mendonça França*
620
533
 
621
- Topic.order("coalesce(author, title)").last
622
- # before: SELECT * FROM `topics`
623
- # after: Deprecation Warning for irreversible order
534
+ * Remove deprecated `ActiveRecord::ConnectionAdapters::SQLite3Adapter#valid_alter_table_type?`.
624
535
 
625
- *Bogdan Gusiev*
536
+ *Rafael Mendonça França*
626
537
 
627
- * Allow `joins` to be unscoped.
538
+ * Do not allow passing the column name to `sum` when a block is passed.
628
539
 
629
- Fixes #13775.
540
+ *Rafael Mendonça França*
630
541
 
631
- *Takashi Kokubun*
542
+ * Do not allow passing the column name to `count` when a block is passed.
632
543
 
633
- * Add `#second_to_last` and `#third_to_last` finder methods.
544
+ *Rafael Mendonça França*
634
545
 
635
- *Brian Christian*
546
+ * Remove delegation of missing methods in a relation to arel.
636
547
 
637
- * Added `numeric` helper into migrations.
548
+ *Rafael Mendonça França*
638
549
 
639
- Example:
550
+ * Remove delegation of missing methods in a relation to private methods of the class.
640
551
 
641
- create_table(:numeric_types) do |t|
642
- t.numeric :numeric_type, precision: 10, scale: 2
643
- end
552
+ *Rafael Mendonça França*
644
553
 
645
- *Mehmet Emin İNAÇ*
554
+ * Deprecate `config.active_record.sqlite3.represent_boolean_as_integer`.
646
555
 
647
- * Bumped the minimum supported version of PostgreSQL to >= 9.1.
648
- Both PG 9.0 and 8.4 are past their end of life date:
649
- http://www.postgresql.org/support/versioning/
556
+ *Rafael Mendonça França*
650
557
 
651
- *Remo Mueller*
558
+ * Change `SQLite3Adapter` to always represent boolean values as integers.
652
559
 
653
- * `ActiveRecord::Relation#reverse_order` throws `ActiveRecord::IrreversibleOrderError`
654
- when the order can not be reversed using current trivial algorithm.
655
- Also raises the same error when `#reverse_order` is called on
656
- relation without any order and table has no primary key:
560
+ *Rafael Mendonça França*
657
561
 
658
- Topic.order("concat(author_name, title)").reverse_order
659
- # Before: SELECT `topics`.* FROM `topics` ORDER BY concat(author_name DESC, title) DESC
660
- # After: raises ActiveRecord::IrreversibleOrderError
661
- Edge.all.reverse_order
662
- # Before: SELECT `edges`.* FROM `edges` ORDER BY `edges`.`` DESC
663
- # After: raises ActiveRecord::IrreversibleOrderError
562
+ * Remove ability to specify a timestamp name for `#cache_key`.
664
563
 
665
- *Bogdan Gusiev*
564
+ *Rafael Mendonça França*
666
565
 
667
- * Improve schema_migrations insertion performance by inserting all versions
668
- in one INSERT SQL.
566
+ * Remove deprecated `ActiveRecord::Migrator.migrations_path=`.
669
567
 
670
- *Akira Matsuda*, *Naoto Koshikawa*
568
+ *Rafael Mendonça França*
671
569
 
672
- * Using `references` or `belongs_to` in migrations will always add index
673
- for the referenced column by default, without adding `index: true` option
674
- to generated migration file. Users can opt out of this by passing
675
- `index: false`.
570
+ * Remove deprecated `expand_hash_conditions_for_aggregates`.
676
571
 
677
- Fixes #18146.
572
+ *Rafael Mendonça França*
678
573
 
679
- *Matthew Draper*, *Prathamesh Sonpatki*
574
+ * Set polymorphic type column to NULL on `dependent: :nullify` strategy.
680
575
 
681
- * Run `type` attributes through attributes API type-casting before
682
- instantiating the corresponding subclass. This makes it possible to define
683
- custom STI mappings.
576
+ On polymorphic associations both the foreign key and the foreign type columns will be set to NULL.
684
577
 
685
- Fixes #21986.
578
+ *Laerti Papa*
686
579
 
687
- *Yves Senn*
580
+ * Allow permitted instance of `ActionController::Parameters` as argument of `ActiveRecord::Relation#exists?`.
688
581
 
689
- * Don't try to quote functions or expressions passed to `:default` option if
690
- they are passed as procs.
582
+ *Gannon McGibbon*
691
583
 
692
- This will generate proper query with the passed function or expression for
693
- the default option, instead of trying to quote it in incorrect fashion.
584
+ * Add support for endless ranges introduces in Ruby 2.6.
694
585
 
695
- Example:
586
+ *Greg Navis*
696
587
 
697
- create_table :posts do |t|
698
- t.datetime :published_at, default: -> { 'NOW()' }
699
- end
588
+ * Deprecate passing `migrations_paths` to `connection.assume_migrated_upto_version`.
700
589
 
701
590
  *Ryuta Kamizono*
702
591
 
703
- * Fix regression when loading fixture files with symbol keys.
704
-
705
- Fixes #22584.
592
+ * MySQL: `ROW_FORMAT=DYNAMIC` create table option by default.
706
593
 
707
- *Yves Senn*
594
+ Since MySQL 5.7.9, the `innodb_default_row_format` option defines the default row
595
+ format for InnoDB tables. The default setting is `DYNAMIC`.
596
+ The row format is required for indexing on `varchar(255)` with `utf8mb4` columns.
708
597
 
709
- * Use `version` column as primary key for schema_migrations table because
710
- `schema_migrations` versions are guaranteed to be unique.
711
-
712
- This makes it possible to use `update_attributes` on models that do
713
- not have a primary key.
598
+ *Ryuta Kamizono*
714
599
 
715
- *Richard Schneeman*
600
+ * Fix join table column quoting with SQLite.
716
601
 
717
- * Add short-hand methods for text and blob types in MySQL.
602
+ *Gannon McGibbon*
718
603
 
719
- In Pg and Sqlite3, `:text` and `:binary` have variable unlimited length.
720
- But in MySQL, these have limited length for each types (ref #21591, #21619).
721
- This change adds short-hand methods for each text and blob types.
604
+ * Allow disabling scopes generated by `ActiveRecord.enum`.
722
605
 
723
- Example:
606
+ *Alfred Dominic*
724
607
 
725
- create_table :foos do |t|
726
- t.tinyblob :tiny_blob
727
- t.mediumblob :medium_blob
728
- t.longblob :long_blob
729
- t.tinytext :tiny_text
730
- t.mediumtext :medium_text
731
- t.longtext :long_text
732
- end
608
+ * Ensure that `delete_all` on collection proxy returns affected count.
733
609
 
734
610
  *Ryuta Kamizono*
735
611
 
736
- * Take into account UTC offset when assigning string representation of
737
- timestamp with offset specified to attribute of time type.
738
-
739
- *Andrey Novikov*
740
-
741
- * When calling `first` with a `limit` argument, return directly from the
742
- `loaded?` records if available.
612
+ * Reset scope after delete on collection association to clear stale offsets of removed records.
743
613
 
744
- *Ben Woosley*
614
+ *Gannon McGibbon*
745
615
 
746
- * Deprecate sending the `offset` argument to `find_nth`. Please use the
747
- `offset` method on relation instead.
616
+ * Add the ability to prevent writes to a database for the duration of a block.
748
617
 
749
- *Ben Woosley*
618
+ Allows the application to prevent writes to a database. This can be useful when
619
+ you're building out multiple databases and want to make sure you're not sending
620
+ writes when you want a read.
750
621
 
751
- * Limit record touching to once per transaction.
622
+ If `while_preventing_writes` is called and the query is considered a write
623
+ query the database will raise an exception regardless of whether the database
624
+ user is able to write.
752
625
 
753
- If you have a parent/grand-parent relation like:
626
+ This is not meant to be a catch-all for write queries but rather a way to enforce
627
+ read-only queries without opening a second connection. One purpose of this is to
628
+ catch accidental writes, not all writes.
754
629
 
755
- Comment belongs_to :message, touch: true
756
- Message belongs_to :project, touch: true
757
- Project belongs_to :account, touch: true
758
-
759
- When the lowest entry(`Comment`) is saved, now, it won't repeat the touch
760
- call multiple times for the parent records.
761
-
762
- Related #18606.
630
+ *Eileen M. Uchitelle*
763
631
 
764
- *arthurnn*
632
+ * Allow aliased attributes to be used in `#update_columns` and `#update`.
765
633
 
766
- * Order the result of `find(ids)` to match the passed array, if the relation
767
- has no explicit order defined.
634
+ *Gannon McGibbon*
768
635
 
769
- Fixes #20338.
636
+ * Allow spaces in postgres table names.
770
637
 
771
- *Miguel Grazziotin*, *Matthew Draper*
638
+ Fixes issue where "user post" is misinterpreted as "\"user\".\"post\"" when quoting table names with the postgres adapter.
772
639
 
773
- * Omit default limit values in dumped schema. It's tidier, and if the defaults
774
- change in the future, we can address that via Migration API Versioning.
640
+ *Gannon McGibbon*
775
641
 
776
- *Jean Boussier*
642
+ * Cached `columns_hash` fields should be excluded from `ResultSet#column_types`.
777
643
 
778
- * Support passing the schema name as a prefix to table name in
779
- `ConnectionAdapters::SchemaStatements#indexes`. Previously the prefix would
780
- be considered a full part of the index name, and only the schema in the
781
- current search path would be considered.
644
+ PR #34528 addresses the inconsistent behaviour when attribute is defined for an ignored column. The following test
645
+ was passing for SQLite and MySQL, but failed for PostgreSQL:
782
646
 
783
- *Grey Baker*
647
+ ```ruby
648
+ class DeveloperName < ActiveRecord::Type::String
649
+ def deserialize(value)
650
+ "Developer: #{value}"
651
+ end
652
+ end
784
653
 
785
- * Ignore index name in `index_exists?` and `remove_index` when not passed a
786
- name to check for.
654
+ class AttributedDeveloper < ActiveRecord::Base
655
+ self.table_name = "developers"
787
656
 
788
- *Grey Baker*
657
+ attribute :name, DeveloperName.new
789
658
 
790
- * Extract support for the legacy `mysql` database adapter from core. It will
791
- live on in a separate gem for now, but most users should just use `mysql2`.
659
+ self.ignored_columns += ["name"]
660
+ end
792
661
 
793
- *Abdelkader Boudih*
662
+ developer = AttributedDeveloper.create
663
+ developer.update_column :name, "name"
794
664
 
795
- * ApplicationRecord is a new superclass for all app models, analogous to app
796
- controllers subclassing ApplicationController instead of
797
- ActionController::Base. This gives apps a single spot to configure app-wide
798
- model behavior.
665
+ loaded_developer = AttributedDeveloper.where(id: developer.id).select("*").first
666
+ puts loaded_developer.name # should be "Developer: name" but it's just "name"
667
+ ```
799
668
 
800
- Newly generated applications have `app/models/application_record.rb`
801
- present by default.
669
+ *Dmitry Tsepelev*
802
670
 
803
- *Genadi Samokovarov*
671
+ * Make the implicit order column configurable.
804
672
 
805
- * Version the API presented to migration classes, so we can change parameter
806
- defaults without breaking existing migrations, or forcing them to be
807
- rewritten through a deprecation cycle.
673
+ When calling ordered finder methods such as `first` or `last` without an
674
+ explicit order clause, ActiveRecord sorts records by primary key. This can
675
+ result in unpredictable and surprising behaviour when the primary key is
676
+ not an auto-incrementing integer, for example when it's a UUID. This change
677
+ makes it possible to override the column used for implicit ordering such
678
+ that `first` and `last` will return more predictable results.
808
679
 
809
- New migrations specify the Rails version they were written for:
680
+ Example:
810
681
 
811
- class AddStatusToOrders < ActiveRecord::Migration[5.0]
812
- def change
813
- # ...
814
- end
682
+ class Project < ActiveRecord::Base
683
+ self.implicit_order_column = "created_at"
815
684
  end
816
685
 
817
- *Matthew Draper*, *Ravil Bayramgalin*
686
+ *Tekin Suleyman*
818
687
 
819
- * Use bind params for `limit` and `offset`. This will generate significantly
820
- fewer prepared statements for common tasks like pagination. To support this
821
- change, passing a string containing a comma to `limit` has been deprecated,
822
- and passing an Arel node to `limit` is no longer supported.
688
+ * Bump minimum PostgreSQL version to 9.3.
823
689
 
824
- Fixes #22250.
690
+ *Yasuo Honda*
825
691
 
826
- *Sean Griffin*
827
-
828
- * Introduce after_{create,update,delete}_commit callbacks.
829
-
830
- Before:
692
+ * Values of enum are frozen, raising an error when attempting to modify them.
831
693
 
832
- after_commit :add_to_index_later, on: :create
833
- after_commit :update_in_index_later, on: :update
834
- after_commit :remove_from_index_later, on: :destroy
694
+ *Emmanuel Byrd*
835
695
 
836
- After:
837
-
838
- after_create_commit :add_to_index_later
839
- after_update_commit :update_in_index_later
840
- after_destroy_commit :remove_from_index_later
696
+ * Move `ActiveRecord::StatementInvalid` SQL to error property and include binds as separate error property.
841
697
 
842
- Fixes #22515.
698
+ `ActiveRecord::ConnectionAdapters::AbstractAdapter#translate_exception_class` now requires `binds` to be passed as the last argument.
843
699
 
844
- *Genadi Samokovarov*
700
+ `ActiveRecord::ConnectionAdapters::AbstractAdapter#translate_exception` now requires `message`, `sql`, and `binds` to be passed as keyword arguments.
845
701
 
846
- * Respect the column default values for `inheritance_column` when
847
- instantiating records through the base class.
848
-
849
- Fixes #17121.
702
+ Subclasses of `ActiveRecord::StatementInvalid` must now provide `sql:` and `binds:` arguments to `super`.
850
703
 
851
704
  Example:
852
705
 
853
- # The schema of BaseModel has `t.string :type, default: 'SubType'`
854
- subtype = BaseModel.new
855
- assert_equals SubType, subtype.class
856
-
857
- *Kuldeep Aggarwal*
706
+ ```
707
+ class MySubclassedError < ActiveRecord::StatementInvalid
708
+ def initialize(message, sql:, binds:)
709
+ super(message, sql: sql, binds: binds)
710
+ end
711
+ end
712
+ ```
858
713
 
859
- * Fix `rake db:structure:dump` on Postgres when multiple schemas are used.
714
+ *Gannon McGibbon*
860
715
 
861
- Fixes #22346.
716
+ * Add an `:if_not_exists` option to `create_table`.
862
717
 
863
- *Nick Muerdter*, *ckoenig*
864
-
865
- * Add schema dumping support for PostgreSQL geometric data types.
866
-
867
- *Ryuta Kamizono*
868
-
869
- * Except keys of `build_record`'s argument from `create_scope` in `initialize_attributes`.
870
-
871
- Fixes #21893.
872
-
873
- *Yuichiro Kaneko*
874
-
875
- * Deprecate `connection.tables` on the SQLite3 and MySQL adapters.
876
- Also deprecate passing arguments to `#tables`.
877
- And deprecate `table_exists?`.
878
-
879
- The `#tables` method of some adapters (mysql, mysql2, sqlite3) would return
880
- both tables and views while others (postgresql) just return tables. To make
881
- their behavior consistent, `#tables` will return only tables in the future.
882
-
883
- The `#table_exists?` method would check both tables and views. To make
884
- their behavior consistent with `#tables`, `#table_exists?` will check only
885
- tables in the future.
886
-
887
- *Yuichiro Kaneko*
888
-
889
- * Improve support for non Active Record objects on `validates_associated`
890
-
891
- Skipping `marked_for_destruction?` when the associated object does not responds
892
- to it make easier to validate virtual associations built on top of Active Model
893
- objects and/or serialized objects that implement a `valid?` instance method.
894
-
895
- *Kassio Borges*, *Lucas Mazza*
718
+ Example:
896
719
 
897
- * Change connection management middleware to return a new response with
898
- a body proxy, rather than mutating the original.
720
+ create_table :posts, if_not_exists: true do |t|
721
+ t.string :title
722
+ end
899
723
 
900
- *Kevin Buchanan*
724
+ That would execute:
901
725
 
902
- * Make `db:migrate:status` to render `1_some.rb` format migrate files.
726
+ CREATE TABLE IF NOT EXISTS posts (
727
+ ...
728
+ )
903
729
 
904
- These files are in `db/migrate`:
730
+ If the table already exists, `if_not_exists: false` (the default) raises an
731
+ exception whereas `if_not_exists: true` does nothing.
905
732
 
906
- * 1_valid_people_have_last_names.rb
907
- * 20150819202140_irreversible_migration.rb
908
- * 20150823202140_add_admin_flag_to_users.rb
909
- * 20150823202141_migration_tests.rb
910
- * 2_we_need_reminders.rb
911
- * 3_innocent_jointable.rb
733
+ *fatkodima*, *Stefan Kanev*
912
734
 
913
- Before:
735
+ * Defining an Enum as a Hash with blank key, or as an Array with a blank value, now raises an `ArgumentError`.
914
736
 
915
- $ bundle exec rake db:migrate:status
916
- ...
737
+ *Christophe Maximin*
917
738
 
918
- Status Migration ID Migration Name
919
- --------------------------------------------------
920
- up 001 ********** NO FILE **********
921
- up 002 ********** NO FILE **********
922
- up 003 ********** NO FILE **********
923
- up 20150819202140 Irreversible migration
924
- up 20150823202140 Add admin flag to users
925
- up 20150823202141 Migration tests
739
+ * Adds support for multiple databases to `rails db:schema:cache:dump` and `rails db:schema:cache:clear`.
926
740
 
927
- After:
741
+ *Gannon McGibbon*
928
742
 
929
- $ bundle exec rake db:migrate:status
930
- ...
743
+ * `update_columns` now correctly raises `ActiveModel::MissingAttributeError`
744
+ if the attribute does not exist.
931
745
 
932
- Status Migration ID Migration Name
933
- --------------------------------------------------
934
- up 001 Valid people have last names
935
- up 002 We need reminders
936
- up 003 Innocent jointable
937
- up 20150819202140 Irreversible migration
938
- up 20150823202140 Add admin flag to users
939
- up 20150823202141 Migration tests
746
+ *Sean Griffin*
940
747
 
941
- *Yuichiro Kaneko*
748
+ * Add support for hash and URL configs in database hash of `ActiveRecord::Base.connected_to`.
942
749
 
943
- * Define `ActiveRecord::Sanitization.sanitize_sql_for_order` and use it inside
944
- `preprocess_order_args`.
750
+ ````
751
+ User.connected_to(database: { writing: "postgres://foo" }) do
752
+ User.create!(name: "Gannon")
753
+ end
945
754
 
946
- *Yuichiro Kaneko*
755
+ config = { "adapter" => "sqlite3", "database" => "db/readonly.sqlite3" }
756
+ User.connected_to(database: { reading: config }) do
757
+ User.count
758
+ end
759
+ ````
947
760
 
948
- * Allow bigint with default nil for avoiding auto increment primary key.
761
+ *Gannon McGibbon*
949
762
 
950
- *Ryuta Kamizono*
763
+ * Support default expression for MySQL.
951
764
 
952
- * Remove `DEFAULT_CHARSET` and `DEFAULT_COLLATION` in `MySQLDatabaseTasks`.
765
+ MySQL 8.0.13 and higher supports default value to be a function or expression.
953
766
 
954
- We should omit the collation entirely rather than providing a default.
955
- Then the choice is the responsibility of the server and MySQL distribution.
767
+ https://dev.mysql.com/doc/refman/8.0/en/create-table.html
956
768
 
957
769
  *Ryuta Kamizono*
958
770
 
959
- * Alias `ActiveRecord::Relation#left_joins` to
960
- `ActiveRecord::Relation#left_outer_joins`.
961
-
962
- *Takashi Kokubun*
963
-
964
- * Use advisory locking to raise a `ConcurrentMigrationError` instead of
965
- attempting to migrate when another migration is currently running.
966
-
967
- *Sam Davies*
968
-
969
- * Added `ActiveRecord::Relation#left_outer_joins`.
970
-
971
- Example:
972
-
973
- User.left_outer_joins(:posts)
974
- # => SELECT "users".* FROM "users" LEFT OUTER JOIN "posts" ON
975
- "posts"."user_id" = "users"."id"
976
-
977
- *Florian Thomas*
978
-
979
- * Support passing an array to `order` for SQL parameter sanitization.
980
-
981
- *Aaron Suggs*
982
-
983
- * Avoid disabling errors on the PostgreSQL connection when enabling the
984
- `standard_conforming_strings` setting. Errors were previously disabled because
985
- the setting wasn't writable in Postgres 8.1 and didn't exist in earlier
986
- versions. Now Rails only supports Postgres 8.2+ we're fine to assume the
987
- setting exists. Disabling errors caused problems when using a connection
988
- pooling tool like PgBouncer because it's not guaranteed to have the same
989
- connection between calls to `execute` and it could leave the connection
990
- with errors disabled.
991
-
992
- Fixes #22101.
771
+ * Support expression indexes for MySQL.
993
772
 
994
- *Harry Marr*
773
+ MySQL 8.0.13 and higher supports functional key parts that index
774
+ expression values rather than column or column prefix values.
995
775
 
996
- * Set `scope.reordering_value` to `true` if `:reordering`-values are specified.
776
+ https://dev.mysql.com/doc/refman/8.0/en/create-index.html
997
777
 
998
- Fixes #21886.
999
-
1000
- *Hiroaki Izu*
1001
-
1002
- * Add support for bidirectional destroy dependencies.
1003
-
1004
- Fixes #13609.
1005
-
1006
- Example:
1007
-
1008
- class Content < ActiveRecord::Base
1009
- has_one :position, dependent: :destroy
1010
- end
1011
-
1012
- class Position < ActiveRecord::Base
1013
- belongs_to :content, dependent: :destroy
1014
- end
1015
-
1016
- *Seb Jacobs*
778
+ *Ryuta Kamizono*
1017
779
 
1018
- * Includes HABTM returns correct size now. It's caused by the join dependency
1019
- only instantiates one HABTM object because the join table hasn't a primary key.
780
+ * Fix collection cache key with limit and custom select to avoid ambiguous timestamp column error.
1020
781
 
1021
- Fixes #16032.
782
+ Fixes #33056.
1022
783
 
1023
- Examples:
784
+ *Federico Martinez*
1024
785
 
1025
- before:
786
+ * Add basic API for connection switching to support multiple databases.
1026
787
 
1027
- Project.first.salaried_developers.size # => 3
1028
- Project.includes(:salaried_developers).first.salaried_developers.size # => 1
788
+ 1) Adds a `connects_to` method for models to connect to multiple databases. Example:
1029
789
 
1030
- after:
790
+ ```
791
+ class AnimalsModel < ApplicationRecord
792
+ self.abstract_class = true
1031
793
 
1032
- Project.first.salaried_developers.size # => 3
1033
- Project.includes(:salaried_developers).first.salaried_developers.size # => 3
794
+ connects_to database: { writing: :animals_primary, reading: :animals_replica }
795
+ end
1034
796
 
1035
- *Bigxiang*
797
+ class Dog < AnimalsModel
798
+ # connected to both the animals_primary db for writing and the animals_replica for reading
799
+ end
800
+ ```
1036
801
 
1037
- * Add option to index errors in nested attributes.
802
+ 2) Adds a `connected_to` block method for switching connection roles or connecting to
803
+ a database that the model didn't connect to. Connecting to the database in this block is
804
+ useful when you have another defined connection, for example `slow_replica` that you don't
805
+ want to connect to by default but need in the console, or a specific code block.
1038
806
 
1039
- For models which have nested attributes, errors within those models will
1040
- now be indexed if `:index_errors` option is set to true when defining a
1041
- `has_many` relationship or by setting the configuration option
1042
- `config.active_record.index_nested_attribute_errors` to true.
807
+ ```
808
+ ActiveRecord::Base.connected_to(role: :reading) do
809
+ Dog.first # finds dog from replica connected to AnimalsBase
810
+ Book.first # doesn't have a reading connection, will raise an error
811
+ end
812
+ ```
1043
813
 
1044
- Example:
814
+ ```
815
+ ActiveRecord::Base.connected_to(database: :slow_replica) do
816
+ 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
817
+ end
818
+ ```
1045
819
 
1046
- class Guitar < ActiveRecord::Base
1047
- has_many :tuning_pegs, index_errors: true
1048
- accepts_nested_attributes_for :tuning_pegs
1049
- end
820
+ *Eileen M. Uchitelle*
1050
821
 
1051
- class TuningPeg < ActiveRecord::Base
1052
- belongs_to :guitar
1053
- validates_numericality_of :pitch
1054
- end
822
+ * Enum raises on invalid definition values
1055
823
 
1056
- # Before
1057
- guitar.errors["tuning_pegs.pitch"] = ["is not a number"]
824
+ When defining a Hash enum it can be easy to use `[]` instead of `{}`. This
825
+ commit checks that only valid definition values are provided, those can
826
+ be a Hash, an array of Symbols or an array of Strings. Otherwise it
827
+ raises an `ArgumentError`.
1058
828
 
1059
- # After
1060
- guitar.errors["tuning_pegs[1].pitch"] = ["is not a number"]
829
+ Fixes #33961
1061
830
 
1062
- *Michael Probber*, *Terence Sun*
831
+ *Alberto Almagro*
1063
832
 
1064
- * Exit with non-zero status for failed database rake tasks.
833
+ * Reloading associations now clears the Query Cache like `Persistence#reload` does.
1065
834
 
1066
- *Jay Hayes*
835
+ ```
836
+ class Post < ActiveRecord::Base
837
+ has_one :category
838
+ belongs_to :author
839
+ has_many :comments
840
+ end
1067
841
 
1068
- * Queries such as `Computer.joins(:monitor).group(:status).count` will now be
1069
- interpreted as `Computer.joins(:monitor).group('computers.status').count`
1070
- so that when `Computer` and `Monitor` have both `status` columns we don't
1071
- have conflicts in projection.
842
+ # Each of the following will now clear the query cache.
843
+ post.reload_category
844
+ post.reload_author
845
+ post.comments.reload
846
+ ```
1072
847
 
1073
- *Rafael Sales*
848
+ *Christophe Maximin*
1074
849
 
1075
- * Add ability to default to `uuid` as primary key when generating database migrations.
850
+ * Added `index` option for `change_table` migration helpers.
851
+ With this change you can create indexes while adding new
852
+ columns into the existing tables.
1076
853
 
1077
854
  Example:
1078
855
 
1079
- config.generators do |g|
1080
- g.orm :active_record, primary_key_type: :uuid
856
+ change_table(:languages) do |t|
857
+ t.string :country_code, index: true
1081
858
  end
1082
859
 
1083
- *Jon McCartie*
1084
-
1085
- * Don't cache arguments in `#find_by` if they are an `ActiveRecord::Relation`.
1086
-
1087
- Fixes #20817.
1088
-
1089
- *Hiroaki Izu*
1090
-
1091
- * Qualify column name inserted by `group` in calculation.
1092
-
1093
- Giving `group` an unqualified column name now works, even if the relation
1094
- has `JOIN` with another table which also has a column of the name.
1095
-
1096
- *Soutaro Matsumoto*
1097
-
1098
- * Don't cache prepared statements containing an IN clause or a SQL literal, as
1099
- these queries will change often and are unlikely to have a cache hit.
1100
-
1101
- *Sean Griffin*
1102
-
1103
- * Fix `rewhere` in a `has_many` association.
1104
-
1105
- Fixes #21955.
1106
-
1107
- *Josh Branchaud*, *Kal*
1108
-
1109
- * `where` raises ArgumentError on unsupported types.
1110
-
1111
- Fixes #20473.
1112
-
1113
- *Jake Worth*
1114
-
1115
- * Add an immutable string type to help reduce memory usage for apps which do
1116
- not need mutation detection on strings.
1117
-
1118
- *Sean Griffin*
1119
-
1120
- * Give `ActiveRecord::Relation#update` its own deprecation warning when
1121
- passed an `ActiveRecord::Base` instance.
1122
-
1123
- Fixes #21945.
1124
-
1125
- *Ted Johansson*
1126
-
1127
- * Make it possible to pass `:to_table` when adding a foreign key through
1128
- `add_reference`.
1129
-
1130
- Fixes #21563.
860
+ *Mehmet Emin İNAÇ*
1131
861
 
1132
- *Yves Senn*
862
+ * Fix `transaction` reverting for migrations.
1133
863
 
1134
- * No longer pass deprecated option `-i` to `pg_dump`.
864
+ Before: Commands inside a `transaction` in a reverted migration ran uninverted.
865
+ Now: This change fixes that by reverting commands inside `transaction` block.
1135
866
 
1136
- *Paul Sadauskas*
867
+ *fatkodima*, *David Verhasselt*
1137
868
 
1138
- * Concurrent `AR::Base#increment!` and `#decrement!` on the same record
1139
- are all reflected in the database rather than overwriting each other.
869
+ * Raise an error instead of scanning the filesystem root when `fixture_path` is blank.
1140
870
 
1141
- *Bogdan Gusiev*
871
+ *Gannon McGibbon*, *Max Albrecht*
1142
872
 
1143
- * Avoid leaking the first relation we call `first` on, per model.
873
+ * Allow `ActiveRecord::Base.configurations=` to be set with a symbolized hash.
1144
874
 
1145
- Fixes #21921.
875
+ *Gannon McGibbon*
1146
876
 
1147
- *Matthew Draper*, *Jean Boussier*
877
+ * Don't update counter cache unless the record is actually saved.
1148
878
 
1149
- * Remove unused `pk_and_sequence_for` in `AbstractMysqlAdapter`.
879
+ Fixes #31493, #33113, #33117.
1150
880
 
1151
881
  *Ryuta Kamizono*
1152
882
 
1153
- * Allow fixtures files to set the model class in the YAML file itself.
1154
-
1155
- To load the fixtures file `accounts.yml` as the `User` model, use:
1156
-
1157
- _fixture:
1158
- model_class: User
1159
- david:
1160
- name: David
1161
-
1162
- Fixes #9516.
1163
-
1164
- *Roque Pinel*
1165
-
1166
- * Don't require a database connection to load a class which uses acceptance
1167
- validations.
1168
-
1169
- *Sean Griffin*
1170
-
1171
- * Correctly apply `unscope` when preloading through associations.
883
+ * Deprecate `ActiveRecord::Result#to_hash` in favor of `ActiveRecord::Result#to_a`.
1172
884
 
1173
- *Jimmy Bourassa*
885
+ *Gannon McGibbon*, *Kevin Cheng*
1174
886
 
1175
- * Fixed taking precision into count when assigning a value to timestamp attribute.
887
+ * SQLite3 adapter supports expression indexes.
1176
888
 
1177
- Timestamp column can have less precision than ruby timestamp
1178
- In result in how big a fraction of a second can be stored in the
1179
- database.
889
+ ```
890
+ create_table :users do |t|
891
+ t.string :email
892
+ end
1180
893
 
894
+ add_index :users, 'lower(email)', name: 'index_users_on_email', unique: true
895
+ ```
1181
896
 
1182
- m = Model.create!
1183
- m.created_at.usec == m.reload.created_at.usec # => false
1184
- # due to different precision in Time.now and database column
897
+ *Gray Kemmey*
1185
898
 
1186
- If the precision is low enough, (mysql default is 0, so it is always low
1187
- enough by default) the value changes when model is reloaded from the
1188
- database. This patch fixes that issue ensuring that any timestamp
1189
- assigned as an attribute is converted to column precision under the
1190
- attribute.
899
+ * Allow subclasses to redefine autosave callbacks for associated records.
1191
900
 
1192
- *Bogdan Gusiev*
1193
-
1194
- * Introduce `connection.data_sources` and `connection.data_source_exists?`.
1195
- These methods determine what relations can be used to back Active Record
1196
- models (usually tables and views).
1197
-
1198
- Also deprecate `SchemaCache#tables`, `SchemaCache#table_exists?` and
1199
- `SchemaCache#clear_table_cache!` in favor of their new data source
1200
- counterparts.
1201
-
1202
- *Yves Senn*, *Matthew Draper*
901
+ Fixes #33305.
1203
902
 
1204
- * Add `ActiveRecord::Base.ignored_columns` to make some columns
1205
- invisible from Active Record.
903
+ *Andrey Subbota*
1206
904
 
1207
- *Jean Boussier*
905
+ * Bump minimum MySQL version to 5.5.8.
1208
906
 
1209
- * `ActiveRecord::Tasks::MySQLDatabaseTasks` fails if shellout to
1210
- mysql commands (like `mysqldump`) is not successful.
907
+ *Yasuo Honda*
1211
908
 
1212
- *Steve Mitchell*
909
+ * Use MySQL utf8mb4 character set by default.
1213
910
 
1214
- * Ensure `select` quotes aliased attributes, even when using `from`.
911
+ `utf8mb4` character set with 4-Byte encoding supports supplementary characters including emoji.
912
+ The previous default 3-Byte encoding character set `utf8` is not enough to support them.
1215
913
 
1216
- Fixes #21488.
914
+ *Yasuo Honda*
1217
915
 
1218
- *Sean Griffin*, *@johanlunds*
916
+ * Fix duplicated record creation when using nested attributes with `create_with`.
1219
917
 
1220
- * MySQL: support `unsigned` numeric data types.
1221
-
1222
- Example:
1223
-
1224
- create_table :foos do |t|
1225
- t.unsigned_integer :quantity
1226
- t.unsigned_bigint :total
1227
- t.unsigned_float :percentage
1228
- t.unsigned_decimal :price, precision: 10, scale: 2
1229
- end
918
+ *Darwin Wu*
1230
919
 
1231
- The `unsigned: true` option may be used for the primary key:
920
+ * Configuration item `config.filter_parameters` could also filter out
921
+ sensitive values of database columns when calling `#inspect`.
922
+ We also added `ActiveRecord::Base::filter_attributes`/`=` in order to
923
+ specify sensitive attributes to specific model.
1232
924
 
1233
- create_table :foos, id: :bigint, unsigned: true do |t|
1234
-
1235
- end
925
+ ```
926
+ Rails.application.config.filter_parameters += [:credit_card_number, /phone/]
927
+ Account.last.inspect # => #<Account id: 123, name: "DHH", credit_card_number: [FILTERED], telephone_number: [FILTERED] ...>
928
+ SecureAccount.filter_attributes += [:name]
929
+ SecureAccount.last.inspect # => #<SecureAccount id: 42, name: [FILTERED], credit_card_number: [FILTERED] ...>
930
+ ```
1236
931
 
1237
- *Ryuta Kamizono*
932
+ *Zhang Kang*, *Yoshiyuki Kinjo*
1238
933
 
1239
- * Add `#views` and `#view_exists?` methods on connection adapters.
934
+ * Deprecate `column_name_length`, `table_name_length`, `columns_per_table`,
935
+ `indexes_per_table`, `columns_per_multicolumn_index`, `sql_query_length`,
936
+ and `joins_per_query` methods in `DatabaseLimits`.
1240
937
 
1241
938
  *Ryuta Kamizono*
1242
939
 
1243
- * Correctly dump composite primary key.
1244
-
1245
- Example:
1246
-
1247
- create_table :barcodes, primary_key: ["region", "code"] do |t|
1248
- t.string :region
1249
- t.integer :code
1250
- end
940
+ * `ActiveRecord::Base.configurations` now returns an object.
1251
941
 
1252
- *Ryuta Kamizono*
942
+ `ActiveRecord::Base.configurations` used to return a hash, but this
943
+ is an inflexible data model. In order to improve multiple-database
944
+ handling in Rails, we've changed this to return an object. Some methods
945
+ are provided to make the object behave hash-like in order to ease the
946
+ transition process. Since most applications don't manipulate the hash
947
+ we've decided to add backwards-compatible functionality that will throw
948
+ a deprecation warning if used, however calling `ActiveRecord::Base.configurations`
949
+ will use the new version internally and externally.
1253
950
 
1254
- * Lookup the attribute name for `restrict_with_error` messages on the
1255
- model class that defines the association.
951
+ For example, the following `database.yml`:
1256
952
 
1257
- *kuboon*, *Ronak Jangir*
953
+ ```
954
+ development:
955
+ adapter: sqlite3
956
+ database: db/development.sqlite3
957
+ ```
1258
958
 
1259
- * Correct query for PostgreSQL 8.2 compatibility.
959
+ Used to become a hash:
1260
960
 
1261
- *Ben Murphy*, *Matthew Draper*
961
+ ```
962
+ { "development" => { "adapter" => "sqlite3", "database" => "db/development.sqlite3" } }
963
+ ```
1262
964
 
1263
- * `bin/rails db:migrate` uses
1264
- `ActiveRecord::Tasks::DatabaseTasks.migrations_paths` instead of
1265
- `Migrator.migrations_paths`.
965
+ Is now converted into the following object:
1266
966
 
1267
- *Tobias Bielohlawek*
967
+ ```
968
+ #<ActiveRecord::DatabaseConfigurations:0x00007fd1acbdf800 @configurations=[
969
+ #<ActiveRecord::DatabaseConfigurations::HashConfig:0x00007fd1acbded10 @env_name="development",
970
+ @spec_name="primary", @config={"adapter"=>"sqlite3", "database"=>"db/development.sqlite3"}>
971
+ ]
972
+ ```
1268
973
 
1269
- * Support dropping indexes concurrently in PostgreSQL.
974
+ Iterating over the database configurations has also changed. Instead of
975
+ calling hash methods on the `configurations` hash directly, a new method `configs_for` has
976
+ been provided that allows you to select the correct configuration. `env_name` and
977
+ `spec_name` arguments are optional. For example, these return an array of
978
+ database config objects for the requested environment and a single database config object
979
+ will be returned for the requested environment and specification name respectively.
1270
980
 
1271
- See http://www.postgresql.org/docs/9.4/static/sql-dropindex.html for more
1272
- details.
981
+ ```
982
+ ActiveRecord::Base.configurations.configs_for(env_name: "development")
983
+ ActiveRecord::Base.configurations.configs_for(env_name: "development", spec_name: "primary")
984
+ ```
1273
985
 
1274
- *Grey Baker*
986
+ *Eileen M. Uchitelle*, *Aaron Patterson*
1275
987
 
1276
- * Deprecate passing conditions to `ActiveRecord::Relation#delete_all`
1277
- and `ActiveRecord::Relation#destroy_all`.
988
+ * Add database configuration to disable advisory locks.
1278
989
 
1279
- *Wojciech Wnętrzak*
990
+ ```
991
+ production:
992
+ adapter: postgresql
993
+ advisory_locks: false
994
+ ```
1280
995
 
1281
- * Instantiating an AR model with `ActionController::Parameters` now raises
1282
- an `ActiveModel::ForbiddenAttributesError` if the parameters include a
1283
- `type` field that has not been explicitly permitted. Previously, the
1284
- `type` field was simply ignored in the same situation.
996
+ *Guo Xiang*
1285
997
 
1286
- *Prem Sichanugrist*
998
+ * SQLite3 adapter `alter_table` method restores foreign keys.
1287
999
 
1288
- * PostgreSQL, `create_schema`, `drop_schema` and `rename_table` now quote
1289
- schema names.
1000
+ *Yasuo Honda*
1290
1001
 
1291
- Fixes #21418.
1002
+ * Allow `:to_table` option to `invert_remove_foreign_key`.
1292
1003
 
1293
1004
  Example:
1294
1005
 
1295
- create_schema("my.schema")
1296
- # CREATE SCHEMA "my.schema";
1006
+ remove_foreign_key :accounts, to_table: :owners
1297
1007
 
1298
- *Yves Senn*
1008
+ *Nikolay Epifanov*, *Rich Chen*
1299
1009
 
1300
- * PostgreSQL, add `:if_exists` option to `#drop_schema`. This makes it
1301
- possible to drop a schema that might exist without raising an exception if
1302
- it doesn't.
1010
+ * Add environment & load_config dependency to `bin/rake db:seed` to enable
1011
+ seed load in environments without Rails and custom DB configuration
1303
1012
 
1304
- *Yves Senn*
1305
-
1306
- * Only try to nullify has_one target association if the record is persisted.
1307
-
1308
- Fixes #21223.
1309
-
1310
- *Agis Anastasopoulos*
1311
-
1312
- * Uniqueness validator raises descriptive error when running on a persisted
1313
- record without primary key.
1314
-
1315
- Fixes #21304.
1316
-
1317
- *Yves Senn*
1013
+ *Tobias Bielohlawek*
1318
1014
 
1319
- * Add a native JSON data type support in MySQL.
1015
+ * Fix default value for mysql time types with specified precision.
1320
1016
 
1321
- Example:
1017
+ *Nikolay Kondratyev*
1322
1018
 
1323
- create_table :json_data_type do |t|
1324
- t.json :settings
1325
- end
1019
+ * Fix `touch` option to behave consistently with `Persistence#touch` method.
1326
1020
 
1327
1021
  *Ryuta Kamizono*
1328
1022
 
1329
- * Descriptive error message when fixtures contain a missing column.
1330
-
1331
- Fixes #21201.
1023
+ * Migrations raise when duplicate column definition.
1332
1024
 
1333
- *Yves Senn*
1025
+ Fixes #33024.
1334
1026
 
1335
- * `ActiveRecord::Tasks::PostgreSQLDatabaseTasks` fail if shellout to
1336
- postgresql commands (like `pg_dump`) is not successful.
1027
+ *Federico Martinez*
1337
1028
 
1338
- *Bryan Paxton*, *Nate Berkopec*
1029
+ * Bump minimum SQLite version to 3.8
1339
1030
 
1340
- * Add `ActiveRecord::Relation#in_batches` to work with records and relations
1341
- in batches.
1031
+ *Yasuo Honda*
1342
1032
 
1343
- Available options are `of` (batch size), `load`, `start`, and `finish`.
1033
+ * Fix parent record should not get saved with duplicate children records.
1344
1034
 
1345
- Examples:
1035
+ Fixes #32940.
1346
1036
 
1347
- Person.in_batches.each_record(&:party_all_night!)
1348
- Person.in_batches.update_all(awesome: true)
1349
- Person.in_batches.delete_all
1350
- Person.in_batches.each do |relation|
1351
- relation.delete_all
1352
- sleep 10 # Throttles the delete queries
1353
- end
1037
+ *Santosh Wadghule*
1354
1038
 
1355
- Fixes #20933.
1039
+ * Fix logic on disabling commit callbacks so they are not called unexpectedly when errors occur.
1356
1040
 
1357
- *Sina Siadat*
1041
+ *Brian Durand*
1358
1042
 
1359
- * Added methods for PostgreSQL geometric data types to use in migrations.
1043
+ * Ensure `Associations::CollectionAssociation#size` and `Associations::CollectionAssociation#empty?`
1044
+ use loaded association ids if present.
1360
1045
 
1361
- Example:
1046
+ *Graham Turner*
1362
1047
 
1363
- create_table :foo do |t|
1364
- t.line :foo_line
1365
- t.lseg :foo_lseg
1366
- t.box :foo_box
1367
- t.path :foo_path
1368
- t.polygon :foo_polygon
1369
- t.circle :foo_circle
1370
- end
1048
+ * Add support to preload associations of polymorphic associations when not all the records have the requested associations.
1371
1049
 
1372
- *Mehmet Emin İNAÇ*
1050
+ *Dana Sherson*
1373
1051
 
1374
- * Add `cache_key` to `ActiveRecord::Relation`.
1052
+ * Add `touch_all` method to `ActiveRecord::Relation`.
1375
1053
 
1376
1054
  Example:
1377
1055
 
1378
- @users = User.where("name like ?", "%Alberto%")
1379
- @users.cache_key
1380
- # => "/users/query-5942b155a43b139f2471b872ac54251f-3-20150714212107656125000"
1381
-
1382
- *Alberto Fernández-Capel*
1383
-
1384
- * Properly allow uniqueness validations on primary keys.
1056
+ Person.where(name: "David").touch_all(time: Time.new(2020, 5, 16, 0, 0, 0))
1385
1057
 
1386
- Fixes #20966.
1058
+ *fatkodima*, *duggiefresh*
1387
1059
 
1388
- *Sean Griffin*, *presskey*
1389
-
1390
- * Don't raise an error if an association failed to destroy when `destroy` was
1391
- called on the parent (as opposed to `destroy!`).
1392
-
1393
- Fixes #20991.
1394
-
1395
- *Sean Griffin*
1396
-
1397
- * `ActiveRecord::RecordNotFound` modified to store model name, primary_key and
1398
- id of the caller model. It allows the catcher of this exception to make
1399
- a better decision to what to do with it.
1400
-
1401
- Example:
1402
-
1403
- class SomeAbstractController < ActionController::Base
1404
- rescue_from ActiveRecord::RecordNotFound, with: :redirect_to_404
1405
-
1406
- private def redirect_to_404(e)
1407
- return redirect_to(posts_url) if e.model == 'Post'
1408
- raise
1409
- end
1410
- end
1411
-
1412
- *Sameer Rahmani*
1413
-
1414
- * Deprecate the keys for association `restrict_dependent_destroy` errors in favor
1415
- of new key names.
1416
-
1417
- Previously `has_one` and `has_many` associations were using the
1418
- `one` and `many` keys respectively. Both of these keys have special
1419
- meaning in I18n (they are considered to be pluralizations) so by
1420
- renaming them to `has_one` and `has_many` we make the messages more explicit
1421
- and most importantly they don't clash with linguistical systems that need to
1422
- validate translation keys (and their pluralizations).
1423
-
1424
- The `:'restrict_dependent_destroy.one'` key should be replaced with
1425
- `:'restrict_dependent_destroy.has_one'`, and `:'restrict_dependent_destroy.many'`
1426
- with `:'restrict_dependent_destroy.has_many'`.
1427
-
1428
- *Roque Pinel*, *Christopher Dell*
1429
-
1430
- * Fix state being carried over from previous transaction.
1431
-
1432
- Considering the following example where `name` is a required attribute.
1433
- Before we had `new_record?` returning `true` for a persisted record:
1434
-
1435
- author = Author.create! name: 'foo'
1436
- author.name = nil
1437
- author.save # => false
1438
- author.new_record? # => true
1439
-
1440
- Fixes #20824.
1441
-
1442
- *Roque Pinel*
1443
-
1444
- * Correctly ignore `mark_for_destruction` when `autosave` isn't set to `true`
1445
- when validating associations.
1446
-
1447
- Fixes #20882.
1448
-
1449
- *Sean Griffin*
1450
-
1451
- * Fix a bug where counter_cache doesn't always work with polymorphic
1452
- relations.
1453
-
1454
- Fixes #16407.
1455
-
1456
- *Stefan Kanev*, *Sean Griffin*
1457
-
1458
- * Ensure that cyclic associations with autosave don't cause duplicate errors
1459
- to be added to the parent record.
1460
-
1461
- Fixes #20874.
1462
-
1463
- *Sean Griffin*
1464
-
1465
- * Ensure that `ActionController::Parameters` can still be passed to nested
1466
- attributes.
1467
-
1468
- Fixes #20922.
1469
-
1470
- *Sean Griffin*
1471
-
1472
- * Deprecate force association reload by passing a truthy argument to
1473
- association method.
1474
-
1475
- For collection association, you can call `#reload` on association proxy to
1476
- force a reload:
1477
-
1478
- @user.posts.reload # Instead of @user.posts(true)
1479
-
1480
- For singular association, you can call `#reload` on the parent object to
1481
- clear its association cache then call the association method:
1482
-
1483
- @user.reload.profile # Instead of @user.profile(true)
1484
-
1485
- Passing a truthy argument to force association to reload will be removed in
1486
- Rails 5.1.
1487
-
1488
- *Prem Sichanugrist*
1489
-
1490
- * Replaced `ActiveSupport::Concurrency::Latch` with `Concurrent::CountDownLatch`
1491
- from the concurrent-ruby gem.
1492
-
1493
- *Jerry D'Antonio*
1494
-
1495
- * Fix through associations using scopes having the scope merged multiple
1496
- times.
1497
-
1498
- Fixes #20721.
1499
- Fixes #20727.
1500
-
1501
- *Sean Griffin*
1502
-
1503
- * `ActiveRecord::Base.dump_schema_after_migration` applies migration tasks
1504
- other than `db:migrate`. (eg. `db:rollback`, `db:migrate:dup`, ...)
1505
-
1506
- Fixes #20743.
1507
-
1508
- *Yves Senn*
1509
-
1510
- * Add alternate syntax to make `change_column_default` reversible.
1511
-
1512
- User can pass in `:from` and `:to` to make `change_column_default` command
1513
- become reversible.
1514
-
1515
- Example:
1516
-
1517
- change_column_default :posts, :status, from: nil, to: "draft"
1518
- change_column_default :users, :authorized, from: true, to: false
1519
-
1520
- *Prem Sichanugrist*
1521
-
1522
- * Prevent error when using `force_reload: true` on an unassigned polymorphic
1523
- belongs_to association.
1524
-
1525
- Fixes #20426.
1526
-
1527
- *James Dabbs*
1528
-
1529
- * Correctly raise `ActiveRecord::AssociationTypeMismatch` when assigning
1530
- a wrong type to a namespaced association.
1531
-
1532
- Fixes #20545.
1533
-
1534
- *Diego Carrion*
1535
-
1536
- * `validates_absence_of` respects `marked_for_destruction?`.
1537
-
1538
- Fixes #20449.
1539
-
1540
- *Yves Senn*
1541
-
1542
- * Include the `Enumerable` module in `ActiveRecord::Relation`
1543
-
1544
- *Sean Griffin*, *bogdan*
1545
-
1546
- * Use `Enumerable#sum` in `ActiveRecord::Relation` if a block is given.
1547
-
1548
- *Sean Griffin*
1549
-
1550
- * Let `WITH` queries (Common Table Expressions) be explainable.
1551
-
1552
- *Vladimir Kochnev*
1553
-
1554
- * Make `remove_index :table, :column` reversible.
1555
-
1556
- *Yves Senn*
1557
-
1558
- * Fixed an error which would occur in dirty checking when calling
1559
- `update_attributes` from a getter.
1560
-
1561
- Fixes #20531.
1562
-
1563
- *Sean Griffin*
1564
-
1565
- * Make `remove_foreign_key` reversible. Any foreign key options must be
1566
- specified, similar to `remove_column`.
1567
-
1568
- *Aster Ryan*
1569
-
1570
- * Add `:_prefix` and `:_suffix` options to `enum` definition.
1571
-
1572
- Fixes #17511, #17415.
1573
-
1574
- *Igor Kapkov*
1575
-
1576
- * Correctly handle decimal arrays with defaults in the schema dumper.
1577
-
1578
- Fixes #20515.
1579
-
1580
- *Sean Griffin*, *jmondo*
1581
-
1582
- * Deprecate the PostgreSQL `:point` type in favor of a new one which will return
1583
- `Point` objects instead of an `Array`
1584
-
1585
- *Sean Griffin*
1586
-
1587
- * Ensure symbols passed to `ActiveRecord::Relation#select` are always treated
1588
- as columns.
1589
-
1590
- Fixes #20360.
1591
-
1592
- *Sean Griffin*
1593
-
1594
- * Do not set `sql_mode` if `strict: :default` is specified.
1595
-
1596
- # config/database.yml
1597
- production:
1598
- adapter: mysql2
1599
- database: foo_prod
1600
- user: foo
1601
- strict: :default
1602
-
1603
- *Ryuta Kamizono*
1604
-
1605
- * Allow proc defaults to be passed to the attributes API. See documentation
1606
- for examples.
1607
-
1608
- *Sean Griffin*, *Kir Shatrov*
1609
-
1610
- * SQLite: `:collation` support for string and text columns.
1611
-
1612
- Example:
1613
-
1614
- create_table :foo do |t|
1615
- t.string :string_nocase, collation: 'NOCASE'
1616
- t.text :text_rtrim, collation: 'RTRIM'
1617
- end
1618
-
1619
- add_column :foo, :title, :string, collation: 'RTRIM'
1620
-
1621
- change_column :foo, :title, :string, collation: 'NOCASE'
1622
-
1623
- *Akshay Vishnoi*
1624
-
1625
- * Allow the use of symbols or strings to specify enum values in test
1626
- fixtures:
1627
-
1628
- awdr:
1629
- title: "Agile Web Development with Rails"
1630
- status: :proposed
1631
-
1632
- *George Claghorn*
1633
-
1634
- * Clear query cache when `ActiveRecord::Base#reload` is called.
1635
-
1636
- *Shane Hender, Pierre Nespo*
1637
-
1638
- * Include stored procedures and function on the MySQL structure dump.
1639
-
1640
- *Jonathan Worek*
1641
-
1642
- * Pass `:extend` option for `has_and_belongs_to_many` associations to the
1643
- underlying `has_many :through`.
1644
-
1645
- *Jaehyun Shin*
1646
-
1647
- * Deprecate `Relation#uniq` use `Relation#distinct` instead.
1648
-
1649
- See #9683.
1650
-
1651
- *Yves Senn*
1652
-
1653
- * Allow single table inheritance instantiation to work when storing
1654
- demodulized class names.
1655
-
1656
- *Alex Robbin*
1657
-
1658
- * Correctly pass MySQL options when using `structure_dump` or
1659
- `structure_load`.
1660
-
1661
- Specifically, it fixes an issue when using SSL authentication.
1662
-
1663
- *Alex Coomans*
1664
-
1665
- * Correctly dump `:options` on `create_table` for MySQL.
1666
-
1667
- *Ryuta Kamizono*
1668
-
1669
- * PostgreSQL: `:collation` support for string and text columns.
1670
-
1671
- Example:
1672
-
1673
- create_table :foos do |t|
1674
- t.string :string_en, collation: 'en_US.UTF-8'
1675
- t.text :text_ja, collation: 'ja_JP.UTF-8'
1676
- end
1677
-
1678
- *Ryuta Kamizono*
1679
-
1680
- * Remove `ActiveRecord::Serialization::XmlSerializer` from core.
1681
-
1682
- *Zachary Scott*
1683
-
1684
- * Make `unscope` aware of "less than" and "greater than" conditions.
1685
-
1686
- *TAKAHASHI Kazuaki*
1687
-
1688
- * `find_by` and `find_by!` raise `ArgumentError` when called without
1689
- arguments.
1690
-
1691
- *Kohei Suzuki*
1692
-
1693
- * Revert behavior of `db:schema:load` back to loading the full
1694
- environment. This ensures that initializers are run.
1695
-
1696
- Fixes #19545.
1697
-
1698
- *Yves Senn*
1699
-
1700
- * Fix missing index when using `timestamps` with the `index` option.
1701
-
1702
- The `index` option used with `timestamps` should be passed to both
1703
- `column` definitions for `created_at` and `updated_at` rather than just
1704
- the first.
1705
-
1706
- *Paul Mucur*
1707
-
1708
- * Rename `:class` to `:anonymous_class` in association options.
1709
-
1710
- Fixes #19659.
1711
-
1712
- *Andrew White*
1713
-
1714
- * Autosave existing records on a has many through association when the parent
1715
- is new.
1716
-
1717
- Fixes #19782.
1718
-
1719
- *Sean Griffin*
1720
-
1721
- * Fixed a bug where uniqueness validations would error on out of range values,
1722
- even if an validation should have prevented it from hitting the database.
1723
-
1724
- *Andrey Voronkov*
1725
-
1726
- * MySQL: `:charset` and `:collation` support for string and text columns.
1727
-
1728
- Example:
1729
-
1730
- create_table :foos do |t|
1731
- t.string :string_utf8_bin, charset: 'utf8', collation: 'utf8_bin'
1732
- t.text :text_ascii, charset: 'ascii'
1733
- end
1734
-
1735
- *Ryuta Kamizono*
1736
-
1737
- * Foreign key related methods in the migration DSL respect
1738
- `ActiveRecord::Base.pluralize_table_names = false`.
1739
-
1740
- Fixes #19643.
1741
-
1742
- *Mehmet Emin İNAÇ*
1743
-
1744
- * Reduce memory usage from loading types on PostgreSQL.
1745
-
1746
- Fixes #19578.
1747
-
1748
- *Sean Griffin*
1749
-
1750
- * Add `config.active_record.warn_on_records_fetched_greater_than` option.
1751
-
1752
- When set to an integer, a warning will be logged whenever a result set
1753
- larger than the specified size is returned by a query.
1754
-
1755
- Fixes #16463.
1756
-
1757
- *Jason Nochlin*
1758
-
1759
- * Ignore `.psqlrc` when loading database structure.
1760
-
1761
- *Jason Weathered*
1762
-
1763
- * Fix referencing wrong table aliases while joining tables of has many through
1764
- association (only when calling calculation methods).
1765
-
1766
- Fixes #19276.
1767
-
1768
- *pinglamb*
1769
-
1770
- * Correctly persist a serialized attribute that has been returned to
1771
- its default value by an in-place modification.
1772
-
1773
- Fixes #19467.
1774
-
1775
- *Matthew Draper*
1776
-
1777
- * Fix generating the schema file when using PostgreSQL `BigInt[]` data type.
1778
- Previously the `limit: 8` was not coming through, and this caused it to
1779
- become `Int[]` data type after rebuilding from the schema.
1780
-
1781
- Fixes #19420.
1782
-
1783
- *Jake Waller*
1784
-
1785
- * Reuse the `CollectionAssociation#reader` cache when the foreign key is
1786
- available prior to save.
1787
-
1788
- *Ben Woosley*
1789
-
1790
- * Add `config.active_record.dump_schemas` to fix `db:structure:dump`
1791
- when using schema_search_path and PostgreSQL extensions.
1792
-
1793
- Fixes #17157.
1794
-
1795
- *Ryan Wallace*
1796
-
1797
- * Renaming `use_transactional_fixtures` to `use_transactional_tests` for clarity.
1798
-
1799
- Fixes #18864.
1800
-
1801
- *Brandon Weiss*
1802
-
1803
- * Increase pg gem version requirement to `~> 0.18`. Earlier versions of the
1804
- pg gem are known to have problems with Ruby 2.2.
1805
-
1806
- *Matt Brictson*
1807
-
1808
- * Correctly dump `serial` and `bigserial`.
1809
-
1810
- *Ryuta Kamizono*
1811
-
1812
- * Fix default `format` value in `ActiveRecord::Tasks::DatabaseTasks#schema_file`.
1813
-
1814
- *James Cox*
1815
-
1816
- * Don't enroll records in the transaction if they don't have commit callbacks.
1817
- This was causing a memory leak when creating many records inside a transaction.
1818
-
1819
- Fixes #15549.
1820
-
1821
- *Will Bryant*, *Aaron Patterson*
1822
-
1823
- * Correctly create through records when created on a has many through
1824
- association when using `where`.
1825
-
1826
- Fixes #19073.
1827
-
1828
- *Sean Griffin*
1829
-
1830
- * Add `SchemaMigration.create_table` support for any unicode charsets with MySQL.
1831
-
1832
- *Ryuta Kamizono*
1833
-
1834
- * PostgreSQL no longer disables user triggers if system triggers can't be
1835
- disabled. Disabling user triggers does not fulfill what the method promises.
1836
- Rails currently requires superuser privileges for this method.
1837
-
1838
- If you absolutely rely on this behavior, consider patching
1839
- `disable_referential_integrity`.
1840
-
1841
- *Yves Senn*
1842
-
1843
- * Restore aborted transaction state when `disable_referential_integrity` fails
1844
- due to missing permissions.
1845
-
1846
- *Toby Ovod-Everett*, *Yves Senn*
1847
-
1848
- * In PostgreSQL, print a warning message if `disable_referential_integrity`
1849
- fails due to missing permissions.
1850
-
1851
- *Andrey Nering*, *Yves Senn*
1852
-
1853
- * Allow a `:limit` option for MySQL bigint primary key support.
1854
-
1855
- Example:
1856
-
1857
- create_table :foos, id: :primary_key, limit: 8 do |t|
1858
- end
1859
-
1860
- # or
1861
-
1862
- create_table :foos, id: false do |t|
1863
- t.primary_key :id, limit: 8
1864
- end
1865
-
1866
- *Ryuta Kamizono*
1867
-
1868
- * `belongs_to` will now trigger a validation error by default if the association is not present.
1869
- You can turn this off on a per-association basis with `optional: true`.
1870
- (Note this new default only applies to new Rails apps that will be generated with
1871
- `config.active_record.belongs_to_required_by_default = true` in initializer.)
1872
-
1873
- *Josef Šimánek*
1874
-
1875
- * Fixed `ActiveRecord::Relation#becomes!` and `changed_attributes` issues for type
1876
- columns.
1877
-
1878
- Fixes #17139.
1879
-
1880
- *Miklos Fazekas*
1881
-
1882
- * Format the time string according to the precision of the time column.
1883
-
1884
- *Ryuta Kamizono*
1885
-
1886
- * Allow a `:precision` option for time type columns.
1887
-
1888
- *Ryuta Kamizono*
1889
-
1890
- * Add `ActiveRecord::Base.suppress` to prevent the receiver from being saved
1891
- during the given block.
1892
-
1893
- For example, here's a pattern of creating notifications when new comments
1894
- are posted. (The notification may in turn trigger an email, a push
1895
- notification, or just appear in the UI somewhere):
1896
-
1897
- class Comment < ActiveRecord::Base
1898
- belongs_to :commentable, polymorphic: true
1899
- after_create -> { Notification.create! comment: self,
1900
- recipients: commentable.recipients }
1901
- end
1902
-
1903
- That's what you want the bulk of the time. A new comment creates a new
1904
- Notification. There may be edge cases where you don't want that, like
1905
- when copying a commentable and its comments, in which case write a
1906
- concern with something like this:
1907
-
1908
- module Copyable
1909
- def copy_to(destination)
1910
- Notification.suppress do
1911
- # Copy logic that creates new comments that we do not want triggering
1912
- # notifications.
1913
- end
1914
- end
1915
- end
1916
-
1917
- *Michael Ryan*
1918
-
1919
- * `:time` option added for `#touch`.
1920
-
1921
- Fixes #18905.
1922
-
1923
- *Hyonjee Joo*
1924
-
1925
- * Add `foreign_key_exists?` method.
1926
-
1927
- *Tõnis Simo*
1928
-
1929
- * Use SQL COUNT and LIMIT 1 queries for `none?` and `one?` methods
1930
- if no block or limit is given, instead of loading the entire
1931
- collection into memory. This applies to relations (e.g. `User.all`)
1932
- as well as associations (e.g. `account.users`)
1933
-
1934
- # Before:
1935
-
1936
- users.none?
1937
- # SELECT "users".* FROM "users"
1938
-
1939
- users.one?
1940
- # SELECT "users".* FROM "users"
1941
-
1942
- # After:
1943
-
1944
- users.none?
1945
- # SELECT 1 AS one FROM "users" LIMIT 1
1946
-
1947
- users.one?
1948
- # SELECT COUNT(*) FROM "users"
1949
-
1950
- *Eugene Gilburg*
1951
-
1952
- * Have `enum` perform type casting consistently with the rest of Active
1953
- Record, such as `where`.
1954
-
1955
- *Sean Griffin*
1956
-
1957
- * `scoping` no longer pollutes the current scope of sibling classes when using
1958
- STI.
1959
-
1960
- Fixes #18806.
1961
-
1962
- Example:
1963
-
1964
- StiOne.none.scoping do
1965
- StiTwo.all
1966
- end
1967
-
1968
-
1969
- *Sean Griffin*
1970
-
1971
- * `remove_reference` with `foreign_key: true` removes the foreign key before
1972
- removing the column. This fixes a bug where it was not possible to remove
1973
- the column on MySQL.
1974
-
1975
- Fixes #18664.
1976
-
1977
- *Yves Senn*
1978
-
1979
- * `find_in_batches` now accepts an `:finish` parameter that complements the `:start`
1980
- parameter to specify where to stop batch processing.
1981
-
1982
- *Vipul A M*
1983
-
1984
- * Fix a rounding problem for PostgreSQL timestamp columns.
1985
-
1986
- If a timestamp column has a precision specified, it needs to
1987
- format according to that.
1988
-
1989
- *Ryuta Kamizono*
1990
-
1991
- * Respect the database default charset for `schema_migrations` table.
1992
-
1993
- The charset of `version` column in `schema_migrations` table depends
1994
- on the database default charset and collation rather than the encoding
1995
- of the connection.
1996
-
1997
- *Ryuta Kamizono*
1998
-
1999
- * Raise `ArgumentError` when passing `nil` or `false` to `Relation#merge`.
2000
-
2001
- These are not valid values to merge in a relation, so it should warn users
2002
- early.
2003
-
2004
- *Rafael Mendonça França*
2005
-
2006
- * Use `SCHEMA` instead of `DB_STRUCTURE` for specifying a structure file.
2007
-
2008
- This makes the `db:structure` tasks consistent with `test:load_structure`.
2009
-
2010
- *Dieter Komendera*
2011
-
2012
- * Respect custom primary keys for associations when calling `Relation#where`
2013
-
2014
- Fixes #18813.
2015
-
2016
- *Sean Griffin*
2017
-
2018
- * Fix several edge cases which could result in a counter cache updating
2019
- twice or not updating at all for `has_many` and `has_many :through`.
2020
-
2021
- Fixes #10865.
2022
-
2023
- *Sean Griffin*
2024
-
2025
- * Foreign keys added by migrations were given random, generated names. This
2026
- meant a different `structure.sql` would be generated every time a developer
2027
- ran migrations on their machine.
2028
-
2029
- The generated part of foreign key names is now a hash of the table name and
2030
- column name, which is consistent every time you run the migration.
2031
-
2032
- *Chris Sinjakli*
2033
-
2034
- * Fix n+1 query problem when eager loading nil associations (fixes #18312)
2035
-
2036
- *Sammy Larbi*
2037
-
2038
- * Change the default error message from `can't be blank` to `must exist` for
2039
- the presence validator of the `:required` option on `belongs_to`/`has_one`
2040
- associations.
2041
-
2042
- *Henrik Nygren*
2043
-
2044
- * Fixed `ActiveRecord::Relation#group` method when an argument is an SQL
2045
- reserved keyword:
2046
-
2047
- Example:
2048
-
2049
- SplitTest.group(:key).count
2050
- Property.group(:value).count
1060
+ * Add `ActiveRecord::Base.base_class?` predicate.
2051
1061
 
2052
1062
  *Bogdan Gusiev*
2053
1063
 
2054
- * Added the `#or` method on `ActiveRecord::Relation`, allowing use of the OR
2055
- operator to combine WHERE or HAVING clauses.
2056
-
2057
- Example:
2058
-
2059
- Post.where('id = 1').or(Post.where('id = 2'))
2060
- # => SELECT * FROM posts WHERE (id = 1) OR (id = 2)
2061
-
2062
- *Sean Griffin*, *Matthew Draper*, *Gael Muller*, *Olivier El Mekki*
2063
-
2064
- * Don't define autosave association callbacks twice from
2065
- `accepts_nested_attributes_for`.
2066
-
2067
- Fixes #18704.
2068
-
2069
- *Sean Griffin*
2070
-
2071
- * Integer types will no longer raise a `RangeError` when assigning an
2072
- attribute, but will instead raise when going to the database.
2073
-
2074
- Fixes several vague issues which were never reported directly. See the
2075
- commit message from the commit which added this line for some examples.
2076
-
2077
- *Sean Griffin*
2078
-
2079
- * Values which would error while being sent to the database (such as an
2080
- ASCII-8BIT string with invalid UTF-8 bytes on SQLite3), no longer error on
2081
- assignment. They will still error when sent to the database, but you are
2082
- given the ability to re-assign it to a valid value.
2083
-
2084
- Fixes #18580.
2085
-
2086
- *Sean Griffin*
2087
-
2088
- * Don't remove join dependencies in `Relation#exists?`
2089
-
2090
- Fixes #18632.
2091
-
2092
- *Sean Griffin*
2093
-
2094
- * Invalid values assigned to a JSON column are assumed to be `nil`.
2095
-
2096
- Fixes #18629.
2097
-
2098
- *Sean Griffin*
2099
-
2100
- * Add `ActiveRecord::Base#accessed_fields`, which can be used to quickly
2101
- discover which fields were read from a model when you are looking to only
2102
- select the data you need from the database.
2103
-
2104
- *Sean Griffin*
2105
-
2106
- * Introduce the `:if_exists` option for `drop_table`.
2107
-
2108
- Example:
2109
-
2110
- drop_table(:posts, if_exists: true)
2111
-
2112
- That would execute:
2113
-
2114
- DROP TABLE IF EXISTS posts
2115
-
2116
- If the table doesn't exist, `if_exists: false` (the default) raises an
2117
- exception whereas `if_exists: true` does nothing.
2118
-
2119
- *Cody Cutrer*, *Stefan Kanev*, *Ryuta Kamizono*
2120
-
2121
- * Don't run SQL if attribute value is not changed for update_attribute method.
2122
-
2123
- *Prathamesh Sonpatki*
2124
-
2125
- * `time` columns can now get affected by `time_zone_aware_attributes`. If you have
2126
- set `config.time_zone` to a value other than `'UTC'`, they will be treated
2127
- as in that time zone by default in Rails 5.1. If this is not the desired
2128
- behavior, you can set
2129
-
2130
- ActiveRecord::Base.time_zone_aware_types = [:datetime]
2131
-
2132
- A deprecation warning will be emitted if you have a `:time` column, and have
2133
- not explicitly opted out.
2134
-
2135
- Fixes #3145.
2136
-
2137
- *Sean Griffin*
2138
-
2139
- * Tests now run after_commit callbacks. You no longer have to declare
2140
- `uses_transaction ‘test name’` to test the results of an after_commit.
2141
-
2142
- after_commit callbacks run after committing a transaction whose parent
2143
- is not `joinable?`: un-nested transactions, transactions within test cases,
2144
- and transactions in `console --sandbox`.
2145
-
2146
- *arthurnn*, *Ravil Bayramgalin*, *Matthew Draper*
2147
-
2148
- * `nil` as a value for a binary column in a query no longer logs as
2149
- "<NULL binary data>", and instead logs as just "nil".
2150
-
2151
- *Sean Griffin*
2152
-
2153
- * `attribute_will_change!` will no longer cause non-persistable attributes to
2154
- be sent to the database.
2155
-
2156
- Fixes #18407.
2157
-
2158
- *Sean Griffin*
2159
-
2160
- * Remove support for the `protected_attributes` gem.
2161
-
2162
- *Carlos Antonio da Silva*, *Roberto Miranda*
2163
-
2164
- * Fix accessing of fixtures having non-string labels like Fixnum.
2165
-
2166
- *Prathamesh Sonpatki*
2167
-
2168
- * Remove deprecated support to preload instance-dependent associations.
2169
-
2170
- *Yves Senn*
2171
-
2172
- * Remove deprecated support for PostgreSQL ranges with exclusive lower bounds.
2173
-
2174
- *Yves Senn*
2175
-
2176
- * Remove deprecation when modifying a relation with cached Arel.
2177
- This raises an `ImmutableRelation` error instead.
2178
-
2179
- *Yves Senn*
2180
-
2181
- * Added `ActiveRecord::SecureToken` in order to encapsulate generation of
2182
- unique tokens for attributes in a model using `SecureRandom`.
2183
-
2184
- *Roberto Miranda*
2185
-
2186
- * Change the behavior of boolean columns to be closer to Ruby's semantics.
2187
-
2188
- Before this change we had a small set of "truthy", and all others are "falsy".
2189
-
2190
- Now, we have a small set of "falsy" values and all others are "truthy" matching
2191
- Ruby's semantics.
2192
-
2193
- *Rafael Mendonça França*
2194
-
2195
- * Deprecate `ActiveRecord::Base.errors_in_transactional_callbacks=`.
2196
-
2197
- *Rafael Mendonça França*
2198
-
2199
- * Change transaction callbacks to not swallow errors.
2200
-
2201
- Before this change any errors raised inside a transaction callback
2202
- were getting rescued and printed in the logs.
2203
-
2204
- Now these errors are not rescued anymore and just bubble up, as the other callbacks.
2205
-
2206
- *Rafael Mendonça França*
2207
-
2208
- * Remove deprecated `sanitize_sql_hash_for_conditions`.
2209
-
2210
- *Rafael Mendonça França*
2211
-
2212
- * Remove deprecated `Reflection#source_macro`.
2213
-
2214
- *Rafael Mendonça França*
2215
-
2216
- * Remove deprecated `symbolized_base_class` and `symbolized_sti_name`.
2217
-
2218
- *Rafael Mendonça França*
2219
-
2220
- * Remove deprecated `ActiveRecord::Base.disable_implicit_join_references=`.
2221
-
2222
- *Rafael Mendonça França*
2223
-
2224
- * Remove deprecated access to connection specification using a string accessor.
2225
-
2226
- Now all strings will be handled as a URL.
2227
-
2228
- *Rafael Mendonça França*
2229
-
2230
- * Change the default `null` value for `timestamps` to `false`.
2231
-
2232
- *Rafael Mendonça França*
2233
-
2234
- * Return an array of pools from `connection_pools`.
2235
-
2236
- *Rafael Mendonça França*
2237
-
2238
- * Return a null column from `column_for_attribute` when no column exists.
2239
-
2240
- *Rafael Mendonça França*
2241
-
2242
- * Remove deprecated `serialized_attributes`.
2243
-
2244
- *Rafael Mendonça França*
2245
-
2246
- * Remove deprecated automatic counter caches on `has_many :through`.
2247
-
2248
- *Rafael Mendonça França*
2249
-
2250
- * Change the way in which callback chains can be halted.
2251
-
2252
- The preferred method to halt a callback chain from now on is to explicitly
2253
- `throw(:abort)`.
2254
- In the past, returning `false` in an Active Record `before_` callback had the
2255
- side effect of halting the callback chain.
2256
- This is not recommended anymore and, depending on the value of the
2257
- `ActiveSupport.halt_callback_chains_on_return_false` option, will
2258
- either not work at all or display a deprecation warning.
2259
-
2260
- *claudiob*
2261
-
2262
- * Clear query cache on rollback.
2263
-
2264
- *Florian Weingarten*
2265
-
2266
- * Fix setting of foreign_key for through associations when building a new record.
2267
-
2268
- Fixes #12698.
2269
-
2270
- *Ivan Antropov*
2271
-
2272
- * Improve dumping of the primary key. If it is not a default primary key,
2273
- correctly dump the type and options.
2274
-
2275
- Fixes #14169, #16599.
2276
-
2277
- *Ryuta Kamizono*
2278
-
2279
- * Format the datetime string according to the precision of the datetime field.
2280
-
2281
- Incompatible to rounding behavior between MySQL 5.6 and earlier.
2282
-
2283
- In 5.5, when you insert `2014-08-17 12:30:00.999999` the fractional part
2284
- is ignored. In 5.6, it's rounded to `2014-08-17 12:30:01`:
2285
-
2286
- http://bugs.mysql.com/bug.php?id=68760
2287
-
2288
- *Ryuta Kamizono*
2289
-
2290
- * Allow a precision option for MySQL datetimes.
2291
-
2292
- *Ryuta Kamizono*
2293
-
2294
- * Fixed automatic `inverse_of` for models nested in a module.
2295
-
2296
- *Andrew McCloud*
2297
-
2298
- * Change `ActiveRecord::Relation#update` behavior so that it can
2299
- be called without passing ids of the records to be updated.
2300
-
2301
- This change allows updating multiple records returned by
2302
- `ActiveRecord::Relation` with callbacks and validations.
2303
-
2304
- # Before
2305
- # ArgumentError: wrong number of arguments (1 for 2)
2306
- Comment.where(group: 'expert').update(body: "Group of Rails Experts")
2307
-
2308
- # After
2309
- # Comments with group expert updated with body "Group of Rails Experts"
2310
- Comment.where(group: 'expert').update(body: "Group of Rails Experts")
2311
-
2312
- *Prathamesh Sonpatki*
2313
-
2314
- * Fix `reaping_frequency` option when the value is a string.
2315
-
2316
- This usually happens when it is configured using `DATABASE_URL`.
2317
-
2318
- *korbin*
2319
-
2320
- * Fix error message when trying to create an associated record and the foreign
2321
- key is missing.
2322
-
2323
- Before this fix the following exception was being raised:
2324
-
2325
- NoMethodError: undefined method `val' for #<Arel::Nodes::BindParam:0x007fc64d19c218>
2326
-
2327
- Now the message is:
2328
-
2329
- ActiveRecord::UnknownAttributeError: unknown attribute 'foreign_key' for Model.
2330
-
2331
- *Rafael Mendonça França*
2332
-
2333
- * Fix change detection problem for PostgreSQL bytea type and
2334
- `ArgumentError: string contains null byte` exception with pg-0.18.
2335
-
2336
- Fixes #17680.
2337
-
2338
- *Lars Kanis*
2339
-
2340
- * When a table has a composite primary key, the `primary_key` method for
2341
- SQLite3 and PostgreSQL adapters was only returning the first field of the key.
2342
- Ensures that it will return nil instead, as Active Record doesn't support
2343
- composite primary keys.
2344
-
2345
- Fixes #18070.
2346
-
2347
- *arthurnn*
2348
-
2349
- * `validates_size_of` / `validates_length_of` do not count records
2350
- which are `marked_for_destruction?`.
2351
-
2352
- Fixes #7247.
2353
-
2354
- *Yves Senn*
2355
-
2356
- * Ensure `first!` and friends work on loaded associations.
2357
-
2358
- Fixes #18237.
2359
-
2360
- *Sean Griffin*
2361
-
2362
- * `eager_load` preserves readonly flag for associations.
2363
-
2364
- Fixes #15853.
2365
-
2366
- *Takashi Kokubun*
2367
-
2368
- * Provide `:touch` option to `save()` to accommodate saving without updating
2369
- timestamps.
2370
-
2371
- Fixes #18202.
2372
-
2373
- *Dan Olson*
2374
-
2375
- * Provide a more helpful error message when an unsupported class is passed to
2376
- `serialize`.
2377
-
2378
- Fixes #18224.
2379
-
2380
- *Sean Griffin*
2381
-
2382
- * Add bigint primary key support for MySQL.
2383
-
2384
- Example:
2385
-
2386
- create_table :foos, id: :bigint do |t|
2387
- end
2388
-
2389
- *Ryuta Kamizono*
2390
-
2391
- * Support for any type of primary key.
2392
-
2393
- Fixes #14194.
2394
-
2395
- *Ryuta Kamizono*
2396
-
2397
- * Dump the default `nil` for PostgreSQL UUID primary key.
2398
-
2399
- *Ryuta Kamizono*
2400
-
2401
- * Add a `:foreign_key` option to `references` and associated migration
2402
- methods. The model and migration generators now use this option, rather than
2403
- the `add_foreign_key` form.
2404
-
2405
- *Sean Griffin*
2406
-
2407
- * Don't raise when writing an attribute with an out-of-range datetime passed
2408
- by the user.
2409
-
2410
- *Grey Baker*
2411
-
2412
- * Replace deprecated `ActiveRecord::Tasks::DatabaseTasks#load_schema` with
2413
- `ActiveRecord::Tasks::DatabaseTasks#load_schema_for`.
2414
-
2415
- *Yves Senn*
2416
-
2417
- * Fix bug with `ActiveRecord::Type::Numeric` that caused negative values to
2418
- be marked as having changed when set to the same negative value.
2419
-
2420
- Fixes #18161.
2421
-
2422
- *Daniel Fox*
2423
-
2424
- * Introduce `force: :cascade` option for `create_table`. Using this option
2425
- will recreate tables even if they have dependent objects (like foreign keys).
2426
- `db/schema.rb` now uses `force: :cascade`. This makes it possible to
2427
- reload the schema when foreign keys are in place.
2428
-
2429
- *Matthew Draper*, *Yves Senn*
2430
-
2431
- * `db:schema:load` and `db:structure:load` no longer purge the database
2432
- before loading the schema. This is left for the user to do.
2433
- `db:test:prepare` will still purge the database.
2434
-
2435
- Fixes #17945.
2436
-
2437
- *Yves Senn*
2438
-
2439
- * Fix undesirable RangeError by `Type::Integer`. Add `Type::UnsignedInteger`.
2440
-
2441
- *Ryuta Kamizono*
2442
-
2443
- * Add `foreign_type` option to `has_one` and `has_many` association macros.
1064
+ * Add custom prefix/suffix options to `ActiveRecord::Store.store_accessor`.
2444
1065
 
2445
- This option enables to define the column name of associated object's type for polymorphic associations.
1066
+ *Tan Huynh*, *Yukio Mizuta*
2446
1067
 
2447
- *Ulisses Almeida*, *Kassio Borges*
1068
+ * Rails 6 requires Ruby 2.5.0 or newer.
2448
1069
 
2449
- * Remove deprecated behavior allowing nested arrays to be passed as query
2450
- values.
1070
+ *Jeremy Daer*, *Kasper Timm Hansen*
2451
1071
 
2452
- *Melanie Gilman*
1072
+ * Deprecate `update_attributes`/`!` in favor of `update`/`!`.
2453
1073
 
2454
- * Deprecate passing a class as a value in a query. Users should pass strings
2455
- instead.
1074
+ *Eddie Lebow*
2456
1075
 
2457
- *Melanie Gilman*
1076
+ * Add `ActiveRecord::Base.create_or_find_by`/`!` to deal with the SELECT/INSERT race condition in
1077
+ `ActiveRecord::Base.find_or_create_by`/`!` by leaning on unique constraints in the database.
2458
1078
 
2459
- * `add_timestamps` and `remove_timestamps` now properly reversible with
2460
- options.
1079
+ *DHH*
2461
1080
 
2462
- *Noam Gagliardi-Rabinovich*
1081
+ * Add `Relation#pick` as short-hand for single-value plucks.
2463
1082
 
2464
- * `ActiveRecord::ConnectionAdapters::ColumnDumper#column_spec` and
2465
- `ActiveRecord::ConnectionAdapters::ColumnDumper#prepare_column_options` no
2466
- longer have a `types` argument. They should access
2467
- `connection#native_database_types` directly.
1083
+ *DHH*
2468
1084
 
2469
- *Yves Senn*
2470
1085
 
2471
- Please check [4-2-stable](https://github.com/rails/rails/blob/4-2-stable/activerecord/CHANGELOG.md) for previous changes.
1086
+ Please check [5-2-stable](https://github.com/rails/rails/blob/5-2-stable/activerecord/CHANGELOG.md) for previous changes.