aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/CHANGELOG.md
Commit message (Collapse)AuthorAgeFilesLines
* Convert the db:abort_if_pending_migrations task to be multi-DB awareMark Lee2019-06-101-0/+4
|
* Unify to use 4 spaces indentation in CHANGELOGs [ci skip]Ryuta Kamizono2019-06-051-4/+5
| | | | | Especially, somehow `CHANGELOG.md` in actiontext and activestorage in master branch had used 3 spaces indentation.
* Fix sqlite3 collation parsing when using decimal columns.Martin Schuster2019-06-041-0/+4
| | | | | | If an sqlite3 table contains a decimal column behind columns with a collation definition, then parsing the collation of all preceeding columns will fail -- the collation will be missed without notice.
* Fix invalid schema dump when primary key column has a commentGuilherme Goettems Schneider2019-06-031-0/+6
| | | | | | | | Before this fix it would either generate an invalid schema, passing `comment` option twice to `create_table`, or it move the comment from primary key column to the table if table had no comment when the dump was generated. The situation now is that a comment on primary key will be ignored (not present on schema). Fixes #29966
* Fix table comment also being applied to the primary key columnGuilherme Goettems Schneider2019-05-311-0/+4
|
* [skip ci] Fix missing punctuation mark and formattingVishal Telangre2019-05-131-1/+1
|
* Merge branch 'migration-timestamp-fix'Gannon McGibbon2019-05-101-0/+2
|\ | | | | | | Closes #28707.
| * Add class option timestamps to migration generatorMichael Duchemin2019-02-091-0/+4
| | | | | | | | Fixes GH#28706. Now rails g migration create_users and rails g model User have the same behavior for timestamps since they implement the same migration template. The expected behavior is that this create table migration will create the table with timestamps unless you pass --no-timestamps or --skip-timestamps to the generator. The expected migration should match what you get when you use the model generator. Using the migration generator, which doesn't have a class_option for timestamps would cause them to not be added to the migration file. Now the migration behavior of the migration generator, create_table only, is aligned with the migration behavior of the model generator. Also modified relevant example of ActiveRecord Migrations Guide.
* | Start Rails 6.1 developmentRafael Mendonça França2019-04-241-945/+1
| |
* | Adds touch option to has_one associationAbhay Nikam2019-04-251-0/+4
| |
* | Deprecate `where.not` working as NOR and will be changed to NAND in Rails 6.1Ryuta Kamizono2019-04-191-0/+41
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | `where.not` with polymorphic association is partly fixed incidentally at 213796f (refer #33493, #26207, #17010, #16983, #14161), and I've added test case e9ba12f to avoid lose that fix accidentally in the future. In Rails 5.2, `where.not(polymorphic: object)` works as expected as NAND, but `where.not(polymorphic_type: object.class.polymorphic_name, polymorphic_id: object.id)` still unexpectedly works as NOR. To will make `where.not` working desiredly as NAND in Rails 6.1, this deprecates `where.not` working as NOR. If people want to continue NOR conditions, we'd encourage to them to `where.not` each conditions manually. ```ruby all = [treasures(:diamond), treasures(:sapphire), cars(:honda), treasures(:sapphire)] assert_equal all, PriceEstimate.all.map(&:estimate_of) ``` In Rails 6.0: ```ruby sapphire = treasures(:sapphire) nor = all.reject { |e| e.estimate_of_type == sapphire.class.polymorphic_name }.reject { |e| e.estimate_of_id == sapphire.id } assert_equal [cars(:honda)], nor without_sapphire = PriceEstimate.where.not( estimate_of_type: sapphire.class.polymorphic_name, estimate_of_id: sapphire.id ) assert_equal nor, without_sapphire.map(&:estimate_of) ``` In Rails 6.1: ```ruby sapphire = treasures(:sapphire) nand = all - [sapphire] assert_equal [treasures(:diamond), cars(:honda)], nand without_sapphire = PriceEstimate.where.not( estimate_of_type: sapphire.class.polymorphic_name, estimate_of_id: sapphire.id ) assert_equal nand, without_sapphire.map(&:estimate_of) ``` Resolves #31209.
* | Merge pull request #35987 from kamipo/fix_dirty_tracking_after_rollbackRyuta Kamizono2019-04-171-0/+6
|\ \ | | | | | | | | | Fix dirty tracking after rollback.
| * | Fix dirty tracking after rollback.Ryuta Kamizono2019-04-161-0/+6
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Currently the rollback only restores primary key value, `new_record?`, `destroyed?`, and `frozen?`. Since the `save` clears current dirty attribute states, retrying save after rollback will causes no change saved if partial writes is enabled (by default). This makes `remember_transaction_record_state` remembers original values then restores dirty attribute states after rollback. Fixes #15018. Fixes #30167. Fixes #33868. Fixes #33443. Closes #33444. Closes #34504.
* | | Add collection cache versioningLachlan Sylvester2019-04-161-0/+11
|/ / | | | | | | | | | | | | | | | | | | | | | | | | | | | | Cache versioning enables the same cache key to be reused when the object being cached changes by moving the volatile part of the cache key out of the cache key and into a version that is embedded in the cache entry. This is already occurring when the object being cached is an `ActiveRecord::Base`, but when caching an `ActiveRecord::Relation` we are currently still putting the volatile information (max updated at and count) as part of the cache key. This PR moves the volatile part of the relations `cache_key` into the `cache_version` to support recycling cache keys for `ActiveRecord::Relation`s.
* | Add CHANGELOG entry for d1107f4d1e2573948d4941ac44511a0af6241f80Ryuta Kamizono2019-04-161-1/+7
| | | | | | | | [ci skip]
* | make change_column_comment and change_table_comment invertibleYoshiyuki Kinjo2019-04-151-0/+5
| | | | | | | | | | | | | | | | | | We can revert migrations using `change_column_comment` or `change_table_comment` at current master. However, results are not what we expect: comments are remained in new status. This change tells previous comment to these methods in a way like `change_column_default`.
* | Don't call after_commit callbacks despite a record isn't savedRyuta Kamizono2019-04-121-0/+6
| | | | | | | | | | | | | | | | | | | | | | Regardless of a record isn't saved (e.g. validation is failed), `after_commit` / `after_rollback` callbacks are invoked for now. To fix the issue, this adds a record to the current transaction only when a record is actually saved. Fixes #29747. Closes #29833.
* | Merge pull request #28155 from lcreid/belongs_toRyuta Kamizono2019-04-101-0/+14
|\ \ | | | | | | | | | Fix "autosave: true" on belongs_to of join model causes invalid records to be saved
| * | Fix circular `autosave: true`Larry Reid2018-07-231-0/+17
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Use a variable local to the `save_collection_association` method in `activerecord/lib/active_record/autosave_association.rb`, instead of an instance variable. Prior to this PR, when there was a circular series of `autosave: true` associations, the callback for a `has_many` association was run while another instance of the same callback on the same association hadn't finished running. When control returned to the first instance of the callback, the instance variable had changed, and subsequent associated records weren't saved correctly. Specifically, the ID field for the `belongs_to` corresponding to the `has_many` was `nil`. Remove unnecessary test and comments. Fixes #28080.
* | | Raise `ArgumentError` for invalid `:limit` and `:precision` like as other ↵Ryuta Kamizono2019-04-071-0/+22
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | options When I've added new `:size` option in #35071, I've found that invalid `:limit` and `:precision` raises `ActiveRecordError` unlike other invalid options. I think that is hard to distinguish argument errors and statement invalid errors since the `StatementInvalid` is a subclass of the `ActiveRecordError`. https://github.com/rails/rails/blob/c9e4c848eeeb8999b778fa1ae52185ca5537fffe/activerecord/lib/active_record/errors.rb#L103 ```ruby begin # execute any migration rescue ActiveRecord::StatementInvalid # statement invalid rescue ActiveRecord::ActiveRecordError, ArgumentError # `ActiveRecordError` except `StatementInvalid` is maybe an argument error end ``` I'd say this is the inconsistency worth fixing. Before: ```ruby add_column :items, :attr1, :binary, size: 10 # => ArgumentError add_column :items, :attr2, :decimal, scale: 10 # => ArgumentError add_column :items, :attr3, :integer, limit: 10 # => ActiveRecordError add_column :items, :attr4, :datetime, precision: 10 # => ActiveRecordError ``` After: ```ruby add_column :items, :attr1, :binary, size: 10 # => ArgumentError add_column :items, :attr2, :decimal, scale: 10 # => ArgumentError add_column :items, :attr3, :integer, limit: 10 # => ArgumentError add_column :items, :attr4, :datetime, precision: 10 # => ArgumentError ```
* | | Association loading isn't to be affected by scoping consistentlyRyuta Kamizono2019-04-051-0/+27
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Follow-up of 5c71000, #29834, and #30271. Currently, preloading and eager loading are not to be affected by scoping, with the exception of `unscoped`. But non eager loaded association access is still affected by scoping. Although this is a breaking change, the association loading will work consistently whether preloaded / eager loaded or not. Before: ```ruby Post.where("1=0").scoping do Comment.find(1).post # => nil Comment.preload(:post).find(1).post # => #<Post id: 1, ...> Comment.eager_load(:post).find(1).post # => #<Post id: 1, ...> end ``` After: ```ruby Post.where("1=0").scoping do Comment.find(1).post # => #<Post id: 1, ...> Comment.preload(:post).find(1).post # => #<Post id: 1, ...> Comment.eager_load(:post).find(1).post # => #<Post id: 1, ...> end ``` Fixes #34638. Fixes #35398.
* | | [ci skip] Touch up `db:prepare` changelog entryKasper Timm Hansen2019-04-031-1/+3
| | |
* | | Add rake db:prepare entry to the CHANGELOG.mdRoberto Miranda2019-04-031-0/+4
| | |
* | | Use official database name [ci skip]Ryuta Kamizono2019-04-031-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | * s/Postgres/PostgreSQL/ * s/MYSQL/MySQL/, s/Mysql/MySQL/ * s/Sqlite/SQLite/ Replaced all newly added them after 6089b31.
* | | Remove duplicated CHANGELOG entry [ci skip]Ryuta Kamizono2019-04-031-2/+0
| | |
* | | Add `after_save_commit` callback as shortcut for `after_commit :hook, on: [ ↵David Heinemeier Hansson2019-04-021-0/+6
| | | | | | | | | | | | :create, :update ]`. (#35804)
* | | url -> URL where apt except inside actionpack/Sharang Dashputre2019-04-011-2/+2
| | |
* | | Follow up tweaks b89a3e7e638a50c648a17d09c48b49b707e1d90d [ci skip]Ryuta Kamizono2019-03-311-5/+5
| | | | | | | | | | | | | | | | | | * use backticks instead of `+` * and more (e.g. missed replacing `Array#excluding` and `Enumerable#excluding` in b89a3e7e638a50c648a17d09c48b49b707e1d90d)
* | | Merge pull request #35799 from leboshi/masterRyuta Kamizono2019-03-311-0/+7
|\ \ \ | | | | | | | | | | | | Fix callbacks on has_many :through associations
| * | | Fix callbacks on has_many :through associations (#33249)Ryan Kerr2019-03-301-0/+7
|/ / / | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | When adding a child record via a has_many :through association, build_through_record would previously build the join record, and then assign the child record and source_type option to it. Because the before_add and after_add callbacks are called as part of build, however, this caused the callbacks to receive incomplete records, specifically without the other end of the has_many :through association. Collecting all attributes before building the join record ensures the callbacks receive the fully constructed record.
* | | Add `ActiveRecord::Relation#extract_associated` for extracting associated ↵David Heinemeier Hansson2019-03-291-0/+9
| | | | | | | | | | | | | | | record (#35784) * Add `ActiveRecord::Relation#extract_associated` for extracting associated records from a relation
* | | [ci skip] Fixed typoChirag Shah2019-03-251-1/+1
| | |
* | | Add Relation#annotate for SQL commentingMatt Yoho2019-03-211-0/+13
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This patch has two main portions: 1. Add SQL comment support to Arel via Arel::Nodes::Comment. 2. Implement a Relation#annotate method on top of that. == Adding SQL comment support Adds a new Arel::Nodes::Comment node that represents an optional SQL comment and teachers the relevant visitors how to handle it. Comment nodes may be added to the basic CRUD statement nodes and set through any of the four (Select|Insert|Update|Delete)Manager objects. For example: manager = Arel::UpdateManager.new manager.table table manager.comment("annotation") manager.to_sql # UPDATE "users" /* annotation */ This new node type will be used by ActiveRecord::Relation to enable query annotation via SQL comments. == Implementing the Relation#annotate method Implements `ActiveRecord::Relation#annotate`, which accepts a comment string that will be appeneded to any queries generated by the relation. Some examples: relation = Post.where(id: 123).annotate("metadata string") relation.first # SELECT "posts".* FROM "posts" WHERE "posts"."id" = 123 # LIMIT 1 /* metadata string */ class Tag < ActiveRecord::Base scope :foo_annotated, -> { annotate("foo") } end Tag.foo_annotated.annotate("bar").first # SELECT "tags".* FROM "tags" LIMIT 1 /* foo */ /* bar */ Also wires up the plumbing so this works with `#update_all` and `#delete_all` as well. This feature is useful for instrumentation and general analysis of queries generated at runtime.
* | | Support Optimizer HintsRyuta Kamizono2019-03-161-0/+25
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | We as Arm Treasure Data are using Optimizer Hints with a monkey patch (https://gist.github.com/kamipo/4c8539f0ce4acf85075cf5a6b0d9712e), especially in order to use `MAX_EXECUTION_TIME` (refer #31129). Example: ```ruby class Job < ApplicationRecord default_scope { optimizer_hints("MAX_EXECUTION_TIME(50000) NO_INDEX_MERGE(jobs)") } end ``` Optimizer Hints is supported not only for MySQL but also for most databases (PostgreSQL on RDS, Oracle, SQL Server, etc), it is really helpful to turn heavy queries for large scale applications.
* | | Merge tag 'v6.0.0.beta3'eileencodes2019-03-131-0/+5
|\ \ \ | | | | | | | | | | | | v6.0.0.beta3 release
| * | | Prep releaseeileencodes2019-03-111-0/+5
| | | | | | | | | | | | | | | | | | | | | | | | | | | | * Update RAILS_VERSION * Bundle * rake update_versions * rake changelog:header
* | | | 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`