aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/CHANGELOG.md
Commit message (Collapse)AuthorAgeFilesLines
* Merge pull request #35320 from ↵Ryuta Kamizono2019-03-111-0/+14
|\ | | | | | | | | | | kamille-gz/fix_query_method_when_given_Date_data_type Fix ActiveRecord query attribute method when given value does't respond to to_i method
| * Fix query attribute method on user-defined attribute to be aware of ↵kamille-3212019-03-111-0/+14
|/ | | | | | | | | | typecasted value change the line to check an attribute has user-defined type ref: https://github.com/rails/rails/pull/35320#discussion_r257924552 check query attribute method is working when given value does not respond to to_i method
* Quote empty ranges like other empty enumerablesPatrick Rebsch2019-03-071-0/+4
|
* Add insert_all to ActiveRecord models (#35077)Bob Lail2019-03-051-0/+10
| | | | | Adds a method to ActiveRecord allowing records to be inserted in bulk without instantiating ActiveRecord models. This method supports options for handling uniqueness violations by skipping duplicate records or overwriting them in an UPSERT operation. ActiveRecord already supports bulk-update and bulk-destroy actions that execute SQL UPDATE and DELETE commands directly. It also supports bulk-read actions through `pluck`. It makes sense for it also to support bulk-creation.
* Allow `truncate` for SQLite3 adapter and add `rails db:seed:replant` (#34779)Bogdan2019-03-041-0/+9
| | | | | | | | | | | | | * Add `ActiveRecord::Base.connection.truncate` for SQLite3 adapter. SQLite doesn't support `TRUNCATE TABLE`, but SQLite3 adapter can support `ActiveRecord::Base.connection.truncate` by using `DELETE FROM`. `DELETE` without `WHERE` uses "The Truncate Optimization", see https://www.sqlite.org/lang_delete.html. * Add `rails db:seed:replant` that truncates database tables and loads the seeds Closes #34765
* Fix typo in CHANGELOG.md [ci skip]Sharang Dashputre2019-03-041-1/+1
|
* Deprecate mismatched collation comparison for uniquness validatorRyuta Kamizono2019-03-041-0/+8
| | | | | | | | | | | | | | | | | | | | | In MySQL, the default collation is case insensitive. Since the uniqueness validator enforces case sensitive comparison by default, it frequently causes mismatched collation issues (performance, weird behavior, etc) to MySQL users. https://grosser.it/2009/12/11/validates_uniqness_of-mysql-slow/ https://github.com/rails/rails/issues/1399 https://github.com/rails/rails/pull/13465 https://github.com/gitlabhq/gitlabhq/commit/c1dddf8c7d947691729f6d64a8ea768b5c915855 https://github.com/huginn/huginn/pull/1330#discussion_r55152573 I'd like to deprecate the implicit default enforcing since I frequently experienced the problems in code reviews. Note that this change has no effect to sqlite3, postgresql, and oracle-enhanced adapters which are implemented as case sensitive by default, only affect to mysql2 adapter (I can take a work if sqlserver adapter will support Rails 6.0).
* Move changelog entry about `reselect` method to the section of the next releasebogdanvlviv2019-03-041-9/+9
| | | | | | | Fixes https://github.com/rails/rails/pull/33611#discussion_r261549790 Related to https://3.basecamp.com/3076981/buckets/24956/chats/12416418@1631552581 [ci skip]
* Merge pull request #33611 from willianveiga/feature/reselect-methodAndrew White2019-03-011-0/+6
|\ | | | | Add reselect method
| * Merge branch 'master' into feature/reselect-methodWillian Gustavo Veiga2018-10-171-1/+9
| |\
| * \ Merge branch 'master' into feature/reselect-methodWillian Gustavo Veiga2018-10-111-0/+64
| |\ \
| * | | Add changelog entryWillian Gustavo Veiga2018-10-021-0/+4
| | | |
* | | | Add negative scopes for all enum values (#35381)David Heinemeier Hansson2019-02-261-0/+14
| | | | | | | | | | | | Add negative scopes for all enum values
* | | | Merge pull request #35361 from ↵Ryuta Kamizono2019-02-271-0/+7
|\ \ \ \ | | | | | | | | | | | | | | | | | | | | | | | | | jvillarejo/fix_wrong_size_query_with_distinct_select Fix different `count` calculation when using `size` with DISTINCT `select`
| * | | | fixes different `count` calculation when using `size` manual `select` with ↵jvillarejo2019-02-261-0/+6
|/ / / / | | | | | | | | | | | | | | | | | | | | | | | | | | | | DISTINCT When using `select` with `'DISTINCT( ... )'` if you use method `size` on a non loaded relation it overrides the column selected by passing `:all` so it returns different value than count. This fixes #35214
* | | | Preparing for 6.0.0.beta2 releaseRafael Mendonça França2019-02-251-0/+2
| | | |
* | | | Fix prepared statements caching to be enabled even when query caching is enabledRyuta Kamizono2019-02-261-0/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Related cbcdecd, 2a56b2d. This is a regression caused by cbcdecd. If query caching is enabled, prepared statement handles are never re-used, since we missed that a query is preprocessed when query caching is enabled, but doesn't keep the `preparable` flag. We should care about that case.
* | | | Ensure `update_all` series cares about optimistic lockingRyuta Kamizono2019-02-251-0/+4
| | | | | | | | | | | | | | | | | | | | | | | | Incrementing the lock version invalidates any other process's optimistic lock, which is the desired outcome: the record no longer looks the same as it did when they loaded it.
* | | | Don't allow `where` with non numeric string matches to 0 valuesRyuta Kamizono2019-02-201-0/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This is a follow-up of #35310. Currently `Topic.find_by(id: "not-a-number")` matches to a `id = 0` record. That is considered as silently leaking information. If non numeric string is given to find by an integer column, it should not be matched to any record. Related #12793.
* | | | Merge pull request #35316 from abhaynikam/35304-add-delete_by_and_destroy_byRyuta Kamizono2019-02-191-0/+26
|\ \ \ \ | | | | | | | | | | | | | | | Introduce delete_by and destroy_by methods to ActiveRecord::Relation
| * | | | Introduce delete_by and destroy_by methods to ActiveRecord::RelationAbhay Nikam2019-02-191-0/+26
|/ / / /
* | | | Don't allow `where` with invalid value matches to nil valuesRyuta Kamizono2019-02-181-0/+6
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | That is considered as silently leaking information. If type casting doesn't return any actual value, it should not be matched to any record. Fixes #33624. Closes #33946.
* | | | Add changelog entry for #35212Ryuta Kamizono2019-02-161-0/+4
| | | | | | | | | | | | | | | | [ci skip]
* | | | Deprecate using class level querying methods if the receiver scope regarded ↵Ryuta Kamizono2019-02-151-0/+5
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | as leaked This deprecates using class level querying methods if the receiver scope regarded as leaked, since #32380 and #35186 may cause that silently leaking information when people upgrade the app. We need deprecation first before making those.
* | | | Revert "Merge pull request #35186 from ↵Ryuta Kamizono2019-02-151-6/+0
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | kamipo/fix_leaking_scope_on_relation_create" This reverts commit b67d5c6dedbf033515a96a95d24d085bf99a0d07, reversing changes made to 2e018361c7c51e36d1d98bf770b7456d78dee68b. Reason: #35186 may cause that silently leaking information when people upgrade the app. We need deprecation first before making this.
* | | | Minor changes to deprecation warning message after 35242Abhay Nikam2019-02-151-2/+2
| | | |
* | | | Revert "Chaining named scope is no longer leaking to class level querying ↵Ryuta Kamizono2019-02-141-6/+0
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | methods" This reverts #32380, since this may cause that silently leaking information when people upgrade the app. We need deprecation first before making this.
* | | | Update CHANGELOG for database_resolver_contextJohn Hawthorn2019-02-071-2/+2
| | | |
* | | | Fix `relation.create` to avoid leaking scope to initialization block and ↵Ryuta Kamizono2019-02-071-0/+6
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | callbacks `relation.create` populates scope attributes to new record by `scoping`, it is necessary to assign the scope attributes to the record and to find STI subclass from the scope attributes. But the effect of `scoping` is class global, it was caused undesired behavior that pollute all class level querying methods in initialization block and callbacks (`after_initialize`, `before_validation`, `before_save`, etc), which are user provided code. To avoid the leaking scope issue, restore the original current scope before initialization block and callbacks are invoked. Fixes #9894. Fixes #17577. Closes #31526.
* | | | Chaining named scope is no longer leaking to class level querying methodsRyuta Kamizono2019-02-061-0/+6
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Active Record uses `scoping` to delegate to named scopes from relations for propagating the chaining source scope. It was needed to restore the source scope in named scopes, but it was caused undesired behavior that pollute all class level querying methods. Example: ```ruby class Topic < ActiveRecord::Base scope :toplevel, -> { where(parent_id: nil) } scope :children, -> { where.not(parent_id: nil) } scope :has_children, -> { where(id: Topic.children.select(:parent_id)) } end # Works as expected. Topic.toplevel.where(id: Topic.children.select(:parent_id)) # Doesn't work due to leaking `toplevel` to `Topic.children`. Topic.toplevel.has_children ``` Since #29301, the receiver in named scopes has changed from the model class to the chaining source scope, so the polluting class level querying methods is no longer required for that purpose. Fixes #14003.
* | | | Adds basic automatic database switching to RailsEileen Uchitelle2019-01-301-0/+33
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The following PR adds behavior to Rails to allow an application to automatically switch it's connection from the primary to the replica. A request will be sent to the replica if: * The request is a read request (`GET` or `HEAD`) * AND It's been 2 seconds since the last write to the database (because we don't want to send a user to a replica if the write hasn't made it to the replica yet) A request will be sent to the primary if: * It's not a GET/HEAD request (ie is a POST, PATCH, etc) * Has been less than 2 seconds since the last write to the database The implementation that decides when to switch reads (the 2 seconds) is "safe" to use in production but not recommended without adequate testing with your infrastructure. At GitHub in addition to the a 5 second delay we have a curcuit breaker that checks the replication delay and will send the query to a replica before the 5 seconds has passed. This is specific to our application and therefore not something Rails should be doing for you. You'll need to test and implement more robust handling of when to switch based on your infrastructure. The auto switcher in Rails is meant to be a basic implementation / API that acts as a guide for how to implement autoswitching. The impementation here is meant to be strict enough that you know how to implement your own resolver and operations classes but flexible enough that we're not telling you how to do it. The middleware is not included automatically and can be installed in your application with the classes you want to use for the resolver and operations passed in. If you don't pass any classes into the middleware the Rails default Resolver and Session classes will be used. The Resolver decides what parameters define when to switch, Operations sets timestamps for the Resolver to read from. For example you may want to use cookies instead of a session so you'd implement a Resolver::Cookies class and pass that into the middleware via configuration options. ``` config.active_record.database_selector = { delay: 2.seconds } config.active_record.database_resolver = MyResolver config.active_record.database_operations = MyResolver::MyCookies ``` Your classes can inherit from the existing classes and reimplment the methods (or implement more methods) that you need to do the switching. You only need to implement methods that you want to change. For example if you wanted to set the session token for the last read from a replica you would reimplement the `read_from_replica` method in your resolver class and implement a method that updates a new timestamp in your operations class.
* | | | Allow changing text and blob size without giving the `limit` optionRyuta Kamizono2019-01-291-0/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | In MySQL, the text column size is 65,535 bytes by default (1 GiB in PostgreSQL). It is sometimes too short when people want to use a text column, so they sometimes change the text size to mediumtext (16 MiB) or longtext (4 GiB) by giving the `limit` option. Unlike MySQL, PostgreSQL doesn't allow the `limit` option for a text column (raises ERROR: type modifier is not allowed for type "text"). So `limit: 4294967295` (longtext) couldn't be used in Action Text. I've allowed changing text and blob size without giving the `limit` option, it prevents that migration failure on PostgreSQL.
* | | | Make `t.timestamps` with precision by defaultRyuta Kamizono2019-01-261-0/+5
| | | |
* | | | Preparing for 6.0.0.beta1 releaseRafael Mendonça França2019-01-181-0/+2
| | | |
* | | | Merge pull request #34966 from ↵Rafael Mendonça França2019-01-171-1/+1
|\ \ \ \ | | | | | | | | | | | | | | | | | | | | | | | | | bogdanvlviv/ensure-ar-relation-exists-allows-permitted-params Ensure that AR::Relation#exists? allows only permitted params
| * | | | Ensure that AR::Relation#exists? allows only permitted paramsbogdanvlviv2019-01-171-4/+4
| | | | | | | | | | | | | | | | | | | | | | | | | Clarify changelog entry Related to #34891
* | | | | Remove deprecated `#set_state` from the transaction objectRafael Mendonça França2019-01-171-0/+4
| | | | |
* | | | | Remove deprecated `#supports_statement_cache?` from the database adaptersRafael Mendonça França2019-01-171-0/+4
| | | | |
* | | | | Remove deprecated `#insert_fixtures` from the database adaptersRafael Mendonça França2019-01-171-0/+4
| | | | |
* | | | | Remove deprecated ↵Rafael Mendonça França2019-01-171-0/+4
| | | | | | | | | | | | | | | | | | | | `ActiveRecord::ConnectionAdapters::SQLite3Adapter#valid_alter_table_type?`
* | | | | Do not allow passing the column name to `sum` when a block is passedRafael Mendonça França2019-01-171-0/+4
| | | | |
* | | | | Do not allow passing the column name to `count` when a block is passedRafael Mendonça França2019-01-171-0/+4
| | | | |
* | | | | Remove delegation of missing methods in a relation to arelRafael Mendonça França2019-01-171-0/+4
| | | | |
* | | | | Remove delegation of missing methods in a relation to private methods of the ↵Rafael Mendonça França2019-01-171-0/+4
| | | | | | | | | | | | | | | | | | | | class
* | | | | Change `SQLite3Adapter` to always represent boolean values as integersRafael Mendonça França2019-01-171-0/+8
| | | | |
* | | | | Remove ability to specify a timestamp name for `#cache_key`Rafael Mendonça França2019-01-171-0/+4
| | | | |
* | | | | Remove deprecated `ActiveRecord::Migrator.migrations_path=`Rafael Mendonça França2019-01-171-0/+4
| | | | |
* | | | | Remove deprecated `expand_hash_conditions_for_aggregates`Rafael Mendonça França2019-01-171-3/+7
|/ / / /
* | | | Refs #28025 nullify *_type column on polymorphic associations on :nu… ↵Laerti2019-01-151-0/+5
| | | | | | | | | | | | | | | | | | | | | | | | (#28078) This PR addresses the issue described in #28025. On `dependent: :nullify` strategy only the foreign key of the relation is nullified. However on polymorphic associations the `*_type` column is not nullified leaving the record with a NULL `*_id` but the `*_type` column is present.
* | | | Merge branch 'master' into ac_params_existsAaron Patterson2019-01-111-0/+5
|\ \ \ \