activerecord 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 (340) hide show
  1. checksums.yaml +7 -0
  2. data/CHANGELOG.md +1013 -0
  3. data/MIT-LICENSE +22 -0
  4. data/README.rdoc +219 -0
  5. data/examples/performance.rb +185 -0
  6. data/examples/simple.rb +15 -0
  7. data/lib/active_record.rb +195 -0
  8. data/lib/active_record/aggregations.rb +285 -0
  9. data/lib/active_record/association_relation.rb +40 -0
  10. data/lib/active_record/associations.rb +1865 -0
  11. data/lib/active_record/associations/alias_tracker.rb +81 -0
  12. data/lib/active_record/associations/association.rb +332 -0
  13. data/lib/active_record/associations/association_scope.rb +166 -0
  14. data/lib/active_record/associations/belongs_to_association.rb +124 -0
  15. data/lib/active_record/associations/belongs_to_polymorphic_association.rb +36 -0
  16. data/lib/active_record/associations/builder/association.rb +136 -0
  17. data/lib/active_record/associations/builder/belongs_to.rb +130 -0
  18. data/lib/active_record/associations/builder/collection_association.rb +72 -0
  19. data/lib/active_record/associations/builder/has_and_belongs_to_many.rb +114 -0
  20. data/lib/active_record/associations/builder/has_many.rb +19 -0
  21. data/lib/active_record/associations/builder/has_one.rb +64 -0
  22. data/lib/active_record/associations/builder/singular_association.rb +44 -0
  23. data/lib/active_record/associations/collection_association.rb +498 -0
  24. data/lib/active_record/associations/collection_proxy.rb +1128 -0
  25. data/lib/active_record/associations/foreign_association.rb +20 -0
  26. data/lib/active_record/associations/has_many_association.rb +136 -0
  27. data/lib/active_record/associations/has_many_through_association.rb +220 -0
  28. data/lib/active_record/associations/has_one_association.rb +118 -0
  29. data/lib/active_record/associations/has_one_through_association.rb +45 -0
  30. data/lib/active_record/associations/join_dependency.rb +258 -0
  31. data/lib/active_record/associations/join_dependency/join_association.rb +80 -0
  32. data/lib/active_record/associations/join_dependency/join_base.rb +23 -0
  33. data/lib/active_record/associations/join_dependency/join_part.rb +71 -0
  34. data/lib/active_record/associations/preloader.rb +201 -0
  35. data/lib/active_record/associations/preloader/association.rb +133 -0
  36. data/lib/active_record/associations/preloader/through_association.rb +116 -0
  37. data/lib/active_record/associations/singular_association.rb +59 -0
  38. data/lib/active_record/associations/through_association.rb +121 -0
  39. data/lib/active_record/attribute_assignment.rb +85 -0
  40. data/lib/active_record/attribute_decorators.rb +90 -0
  41. data/lib/active_record/attribute_methods.rb +420 -0
  42. data/lib/active_record/attribute_methods/before_type_cast.rb +81 -0
  43. data/lib/active_record/attribute_methods/dirty.rb +221 -0
  44. data/lib/active_record/attribute_methods/primary_key.rb +136 -0
  45. data/lib/active_record/attribute_methods/query.rb +41 -0
  46. data/lib/active_record/attribute_methods/read.rb +47 -0
  47. data/lib/active_record/attribute_methods/serialization.rb +90 -0
  48. data/lib/active_record/attribute_methods/time_zone_conversion.rb +91 -0
  49. data/lib/active_record/attribute_methods/write.rb +61 -0
  50. data/lib/active_record/attributes.rb +279 -0
  51. data/lib/active_record/autosave_association.rb +508 -0
  52. data/lib/active_record/base.rb +328 -0
  53. data/lib/active_record/callbacks.rb +339 -0
  54. data/lib/active_record/coders/json.rb +15 -0
  55. data/lib/active_record/coders/yaml_column.rb +50 -0
  56. data/lib/active_record/connection_adapters/abstract/connection_pool.rb +1165 -0
  57. data/lib/active_record/connection_adapters/abstract/database_limits.rb +85 -0
  58. data/lib/active_record/connection_adapters/abstract/database_statements.rb +512 -0
  59. data/lib/active_record/connection_adapters/abstract/query_cache.rb +154 -0
  60. data/lib/active_record/connection_adapters/abstract/quoting.rb +251 -0
  61. data/lib/active_record/connection_adapters/abstract/savepoints.rb +23 -0
  62. data/lib/active_record/connection_adapters/abstract/schema_creation.rb +153 -0
  63. data/lib/active_record/connection_adapters/abstract/schema_definitions.rb +713 -0
  64. data/lib/active_record/connection_adapters/abstract/schema_dumper.rb +93 -0
  65. data/lib/active_record/connection_adapters/abstract/schema_statements.rb +1475 -0
  66. data/lib/active_record/connection_adapters/abstract/transaction.rb +323 -0
  67. data/lib/active_record/connection_adapters/abstract_adapter.rb +761 -0
  68. data/lib/active_record/connection_adapters/abstract_mysql_adapter.rb +821 -0
  69. data/lib/active_record/connection_adapters/column.rb +95 -0
  70. data/lib/active_record/connection_adapters/connection_specification.rb +297 -0
  71. data/lib/active_record/connection_adapters/determine_if_preparable_visitor.rb +29 -0
  72. data/lib/active_record/connection_adapters/mysql/column.rb +27 -0
  73. data/lib/active_record/connection_adapters/mysql/database_statements.rb +200 -0
  74. data/lib/active_record/connection_adapters/mysql/explain_pretty_printer.rb +72 -0
  75. data/lib/active_record/connection_adapters/mysql/quoting.rb +81 -0
  76. data/lib/active_record/connection_adapters/mysql/schema_creation.rb +72 -0
  77. data/lib/active_record/connection_adapters/mysql/schema_definitions.rb +95 -0
  78. data/lib/active_record/connection_adapters/mysql/schema_dumper.rb +88 -0
  79. data/lib/active_record/connection_adapters/mysql/schema_statements.rb +264 -0
  80. data/lib/active_record/connection_adapters/mysql/type_metadata.rb +31 -0
  81. data/lib/active_record/connection_adapters/mysql2_adapter.rb +146 -0
  82. data/lib/active_record/connection_adapters/postgresql/column.rb +30 -0
  83. data/lib/active_record/connection_adapters/postgresql/database_statements.rb +182 -0
  84. data/lib/active_record/connection_adapters/postgresql/explain_pretty_printer.rb +44 -0
  85. data/lib/active_record/connection_adapters/postgresql/oid.rb +34 -0
  86. data/lib/active_record/connection_adapters/postgresql/oid/array.rb +92 -0
  87. data/lib/active_record/connection_adapters/postgresql/oid/bit.rb +53 -0
  88. data/lib/active_record/connection_adapters/postgresql/oid/bit_varying.rb +15 -0
  89. data/lib/active_record/connection_adapters/postgresql/oid/bytea.rb +17 -0
  90. data/lib/active_record/connection_adapters/postgresql/oid/cidr.rb +50 -0
  91. data/lib/active_record/connection_adapters/postgresql/oid/date.rb +23 -0
  92. data/lib/active_record/connection_adapters/postgresql/oid/date_time.rb +23 -0
  93. data/lib/active_record/connection_adapters/postgresql/oid/decimal.rb +15 -0
  94. data/lib/active_record/connection_adapters/postgresql/oid/enum.rb +21 -0
  95. data/lib/active_record/connection_adapters/postgresql/oid/hstore.rb +71 -0
  96. data/lib/active_record/connection_adapters/postgresql/oid/inet.rb +15 -0
  97. data/lib/active_record/connection_adapters/postgresql/oid/jsonb.rb +15 -0
  98. data/lib/active_record/connection_adapters/postgresql/oid/legacy_point.rb +45 -0
  99. data/lib/active_record/connection_adapters/postgresql/oid/money.rb +41 -0
  100. data/lib/active_record/connection_adapters/postgresql/oid/oid.rb +15 -0
  101. data/lib/active_record/connection_adapters/postgresql/oid/point.rb +65 -0
  102. data/lib/active_record/connection_adapters/postgresql/oid/range.rb +97 -0
  103. data/lib/active_record/connection_adapters/postgresql/oid/specialized_string.rb +18 -0
  104. data/lib/active_record/connection_adapters/postgresql/oid/type_map_initializer.rb +113 -0
  105. data/lib/active_record/connection_adapters/postgresql/oid/uuid.rb +26 -0
  106. data/lib/active_record/connection_adapters/postgresql/oid/vector.rb +28 -0
  107. data/lib/active_record/connection_adapters/postgresql/oid/xml.rb +30 -0
  108. data/lib/active_record/connection_adapters/postgresql/quoting.rb +205 -0
  109. data/lib/active_record/connection_adapters/postgresql/referential_integrity.rb +43 -0
  110. data/lib/active_record/connection_adapters/postgresql/schema_creation.rb +76 -0
  111. data/lib/active_record/connection_adapters/postgresql/schema_definitions.rb +222 -0
  112. data/lib/active_record/connection_adapters/postgresql/schema_dumper.rb +50 -0
  113. data/lib/active_record/connection_adapters/postgresql/schema_statements.rb +776 -0
  114. data/lib/active_record/connection_adapters/postgresql/type_metadata.rb +36 -0
  115. data/lib/active_record/connection_adapters/postgresql/utils.rb +81 -0
  116. data/lib/active_record/connection_adapters/postgresql_adapter.rb +949 -0
  117. data/lib/active_record/connection_adapters/schema_cache.rb +141 -0
  118. data/lib/active_record/connection_adapters/sql_type_metadata.rb +37 -0
  119. data/lib/active_record/connection_adapters/sqlite3/database_statements.rb +118 -0
  120. data/lib/active_record/connection_adapters/sqlite3/explain_pretty_printer.rb +21 -0
  121. data/lib/active_record/connection_adapters/sqlite3/quoting.rb +103 -0
  122. data/lib/active_record/connection_adapters/sqlite3/schema_creation.rb +17 -0
  123. data/lib/active_record/connection_adapters/sqlite3/schema_definitions.rb +19 -0
  124. data/lib/active_record/connection_adapters/sqlite3/schema_dumper.rb +18 -0
  125. data/lib/active_record/connection_adapters/sqlite3/schema_statements.rb +137 -0
  126. data/lib/active_record/connection_adapters/sqlite3_adapter.rb +557 -0
  127. data/lib/active_record/connection_adapters/statement_pool.rb +61 -0
  128. data/lib/active_record/connection_handling.rb +267 -0
  129. data/lib/active_record/core.rb +599 -0
  130. data/lib/active_record/counter_cache.rb +193 -0
  131. data/lib/active_record/database_configurations.rb +233 -0
  132. data/lib/active_record/database_configurations/database_config.rb +37 -0
  133. data/lib/active_record/database_configurations/hash_config.rb +50 -0
  134. data/lib/active_record/database_configurations/url_config.rb +79 -0
  135. data/lib/active_record/define_callbacks.rb +22 -0
  136. data/lib/active_record/dynamic_matchers.rb +122 -0
  137. data/lib/active_record/enum.rb +274 -0
  138. data/lib/active_record/errors.rb +388 -0
  139. data/lib/active_record/explain.rb +50 -0
  140. data/lib/active_record/explain_registry.rb +32 -0
  141. data/lib/active_record/explain_subscriber.rb +34 -0
  142. data/lib/active_record/fixture_set/file.rb +82 -0
  143. data/lib/active_record/fixture_set/model_metadata.rb +33 -0
  144. data/lib/active_record/fixture_set/render_context.rb +17 -0
  145. data/lib/active_record/fixture_set/table_row.rb +153 -0
  146. data/lib/active_record/fixture_set/table_rows.rb +47 -0
  147. data/lib/active_record/fixtures.rb +738 -0
  148. data/lib/active_record/gem_version.rb +17 -0
  149. data/lib/active_record/inheritance.rb +293 -0
  150. data/lib/active_record/insert_all.rb +179 -0
  151. data/lib/active_record/integration.rb +207 -0
  152. data/lib/active_record/internal_metadata.rb +53 -0
  153. data/lib/active_record/legacy_yaml_adapter.rb +48 -0
  154. data/lib/active_record/locale/en.yml +48 -0
  155. data/lib/active_record/locking/optimistic.rb +197 -0
  156. data/lib/active_record/locking/pessimistic.rb +89 -0
  157. data/lib/active_record/log_subscriber.rb +118 -0
  158. data/lib/active_record/middleware/database_selector.rb +75 -0
  159. data/lib/active_record/middleware/database_selector/resolver.rb +92 -0
  160. data/lib/active_record/middleware/database_selector/resolver/session.rb +45 -0
  161. data/lib/active_record/migration.rb +1397 -0
  162. data/lib/active_record/migration/command_recorder.rb +284 -0
  163. data/lib/active_record/migration/compatibility.rb +244 -0
  164. data/lib/active_record/migration/join_table.rb +17 -0
  165. data/lib/active_record/model_schema.rb +542 -0
  166. data/lib/active_record/nested_attributes.rb +600 -0
  167. data/lib/active_record/no_touching.rb +65 -0
  168. data/lib/active_record/null_relation.rb +68 -0
  169. data/lib/active_record/persistence.rb +967 -0
  170. data/lib/active_record/query_cache.rb +52 -0
  171. data/lib/active_record/querying.rb +82 -0
  172. data/lib/active_record/railtie.rb +263 -0
  173. data/lib/active_record/railties/collection_cache_association_loading.rb +34 -0
  174. data/lib/active_record/railties/console_sandbox.rb +7 -0
  175. data/lib/active_record/railties/controller_runtime.rb +51 -0
  176. data/lib/active_record/railties/databases.rake +527 -0
  177. data/lib/active_record/readonly_attributes.rb +24 -0
  178. data/lib/active_record/reflection.rb +1042 -0
  179. data/lib/active_record/relation.rb +859 -0
  180. data/lib/active_record/relation/batches.rb +290 -0
  181. data/lib/active_record/relation/batches/batch_enumerator.rb +69 -0
  182. data/lib/active_record/relation/calculations.rb +424 -0
  183. data/lib/active_record/relation/delegation.rb +130 -0
  184. data/lib/active_record/relation/finder_methods.rb +552 -0
  185. data/lib/active_record/relation/from_clause.rb +26 -0
  186. data/lib/active_record/relation/merger.rb +184 -0
  187. data/lib/active_record/relation/predicate_builder.rb +150 -0
  188. data/lib/active_record/relation/predicate_builder/array_handler.rb +49 -0
  189. data/lib/active_record/relation/predicate_builder/association_query_value.rb +43 -0
  190. data/lib/active_record/relation/predicate_builder/base_handler.rb +18 -0
  191. data/lib/active_record/relation/predicate_builder/basic_object_handler.rb +19 -0
  192. data/lib/active_record/relation/predicate_builder/polymorphic_array_value.rb +53 -0
  193. data/lib/active_record/relation/predicate_builder/range_handler.rb +22 -0
  194. data/lib/active_record/relation/predicate_builder/relation_handler.rb +19 -0
  195. data/lib/active_record/relation/query_attribute.rb +50 -0
  196. data/lib/active_record/relation/query_methods.rb +1359 -0
  197. data/lib/active_record/relation/record_fetch_warning.rb +51 -0
  198. data/lib/active_record/relation/spawn_methods.rb +77 -0
  199. data/lib/active_record/relation/where_clause.rb +190 -0
  200. data/lib/active_record/relation/where_clause_factory.rb +33 -0
  201. data/lib/active_record/result.rb +168 -0
  202. data/lib/active_record/runtime_registry.rb +24 -0
  203. data/lib/active_record/sanitization.rb +214 -0
  204. data/lib/active_record/schema.rb +61 -0
  205. data/lib/active_record/schema_dumper.rb +270 -0
  206. data/lib/active_record/schema_migration.rb +60 -0
  207. data/lib/active_record/scoping.rb +106 -0
  208. data/lib/active_record/scoping/default.rb +151 -0
  209. data/lib/active_record/scoping/named.rb +217 -0
  210. data/lib/active_record/secure_token.rb +40 -0
  211. data/lib/active_record/serialization.rb +22 -0
  212. data/lib/active_record/statement_cache.rb +148 -0
  213. data/lib/active_record/store.rb +290 -0
  214. data/lib/active_record/suppressor.rb +61 -0
  215. data/lib/active_record/table_metadata.rb +75 -0
  216. data/lib/active_record/tasks/database_tasks.rb +506 -0
  217. data/lib/active_record/tasks/mysql_database_tasks.rb +115 -0
  218. data/lib/active_record/tasks/postgresql_database_tasks.rb +141 -0
  219. data/lib/active_record/tasks/sqlite_database_tasks.rb +77 -0
  220. data/lib/active_record/test_databases.rb +23 -0
  221. data/lib/active_record/test_fixtures.rb +224 -0
  222. data/lib/active_record/timestamp.rb +167 -0
  223. data/lib/active_record/touch_later.rb +66 -0
  224. data/lib/active_record/transactions.rb +493 -0
  225. data/lib/active_record/translation.rb +24 -0
  226. data/lib/active_record/type.rb +78 -0
  227. data/lib/active_record/type/adapter_specific_registry.rb +129 -0
  228. data/lib/active_record/type/date.rb +9 -0
  229. data/lib/active_record/type/date_time.rb +9 -0
  230. data/lib/active_record/type/decimal_without_scale.rb +15 -0
  231. data/lib/active_record/type/hash_lookup_type_map.rb +25 -0
  232. data/lib/active_record/type/internal/timezone.rb +17 -0
  233. data/lib/active_record/type/json.rb +30 -0
  234. data/lib/active_record/type/serialized.rb +71 -0
  235. data/lib/active_record/type/text.rb +11 -0
  236. data/lib/active_record/type/time.rb +21 -0
  237. data/lib/active_record/type/type_map.rb +62 -0
  238. data/lib/active_record/type/unsigned_integer.rb +17 -0
  239. data/lib/active_record/type_caster.rb +9 -0
  240. data/lib/active_record/type_caster/connection.rb +34 -0
  241. data/lib/active_record/type_caster/map.rb +20 -0
  242. data/lib/active_record/validations.rb +94 -0
  243. data/lib/active_record/validations/absence.rb +25 -0
  244. data/lib/active_record/validations/associated.rb +60 -0
  245. data/lib/active_record/validations/length.rb +26 -0
  246. data/lib/active_record/validations/presence.rb +68 -0
  247. data/lib/active_record/validations/uniqueness.rb +226 -0
  248. data/lib/active_record/version.rb +10 -0
  249. data/lib/arel.rb +51 -0
  250. data/lib/arel/alias_predication.rb +9 -0
  251. data/lib/arel/attributes.rb +22 -0
  252. data/lib/arel/attributes/attribute.rb +37 -0
  253. data/lib/arel/collectors/bind.rb +24 -0
  254. data/lib/arel/collectors/composite.rb +31 -0
  255. data/lib/arel/collectors/plain_string.rb +20 -0
  256. data/lib/arel/collectors/sql_string.rb +20 -0
  257. data/lib/arel/collectors/substitute_binds.rb +28 -0
  258. data/lib/arel/crud.rb +42 -0
  259. data/lib/arel/delete_manager.rb +18 -0
  260. data/lib/arel/errors.rb +9 -0
  261. data/lib/arel/expressions.rb +29 -0
  262. data/lib/arel/factory_methods.rb +49 -0
  263. data/lib/arel/insert_manager.rb +49 -0
  264. data/lib/arel/math.rb +45 -0
  265. data/lib/arel/nodes.rb +68 -0
  266. data/lib/arel/nodes/and.rb +32 -0
  267. data/lib/arel/nodes/ascending.rb +23 -0
  268. data/lib/arel/nodes/binary.rb +52 -0
  269. data/lib/arel/nodes/bind_param.rb +36 -0
  270. data/lib/arel/nodes/case.rb +55 -0
  271. data/lib/arel/nodes/casted.rb +50 -0
  272. data/lib/arel/nodes/comment.rb +29 -0
  273. data/lib/arel/nodes/count.rb +12 -0
  274. data/lib/arel/nodes/delete_statement.rb +45 -0
  275. data/lib/arel/nodes/descending.rb +23 -0
  276. data/lib/arel/nodes/equality.rb +18 -0
  277. data/lib/arel/nodes/extract.rb +24 -0
  278. data/lib/arel/nodes/false.rb +16 -0
  279. data/lib/arel/nodes/full_outer_join.rb +8 -0
  280. data/lib/arel/nodes/function.rb +44 -0
  281. data/lib/arel/nodes/grouping.rb +8 -0
  282. data/lib/arel/nodes/in.rb +8 -0
  283. data/lib/arel/nodes/infix_operation.rb +80 -0
  284. data/lib/arel/nodes/inner_join.rb +8 -0
  285. data/lib/arel/nodes/insert_statement.rb +37 -0
  286. data/lib/arel/nodes/join_source.rb +20 -0
  287. data/lib/arel/nodes/matches.rb +18 -0
  288. data/lib/arel/nodes/named_function.rb +23 -0
  289. data/lib/arel/nodes/node.rb +50 -0
  290. data/lib/arel/nodes/node_expression.rb +13 -0
  291. data/lib/arel/nodes/outer_join.rb +8 -0
  292. data/lib/arel/nodes/over.rb +15 -0
  293. data/lib/arel/nodes/regexp.rb +16 -0
  294. data/lib/arel/nodes/right_outer_join.rb +8 -0
  295. data/lib/arel/nodes/select_core.rb +67 -0
  296. data/lib/arel/nodes/select_statement.rb +41 -0
  297. data/lib/arel/nodes/sql_literal.rb +16 -0
  298. data/lib/arel/nodes/string_join.rb +11 -0
  299. data/lib/arel/nodes/table_alias.rb +27 -0
  300. data/lib/arel/nodes/terminal.rb +16 -0
  301. data/lib/arel/nodes/true.rb +16 -0
  302. data/lib/arel/nodes/unary.rb +45 -0
  303. data/lib/arel/nodes/unary_operation.rb +20 -0
  304. data/lib/arel/nodes/unqualified_column.rb +22 -0
  305. data/lib/arel/nodes/update_statement.rb +41 -0
  306. data/lib/arel/nodes/values_list.rb +9 -0
  307. data/lib/arel/nodes/window.rb +126 -0
  308. data/lib/arel/nodes/with.rb +11 -0
  309. data/lib/arel/order_predications.rb +13 -0
  310. data/lib/arel/predications.rb +257 -0
  311. data/lib/arel/select_manager.rb +271 -0
  312. data/lib/arel/table.rb +110 -0
  313. data/lib/arel/tree_manager.rb +72 -0
  314. data/lib/arel/update_manager.rb +34 -0
  315. data/lib/arel/visitors.rb +20 -0
  316. data/lib/arel/visitors/depth_first.rb +204 -0
  317. data/lib/arel/visitors/dot.rb +297 -0
  318. data/lib/arel/visitors/ibm_db.rb +34 -0
  319. data/lib/arel/visitors/informix.rb +62 -0
  320. data/lib/arel/visitors/mssql.rb +157 -0
  321. data/lib/arel/visitors/mysql.rb +83 -0
  322. data/lib/arel/visitors/oracle.rb +159 -0
  323. data/lib/arel/visitors/oracle12.rb +66 -0
  324. data/lib/arel/visitors/postgresql.rb +110 -0
  325. data/lib/arel/visitors/sqlite.rb +39 -0
  326. data/lib/arel/visitors/to_sql.rb +889 -0
  327. data/lib/arel/visitors/visitor.rb +46 -0
  328. data/lib/arel/visitors/where_sql.rb +23 -0
  329. data/lib/arel/window_predications.rb +9 -0
  330. data/lib/rails/generators/active_record.rb +19 -0
  331. data/lib/rails/generators/active_record/application_record/application_record_generator.rb +27 -0
  332. data/lib/rails/generators/active_record/application_record/templates/application_record.rb.tt +5 -0
  333. data/lib/rails/generators/active_record/migration.rb +48 -0
  334. data/lib/rails/generators/active_record/migration/migration_generator.rb +75 -0
  335. data/lib/rails/generators/active_record/migration/templates/create_table_migration.rb.tt +24 -0
  336. data/lib/rails/generators/active_record/migration/templates/migration.rb.tt +48 -0
  337. data/lib/rails/generators/active_record/model/model_generator.rb +49 -0
  338. data/lib/rails/generators/active_record/model/templates/model.rb.tt +22 -0
  339. data/lib/rails/generators/active_record/model/templates/module.rb.tt +7 -0
  340. metadata +415 -0
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: ed17e948626d108075b2951ac71abbac3075ef55b055abe64e2b352e91755fd9
4
+ data.tar.gz: 2c031642e021041f9fdf278888b580fd446879008a23f12d33c8b33aafbddc59
5
+ SHA512:
6
+ metadata.gz: 6b208a5cbee77c2a057649b762a92ec4ca5be3b8fbd1b2123caf485579abbc602bcb2aee455a503b74f33efa9ce364ab644dc8958b9e1edd94fee3397bf17cc8
7
+ data.tar.gz: 751ecf72279d478887665f6a3efc5ad366b70284fb3f4ef6d2f3b072faf7c325be660116a7d3ac9427ac44dcf6f8c345e145921692d0465e24a70f1c2ca3b1bd
@@ -0,0 +1,1013 @@
1
+ ## Rails 6.0.0 (August 16, 2019) ##
2
+
3
+ * Preserve user supplied joins order as much as possible.
4
+
5
+ Fixes #36761, #34328, #24281, #12953.
6
+
7
+ *Ryuta Kamizono*
8
+
9
+ * Make the DATABASE_URL env variable only affect the primary connection. Add new env variables for multiple databases.
10
+
11
+ *John Crepezzi*, *Eileen Uchitelle*
12
+
13
+ * Add a warning for enum elements with 'not_' prefix.
14
+
15
+ class Foo
16
+ enum status: [:sent, :not_sent]
17
+ end
18
+
19
+ *Edu Depetris*
20
+
21
+ * Make currency symbols optional for money column type in PostgreSQL
22
+
23
+ *Joel Schneider*
24
+
25
+
26
+ ## Rails 6.0.0.rc2 (July 22, 2019) ##
27
+
28
+ * Add database_exists? method to connection adapters to check if a database exists.
29
+
30
+ *Guilherme Mansur*
31
+
32
+ * PostgreSQL: Fix GROUP BY with ORDER BY virtual count attribute.
33
+
34
+ Fixes #36022.
35
+
36
+ *Ryuta Kamizono*
37
+
38
+ * Make ActiveRecord `ConnectionPool.connections` method thread-safe.
39
+
40
+ Fixes #36465.
41
+
42
+ *Jeff Doering*
43
+
44
+ * Fix sqlite3 collation parsing when using decimal columns.
45
+
46
+ *Martin R. Schuster*
47
+
48
+ * Fix invalid schema when primary key column has a comment.
49
+
50
+ Fixes #29966.
51
+
52
+ *Guilherme Goettems Schneider*
53
+
54
+ * Fix table comment also being applied to the primary key column.
55
+
56
+ *Guilherme Goettems Schneider*
57
+
58
+ * Fix merging left_joins to maintain its own `join_type` context.
59
+
60
+ Fixes #36103.
61
+
62
+ *Ryuta Kamizono*
63
+
64
+
65
+ ## Rails 6.0.0.rc1 (April 24, 2019) ##
66
+
67
+ * Add `touch` option to `has_one` association.
68
+
69
+ *Abhay Nikam*
70
+
71
+ * Deprecate `where.not` working as NOR and will be changed to NAND in Rails 6.1.
72
+
73
+ ```ruby
74
+ all = [treasures(:diamond), treasures(:sapphire), cars(:honda), treasures(:sapphire)]
75
+ assert_equal all, PriceEstimate.all.map(&:estimate_of)
76
+ ```
77
+
78
+ In Rails 6.0:
79
+
80
+ ```ruby
81
+ sapphire = treasures(:sapphire)
82
+
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
89
+
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
+ ```
95
+
96
+ In Rails 6.1:
97
+
98
+ ```ruby
99
+ sapphire = treasures(:sapphire)
100
+
101
+ nand = all - [sapphire]
102
+ assert_equal [treasures(:diamond), cars(:honda)], nand
103
+
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
+ ```
109
+
110
+ *Ryuta Kamizono*
111
+
112
+ * Fix dirty tracking after rollback.
113
+
114
+ Fixes #15018, #30167, #33868.
115
+
116
+ *Ryuta Kamizono*
117
+
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.
122
+
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+
126
+
127
+ *Lachlan Sylvester*
128
+
129
+ * Fix dirty tracking for `touch` to track saved changes.
130
+
131
+ Fixes #33429.
132
+
133
+ *Ryuta Kamzono*
134
+
135
+ * `change_column_comment` and `change_table_comment` are invertible only if
136
+ `to` and `from` options are specified.
137
+
138
+ *Yoshiyuki Kinjo*
139
+
140
+ * Don't call commit/rollback callbacks when a record isn't saved.
141
+
142
+ Fixes #29747.
143
+
144
+ *Ryuta Kamizono*
145
+
146
+ * Fix circular `autosave: true` causes invalid records to be saved.
147
+
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`.
155
+
156
+ Fixes #28080.
157
+
158
+ *Larry Reid*
159
+
160
+ * Raise `ArgumentError` for invalid `:limit` and `:precision` like as other options.
161
+
162
+ Before:
163
+
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
+ ```
170
+
171
+ After:
172
+
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
+ ```
179
+
180
+ *Ryuta Kamizono*
181
+
182
+ * Association loading isn't to be affected by scoping consistently
183
+ whether preloaded / eager loaded or not, with the exception of `unscoped`.
184
+
185
+ Before:
186
+
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
+ ```
194
+
195
+ After:
196
+
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
+ ```
204
+
205
+ Fixes #34638, #35398.
206
+
207
+ *Ryuta Kamizono*
208
+
209
+ * Add `rails db:prepare` to migrate or setup a database.
210
+
211
+ Runs `db:migrate` if the database exists or `db:setup` if it doesn't.
212
+
213
+ *Roberto Miranda*
214
+
215
+ * Add `after_save_commit` callback as shortcut for `after_commit :hook, on: [ :create, :update ]`.
216
+
217
+ *DHH*
218
+
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.
221
+
222
+ Fixes #33249.
223
+
224
+ *Ryan H. Kerr*
225
+
226
+ * Add `ActiveRecord::Relation#extract_associated` for extracting associated records from a relation.
227
+
228
+ ```
229
+ account.memberships.extract_associated(:user)
230
+ # => Returns collection of User records
231
+ ```
232
+
233
+ *DHH*
234
+
235
+ * Add `ActiveRecord::Relation#annotate` for adding SQL comments to its queries.
236
+
237
+ For example:
238
+
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
+ ```
243
+
244
+ This can be useful in instrumentation or other analysis of issued queries.
245
+
246
+ *Matt Yoho*
247
+
248
+ * Support Optimizer Hints.
249
+
250
+ In most databases, a way to control the optimizer is by using optimizer hints,
251
+ which can be specified within individual statements.
252
+
253
+ Example (for MySQL):
254
+
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`
257
+
258
+ Example (for PostgreSQL with pg_hint_plan):
259
+
260
+ Topic.optimizer_hints("SeqScan(topics)", "Parallel(topics 8)")
261
+ # SELECT /*+ SeqScan(topics) Parallel(topics 8) */ "topics".* FROM "topics"
262
+
263
+ See also:
264
+
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
270
+
271
+ *Ryuta Kamizono*
272
+
273
+ * Fix query attribute method on user-defined attribute to be aware of typecasted value.
274
+
275
+ For example, the following code no longer return false as casted non-empty string:
276
+
277
+ ```
278
+ class Post < ActiveRecord::Base
279
+ attribute :user_defined_text, :text
280
+ end
281
+
282
+ Post.new(user_defined_text: "false").user_defined_text? # => true
283
+ ```
284
+
285
+ *Yuji Kamijima*
286
+
287
+ * Quote empty ranges like other empty enumerables.
288
+
289
+ *Patrick Rebsch*
290
+
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`.
294
+
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.
298
+
299
+ *Bob Lail*
300
+
301
+ * Add `rails db:seed:replant` that truncates tables of each database
302
+ for current environment and loads the seeds.
303
+
304
+ *bogdanvlviv*, *DHH*
305
+
306
+ * Add `ActiveRecord::Base.connection.truncate` for SQLite3 adapter.
307
+
308
+ *bogdanvlviv*
309
+
310
+ * Deprecate mismatched collation comparison for uniqueness validator.
311
+
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.
315
+
316
+ *Ryuta Kamizono*
317
+
318
+ * Add `reselect` method. This is a short-hand for `unscope(:select).select(fields)`.
319
+
320
+ Fixes #27340.
321
+
322
+ *Willian Gustavo Veiga*
323
+
324
+ * Add negative scopes for all enum values.
325
+
326
+ Example:
327
+
328
+ class Post < ActiveRecord::Base
329
+ enum status: %i[ drafted active trashed ]
330
+ end
331
+
332
+ Post.not_drafted # => where.not(status: :drafted)
333
+ Post.not_active # => where.not(status: :active)
334
+ Post.not_trashed # => where.not(status: :trashed)
335
+
336
+ *DHH*
337
+
338
+ * Fix different `count` calculation when using `size` with manual `select` with DISTINCT.
339
+
340
+ Fixes #35214.
341
+
342
+ *Juani Villarejo*
343
+
344
+
345
+ ## Rails 6.0.0.beta3 (March 11, 2019) ##
346
+
347
+ * No changes.
348
+
349
+
350
+ ## Rails 6.0.0.beta2 (February 25, 2019) ##
351
+
352
+ * Fix prepared statements caching to be enabled even when query caching is enabled.
353
+
354
+ *Ryuta Kamizono*
355
+
356
+ * Ensure `update_all` series cares about optimistic locking.
357
+
358
+ *Ryuta Kamizono*
359
+
360
+ * Don't allow `where` with non numeric string matches to 0 values.
361
+
362
+ *Ryuta Kamizono*
363
+
364
+ * Introduce `ActiveRecord::Relation#destroy_by` and `ActiveRecord::Relation#delete_by`.
365
+
366
+ `destroy_by` allows relation to find all the records matching the condition and perform
367
+ `destroy_all` on the matched records.
368
+
369
+ Example:
370
+
371
+ Person.destroy_by(name: 'David')
372
+ Person.destroy_by(name: 'David', rating: 4)
373
+
374
+ david = Person.find_by(name: 'David')
375
+ david.posts.destroy_by(id: [1, 2, 3])
376
+
377
+ `delete_by` allows relation to find all the records matching the condition and perform
378
+ `delete_all` on the matched records.
379
+
380
+ Example:
381
+
382
+ Person.delete_by(name: 'David')
383
+ Person.delete_by(name: 'David', rating: 4)
384
+
385
+ david = Person.find_by(name: 'David')
386
+ david.posts.delete_by(id: [1, 2, 3])
387
+
388
+ *Abhay Nikam*
389
+
390
+ * Don't allow `where` with invalid value matches to nil values.
391
+
392
+ Fixes #33624.
393
+
394
+ *Ryuta Kamizono*
395
+
396
+ * SQLite3: Implement `add_foreign_key` and `remove_foreign_key`.
397
+
398
+ *Ryuta Kamizono*
399
+
400
+ * Deprecate using class level querying methods if the receiver scope
401
+ regarded as leaked. Use `klass.unscoped` to avoid the leaking scope.
402
+
403
+ *Ryuta Kamizono*
404
+
405
+ * Allow applications to automatically switch connections.
406
+
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.
410
+
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.
417
+
418
+ To use the middleware in your application you can use the following
419
+ configuration options:
420
+
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
+ ```
426
+
427
+ To change the database selection strategy, pass a custom class to the
428
+ configuration options:
429
+
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
+ ```
435
+
436
+ *Eileen M. Uchitelle*
437
+
438
+ * MySQL: Support `:size` option to change text and blob size.
439
+
440
+ *Ryuta Kamizono*
441
+
442
+ * Make `t.timestamps` with precision by default.
443
+
444
+ *Ryuta Kamizono*
445
+
446
+
447
+ ## Rails 6.0.0.beta1 (January 18, 2019) ##
448
+
449
+ * Remove deprecated `#set_state` from the transaction object.
450
+
451
+ *Rafael Mendonça França*
452
+
453
+ * Remove deprecated `#supports_statement_cache?` from the database adapters.
454
+
455
+ *Rafael Mendonça França*
456
+
457
+ * Remove deprecated `#insert_fixtures` from the database adapters.
458
+
459
+ *Rafael Mendonça França*
460
+
461
+ * Remove deprecated `ActiveRecord::ConnectionAdapters::SQLite3Adapter#valid_alter_table_type?`.
462
+
463
+ *Rafael Mendonça França*
464
+
465
+ * Do not allow passing the column name to `sum` when a block is passed.
466
+
467
+ *Rafael Mendonça França*
468
+
469
+ * Do not allow passing the column name to `count` when a block is passed.
470
+
471
+ *Rafael Mendonça França*
472
+
473
+ * Remove delegation of missing methods in a relation to arel.
474
+
475
+ *Rafael Mendonça França*
476
+
477
+ * Remove delegation of missing methods in a relation to private methods of the class.
478
+
479
+ *Rafael Mendonça França*
480
+
481
+ * Deprecate `config.activerecord.sqlite3.represent_boolean_as_integer`.
482
+
483
+ *Rafael Mendonça França*
484
+
485
+ * Change `SQLite3Adapter` to always represent boolean values as integers.
486
+
487
+ *Rafael Mendonça França*
488
+
489
+ * Remove ability to specify a timestamp name for `#cache_key`.
490
+
491
+ *Rafael Mendonça França*
492
+
493
+ * Remove deprecated `ActiveRecord::Migrator.migrations_path=`.
494
+
495
+ *Rafael Mendonça França*
496
+
497
+ * Remove deprecated `expand_hash_conditions_for_aggregates`.
498
+
499
+ *Rafael Mendonça França*
500
+
501
+ * Set polymorphic type column to NULL on `dependent: :nullify` strategy.
502
+
503
+ On polymorphic associations both the foreign key and the foreign type columns will be set to NULL.
504
+
505
+ *Laerti Papa*
506
+
507
+ * Allow permitted instance of `ActionController::Parameters` as argument of `ActiveRecord::Relation#exists?`.
508
+
509
+ *Gannon McGibbon*
510
+
511
+ * Add support for endless ranges introduces in Ruby 2.6.
512
+
513
+ *Greg Navis*
514
+
515
+ * Deprecate passing `migrations_paths` to `connection.assume_migrated_upto_version`.
516
+
517
+ *Ryuta Kamizono*
518
+
519
+ * MySQL: `ROW_FORMAT=DYNAMIC` create table option by default.
520
+
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.
524
+
525
+ *Ryuta Kamizono*
526
+
527
+ * Fix join table column quoting with SQLite.
528
+
529
+ *Gannon McGibbon*
530
+
531
+ * Allow disabling scopes generated by `ActiveRecord.enum`.
532
+
533
+ *Alfred Dominic*
534
+
535
+ * Ensure that `delete_all` on collection proxy returns affected count.
536
+
537
+ *Ryuta Kamizono*
538
+
539
+ * Reset scope after delete on collection association to clear stale offsets of removed records.
540
+
541
+ *Gannon McGibbon*
542
+
543
+ * Add the ability to prevent writes to a database for the duration of a block.
544
+
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.
548
+
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.
552
+
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.
556
+
557
+ *Eileen M. Uchitelle*
558
+
559
+ * Allow aliased attributes to be used in `#update_columns` and `#update`.
560
+
561
+ *Gannon McGibbon*
562
+
563
+ * Allow spaces in postgres table names.
564
+
565
+ Fixes issue where "user post" is misinterpreted as "\"user\".\"post\"" when quoting table names with the postgres adapter.
566
+
567
+ *Gannon McGibbon*
568
+
569
+ * Cached `columns_hash` fields should be excluded from `ResultSet#column_types`.
570
+
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:
573
+
574
+ ```ruby
575
+ class DeveloperName < ActiveRecord::Type::String
576
+ def deserialize(value)
577
+ "Developer: #{value}"
578
+ end
579
+ end
580
+
581
+ class AttributedDeveloper < ActiveRecord::Base
582
+ self.table_name = "developers"
583
+
584
+ attribute :name, DeveloperName.new
585
+
586
+ self.ignored_columns += ["name"]
587
+ end
588
+
589
+ developer = AttributedDeveloper.create
590
+ developer.update_column :name, "name"
591
+
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
+ ```
595
+
596
+ *Dmitry Tsepelev*
597
+
598
+ * Make the implicit order column configurable.
599
+
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.
606
+
607
+ Example:
608
+
609
+ class Project < ActiveRecord::Base
610
+ self.implicit_order_column = "created_at"
611
+ end
612
+
613
+ *Tekin Suleyman*
614
+
615
+ * Bump minimum PostgreSQL version to 9.3.
616
+
617
+ *Yasuo Honda*
618
+
619
+ * Values of enum are frozen, raising an error when attempting to modify them.
620
+
621
+ *Emmanuel Byrd*
622
+
623
+ * Move `ActiveRecord::StatementInvalid` SQL to error property and include binds as separate error property.
624
+
625
+ `ActiveRecord::ConnectionAdapters::AbstractAdapter#translate_exception_class` now requires `binds` to be passed as the last argument.
626
+
627
+ `ActiveRecord::ConnectionAdapters::AbstractAdapter#translate_exception` now requires `message`, `sql`, and `binds` to be passed as keyword arguments.
628
+
629
+ Subclasses of `ActiveRecord::StatementInvalid` must now provide `sql:` and `binds:` arguments to `super`.
630
+
631
+ Example:
632
+
633
+ ```
634
+ class MySubclassedError < ActiveRecord::StatementInvalid
635
+ def initialize(message, sql:, binds:)
636
+ super(message, sql: sql, binds: binds)
637
+ end
638
+ end
639
+ ```
640
+
641
+ *Gannon McGibbon*
642
+
643
+ * Add an `:if_not_exists` option to `create_table`.
644
+
645
+ Example:
646
+
647
+ create_table :posts, if_not_exists: true do |t|
648
+ t.string :title
649
+ end
650
+
651
+ That would execute:
652
+
653
+ CREATE TABLE IF NOT EXISTS posts (
654
+ ...
655
+ )
656
+
657
+ If the table already exists, `if_not_exists: false` (the default) raises an
658
+ exception whereas `if_not_exists: true` does nothing.
659
+
660
+ *fatkodima*, *Stefan Kanev*
661
+
662
+ * Defining an Enum as a Hash with blank key, or as an Array with a blank value, now raises an `ArgumentError`.
663
+
664
+ *Christophe Maximin*
665
+
666
+ * Adds support for multiple databases to `rails db:schema:cache:dump` and `rails db:schema:cache:clear`.
667
+
668
+ *Gannon McGibbon*
669
+
670
+ * `update_columns` now correctly raises `ActiveModel::MissingAttributeError`
671
+ if the attribute does not exist.
672
+
673
+ *Sean Griffin*
674
+
675
+ * Add support for hash and URL configs in database hash of `ActiveRecord::Base.connected_to`.
676
+
677
+ ````
678
+ User.connected_to(database: { writing: "postgres://foo" }) do
679
+ User.create!(name: "Gannon")
680
+ end
681
+
682
+ config = { "adapter" => "sqlite3", "database" => "db/readonly.sqlite3" }
683
+ User.connected_to(database: { reading: config }) do
684
+ User.count
685
+ end
686
+ ````
687
+
688
+ *Gannon McGibbon*
689
+
690
+ * Support default expression for MySQL.
691
+
692
+ MySQL 8.0.13 and higher supports default value to be a function or expression.
693
+
694
+ https://dev.mysql.com/doc/refman/8.0/en/create-table.html
695
+
696
+ *Ryuta Kamizono*
697
+
698
+ * Support expression indexes for MySQL.
699
+
700
+ MySQL 8.0.13 and higher supports functional key parts that index
701
+ expression values rather than column or column prefix values.
702
+
703
+ https://dev.mysql.com/doc/refman/8.0/en/create-index.html
704
+
705
+ *Ryuta Kamizono*
706
+
707
+ * Fix collection cache key with limit and custom select to avoid ambiguous timestamp column error.
708
+
709
+ Fixes #33056.
710
+
711
+ *Federico Martinez*
712
+
713
+ * Add basic API for connection switching to support multiple databases.
714
+
715
+ 1) Adds a `connects_to` method for models to connect to multiple databases. Example:
716
+
717
+ ```
718
+ class AnimalsModel < ApplicationRecord
719
+ self.abstract_class = true
720
+
721
+ connects_to database: { writing: :animals_primary, reading: :animals_replica }
722
+ end
723
+
724
+ class Dog < AnimalsModel
725
+ # connected to both the animals_primary db for writing and the animals_replica for reading
726
+ end
727
+ ```
728
+
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.
733
+
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
+ ```
740
+
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
+ ```
746
+
747
+ *Eileen M. Uchitelle*
748
+
749
+ * Enum raises on invalid definition values
750
+
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`.
755
+
756
+ Fixes #33961
757
+
758
+ *Alberto Almagro*
759
+
760
+ * Reloading associations now clears the Query Cache like `Persistence#reload` does.
761
+
762
+ ```
763
+ class Post < ActiveRecord::Base
764
+ has_one :category
765
+ belongs_to :author
766
+ has_many :comments
767
+ end
768
+
769
+ # Each of the following will now clear the query cache.
770
+ post.reload_category
771
+ post.reload_author
772
+ post.comments.reload
773
+ ```
774
+
775
+ *Christophe Maximin*
776
+
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.
780
+
781
+ Example:
782
+
783
+ change_table(:languages) do |t|
784
+ t.string :country_code, index: true
785
+ end
786
+
787
+ *Mehmet Emin İNAÇ*
788
+
789
+ * Fix `transaction` reverting for migrations.
790
+
791
+ Before: Commands inside a `transaction` in a reverted migration ran uninverted.
792
+ Now: This change fixes that by reverting commands inside `transaction` block.
793
+
794
+ *fatkodima*, *David Verhasselt*
795
+
796
+ * Raise an error instead of scanning the filesystem root when `fixture_path` is blank.
797
+
798
+ *Gannon McGibbon*, *Max Albrecht*
799
+
800
+ * Allow `ActiveRecord::Base.configurations=` to be set with a symbolized hash.
801
+
802
+ *Gannon McGibbon*
803
+
804
+ * Don't update counter cache unless the record is actually saved.
805
+
806
+ Fixes #31493, #33113, #33117.
807
+
808
+ *Ryuta Kamizono*
809
+
810
+ * Deprecate `ActiveRecord::Result#to_hash` in favor of `ActiveRecord::Result#to_a`.
811
+
812
+ *Gannon McGibbon*, *Kevin Cheng*
813
+
814
+ * SQLite3 adapter supports expression indexes.
815
+
816
+ ```
817
+ create_table :users do |t|
818
+ t.string :email
819
+ end
820
+
821
+ add_index :users, 'lower(email)', name: 'index_users_on_email', unique: true
822
+ ```
823
+
824
+ *Gray Kemmey*
825
+
826
+ * Allow subclasses to redefine autosave callbacks for associated records.
827
+
828
+ Fixes #33305.
829
+
830
+ *Andrey Subbota*
831
+
832
+ * Bump minimum MySQL version to 5.5.8.
833
+
834
+ *Yasuo Honda*
835
+
836
+ * Use MySQL utf8mb4 character set by default.
837
+
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.
840
+
841
+ *Yasuo Honda*
842
+
843
+ * Fix duplicated record creation when using nested attributes with `create_with`.
844
+
845
+ *Darwin Wu*
846
+
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.
851
+
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
+ ```
858
+
859
+ *Zhang Kang*, *Yoshiyuki Kinjo*
860
+
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`.
864
+
865
+ *Ryuta Kamizono*
866
+
867
+ * `ActiveRecord::Base.configurations` now returns an object.
868
+
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.
877
+
878
+ For example, the following `database.yml`:
879
+
880
+ ```
881
+ development:
882
+ adapter: sqlite3
883
+ database: db/development.sqlite3
884
+ ```
885
+
886
+ Used to become a hash:
887
+
888
+ ```
889
+ { "development" => { "adapter" => "sqlite3", "database" => "db/development.sqlite3" } }
890
+ ```
891
+
892
+ Is now converted into the following object:
893
+
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
+ ```
900
+
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.
907
+
908
+ ```
909
+ ActiveRecord::Base.configurations.configs_for(env_name: "development")
910
+ ActiveRecord::Base.configurations.configs_for(env_name: "development", spec_name: "primary")
911
+ ```
912
+
913
+ *Eileen M. Uchitelle*, *Aaron Patterson*
914
+
915
+ * Add database configuration to disable advisory locks.
916
+
917
+ ```
918
+ production:
919
+ adapter: postgresql
920
+ advisory_locks: false
921
+ ```
922
+
923
+ *Guo Xiang*
924
+
925
+ * SQLite3 adapter `alter_table` method restores foreign keys.
926
+
927
+ *Yasuo Honda*
928
+
929
+ * Allow `:to_table` option to `invert_remove_foreign_key`.
930
+
931
+ Example:
932
+
933
+ remove_foreign_key :accounts, to_table: :owners
934
+
935
+ *Nikolay Epifanov*, *Rich Chen*
936
+
937
+ * Add environment & load_config dependency to `bin/rake db:seed` to enable
938
+ seed load in environments without Rails and custom DB configuration
939
+
940
+ *Tobias Bielohlawek*
941
+
942
+ * Fix default value for mysql time types with specified precision.
943
+
944
+ *Nikolay Kondratyev*
945
+
946
+ * Fix `touch` option to behave consistently with `Persistence#touch` method.
947
+
948
+ *Ryuta Kamizono*
949
+
950
+ * Migrations raise when duplicate column definition.
951
+
952
+ Fixes #33024.
953
+
954
+ *Federico Martinez*
955
+
956
+ * Bump minimum SQLite version to 3.8
957
+
958
+ *Yasuo Honda*
959
+
960
+ * Fix parent record should not get saved with duplicate children records.
961
+
962
+ Fixes #32940.
963
+
964
+ *Santosh Wadghule*
965
+
966
+ * Fix logic on disabling commit callbacks so they are not called unexpectedly when errors occur.
967
+
968
+ *Brian Durand*
969
+
970
+ * Ensure `Associations::CollectionAssociation#size` and `Associations::CollectionAssociation#empty?`
971
+ use loaded association ids if present.
972
+
973
+ *Graham Turner*
974
+
975
+ * Add support to preload associations of polymorphic associations when not all the records have the requested associations.
976
+
977
+ *Dana Sherson*
978
+
979
+ * Add `touch_all` method to `ActiveRecord::Relation`.
980
+
981
+ Example:
982
+
983
+ Person.where(name: "David").touch_all(time: Time.new(2020, 5, 16, 0, 0, 0))
984
+
985
+ *fatkodima*, *duggiefresh*
986
+
987
+ * Add `ActiveRecord::Base.base_class?` predicate.
988
+
989
+ *Bogdan Gusiev*
990
+
991
+ * Add custom prefix/suffix options to `ActiveRecord::Store.store_accessor`.
992
+
993
+ *Tan Huynh*, *Yukio Mizuta*
994
+
995
+ * Rails 6 requires Ruby 2.5.0 or newer.
996
+
997
+ *Jeremy Daer*, *Kasper Timm Hansen*
998
+
999
+ * Deprecate `update_attributes`/`!` in favor of `update`/`!`.
1000
+
1001
+ *Eddie Lebow*
1002
+
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.
1005
+
1006
+ *DHH*
1007
+
1008
+ * Add `Relation#pick` as short-hand for single-value plucks.
1009
+
1010
+ *DHH*
1011
+
1012
+
1013
+ Please check [5-2-stable](https://github.com/rails/rails/blob/5-2-stable/activerecord/CHANGELOG.md) for previous changes.