activerecord 4.2.0 → 6.0.0

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