aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord
Commit message (Collapse)AuthorAgeFilesLines
...
| * | | | | | Make implicit order column configurableTekin Suleyman2018-11-264-2/+45
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | When calling ordered finder methods such as +first+ or +last+ without an explicit order clause, ActiveRecord sorts records by primary key. This can result in unpredictable and surprising behaviour when the primary key is not an auto-incrementing integer, for example when it's a UUID. This change makes it possible to override the column used for implicit ordering such that +first+ and +last+ will return more predictable results. For Example: class Project < ActiveRecord::Base self.implicit_order_column = "created_at" end
* | | | | | | Revert "We still need the `Helpers` constant in the `ActiveRecord` namespace"Ryuta Kamizono2018-11-271-1/+0
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This reverts commit d52f74480ae46cd3de7ce697093136b01c7a2172. Since 24adc20, the `Helpers` constant in the `ActiveRecord` namespace is not referenced anymore.
* | | | | | | `Mutable` helper is in `ActiveModel`Ryuta Kamizono2018-11-274-4/+4
|/ / / / / / | | | | | | | | | | | | | | | | | | It should be referenced by full qualified name from Active Record.
* | | | | | Merge pull request #34520 from yahonda/bump_pg93Rafael França2018-11-268-402/+382
|\ \ \ \ \ \ | | | | | | | | | | | | | | Bump the minimum version of PostgreSQL to 9.3
| * | | | | | Bump the minimum version of PostgreSQL to 9.3Yasuo Honda2018-11-258-402/+382
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | https://www.postgresql.org/support/versioning/ - 9.1 EOLed on September 2016. - 9.2 EOLed on September 2017. 9.3 is also not supported since Nov 8, 2018. https://www.postgresql.org/about/news/1905/ I think it may be a little bit early to drop PostgreSQL 9.3 yet. * Deprecated `supports_ranges?` since no other databases support range data type * Add `supports_materialized_views?` to abstract adapter Materialized views itself is supported by other databases, other connection adapters may support them * Remove `with_manual_interventions` It was only necessary for PostgreSQL 9.1 or earlier * Drop CI against PostgreSQL 9.2
* | | | | | | Merge pull request #34521 from azbshiri/mysql-exec-query-resultEileen M. Uchitelle2018-11-262-2/+15
|\ \ \ \ \ \ \ | |_|/ / / / / |/| | | | | | Test when using MySQL `exec_query` returns `ActiveRecord::Result` all…
| * | | | | | When running exec_query MySQL always returns ActiveRecord::ResultAlireza Bashiri2018-11-252-2/+15
| |/ / / / / | | | | | | | | | | | | | | | | | | | | | | | | When running `exec_query` with `INSERT` (or other write commands), MySQL returns `ActiveRecord::Result`.
* | | | | | Fix random CI failure due to non-deterministic sorting orderRyuta Kamizono2018-11-261-2/+2
| | | | | | | | | | | | | | | | | | | | | | | | https://travis-ci.org/rails/rails/jobs/459534536#L1280
* | | | | | SQLite 3.7.16+ returns the order of the primary key columnsYasuo Honda2018-11-251-2/+0
|/ / / / / | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | https://www.sqlite.org/releaselog/3_7_16.html > 9 Enhance the PRAGMA table_info command so that the "pk" column is an increasing integer to show the order of columns in the primary key. Rails 6 supports SQLite 3.8 then we can remove this skip condition.
* | | | | Raises error when attempting to modify enum valuesebyrds2018-11-233-0/+19
| | | | |
* | | | | Merge pull request #34468 from gmcgibbon/redact_sql_in_errorsRafael França2018-11-239-58/+112
|\ \ \ \ \ | | | | | | | | | | | | Redact SQL in errors
| * | | | | Redact SQL in errorsGannon McGibbon2018-11-229-58/+112
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Move `ActiveRecord::StatementInvalid` SQL to error property. Also add bindings as an error property.
* | | | | | Use squiggly heredoc to strip odd indentation in the executed SQLRyuta Kamizono2018-11-2219-91/+81
|/ / / / / | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Before: ``` LOG: execute <unnamed>: SELECT t.oid, t.typname FROM pg_type as t WHERE t.typname IN ('int2', 'int4', 'int8', 'oid', 'float4', 'float8', 'bool') LOG: execute <unnamed>: SELECT t.oid, t.typname, t.typelem, t.typdelim, t.typinput, r.rngsubtype, t.typtype, t.typbasetype FROM pg_type as t LEFT JOIN pg_range as r ON oid = rngtypid WHERE t.typname IN ('int2', 'int4', 'int8', 'oid', 'float4', 'float8', 'text', 'varchar', 'char', 'name', 'bpchar', 'bool', 'bit', 'varbit', 'timestamptz', 'date', 'money', 'bytea', 'point', 'hstore', 'json', 'jsonb', 'cidr', 'inet', 'uuid', 'xml', 'tsvector', 'macaddr', 'citext', 'ltree', 'interval', 'path', 'line', 'polygon', 'circle', 'lseg', 'box', 'time', 'timestamp', 'numeric') OR t.typtype IN ('r', 'e', 'd') OR t.typinput::varchar = 'array_in' OR t.typelem != 0 LOG: statement: SHOW TIME ZONE LOG: statement: SELECT 1 LOG: execute <unnamed>: SELECT COUNT(*) FROM pg_class c LEFT JOIN pg_namespace n ON n.oid = c.relnamespace WHERE c.relkind IN ('r','v','m') -- (r)elation/table, (v)iew, (m)aterialized view AND c.relname = 'accounts' AND n.nspname = ANY (current_schemas(false)) ``` After: ``` LOG: execute <unnamed>: SELECT t.oid, t.typname FROM pg_type as t WHERE t.typname IN ('int2', 'int4', 'int8', 'oid', 'float4', 'float8', 'bool') LOG: execute <unnamed>: SELECT t.oid, t.typname, t.typelem, t.typdelim, t.typinput, r.rngsubtype, t.typtype, t.typbasetype FROM pg_type as t LEFT JOIN pg_range as r ON oid = rngtypid WHERE t.typname IN ('int2', 'int4', 'int8', 'oid', 'float4', 'float8', 'text', 'varchar', 'char', 'name', 'bpchar', 'bool', 'bit', 'varbit', 'timestamptz', 'date', 'money', 'bytea', 'point', 'hstore', 'json', 'jsonb', 'cidr', 'inet', 'uuid', 'xml', 'tsvector', 'macaddr', 'citext', 'ltree', 'interval', 'path', 'line', 'polygon', 'circle', 'lseg', 'box', 'time', 'timestamp', 'numeric') OR t.typtype IN ('r', 'e', 'd') OR t.typinput::varchar = 'array_in' OR t.typelem != 0 LOG: statement: SHOW TIME ZONE LOG: statement: SELECT 1 LOG: execute <unnamed>: SELECT COUNT(*) FROM pg_class c LEFT JOIN pg_namespace n ON n.oid = c.relnamespace WHERE c.relkind IN ('r','v','m') -- (r)elation/table, (v)iew, (m)aterialized view AND c.relname = 'accounts' AND n.nspname = ANY (current_schemas(false)) ```
* | | | | Fixing an issue when parsing an opclass by allowing indexed columnThomas Bianchini2018-11-212-1/+13
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | in indexdef to be wrapped up by double quotes Fixes #34493. *Thomas Bianchini*
* | | | | Merge pull request #34491 from rails/fix-query-cache-on-multiple-connectionsEileen M. Uchitelle2018-11-212-4/+27
|\ \ \ \ \ | | | | | | | | | | | | Fix query cache for multiple connections
| * | | | | Fix query cache for multiple connectionsEileen Uchitelle2018-11-202-4/+27
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Currently the query cache is only aware of one handler so once we added multiple databases switching on the handler we broke query cache for those reading connections. While #34054 is the proper fix, that fix is not straight forward and I want to make sure that the query cache isn't just broken for all other connections not in the main handler.
* | | | | | Make connection handler per thread instead of per fiberEileen Uchitelle2018-11-202-2/+39
|/ / / / / | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The connection handler was using the RuntimeRegistry which kind of implies it's a per thread registry. But it's actually per fiber. If you have an application that uses fibers and you're using multiple databases, when you switch the connection handler to swap connections new fibers running on the same thread used to get a different connection id. This PR changes the code to actually use a thread so that we get the same connection. Fixes https://github.com/rails/rails/issues/30047 [Eileen M. Uchitelle, Aaron Patterson, & Arthur Neeves]
* | | | | Merge pull request #33954 from ↵Aaron Patterson2018-11-204-3/+43
|\ \ \ \ \ | | | | | | | | | | | | | | | | | | | | | | | | febeling/inconsistent-assignment-has-many-through-33942 Fix handling of duplicates for `replace` on has_many-through
| * | | | | Optimize difference and intersectionFlorian Ebeling2018-11-061-17/+9
| | | | | |
| * | | | | Rename union to intersectionFlorian Ebeling2018-11-063-3/+3
| | | | | |
| * | | | | Fix handling of duplicates for `replace` on has_many-throughFlorian Ebeling2018-11-064-3/+51
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | There was a bug in the handling of duplicates when assigning (replacing) associated records, which made the result dependent on whether a given record was associated already before being assigned anew. E.g. post.people = [person, person] post.people.count # => 2 while post.people = [person] post.people = [person, person] post.people.count # => 1 This change adds a test to provoke the former incorrect behavior, and fixes it. Cause of the bug was the handling of record collections as sets, and using `-` (difference) and `&` (union) operations on them indiscriminately. This temporary conversion to sets would eliminate duplicates. The fix is to decorate record collections for these operations, and only for the `has_many :through` case. It is done by counting occurrences, and use the record together with the occurrence number as element, in order to make them work well in sets. Given a, b = *Person.all then the collection used for finding the difference or union of records would be internally changed from [a, b, a] to [[a, 1], [b, 1], [a, 2]] for these operations. So a first occurrence and a second occurrence would be distinguishable, which is all that is necessary for this task. Fixes #33942.
* | | | | | Merge pull request #34453 from bogdanvlviv/exercise-connected_to-and-connects_toAaron Patterson2018-11-192-1/+36
|\ \ \ \ \ \ | | | | | | | | | | | | | | Exercise `connected_to` and `connects_to` methods
| * | | | | | Exercise `connected_to` and `connects_to` methodsbogdanvlviv2018-11-152-1/+36
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Since both methods are public API I think it makes sense to add these tests in order to prevent any regression in the behavior of those methods after the 6.0 release. Exercise `connected_to` - Ensure that the method raises with both `database` and `role` arguments - Ensure that the method raises without `database` and `role` Exercise `connects_to` - Ensure that the method returns an array of established connections(as mentioned in the docs of the method) Related to #34052
* | | | | | | Fix typo and clarify documentationJacob Evelyn2018-11-161-3/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This commit fixes a small typo in documentation of the "UNLOGGED" table option for PostgreSQL databases, and clarifies the documentation slightly.
* | | | | | | Fix cache_versioning default note (#34466)Gannon McGibbon2018-11-161-1/+1
| | | | | | | | | | | | | | | | | | | | | [ci skip]
* | | | | | | Arel: Implemented DB-aware NULL-safe comparison (#34451)Dmytro Shteflyuk2018-11-1523-1/+492
|/ / / / / / | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * Arel: Implemented DB-aware NULL-safe comparison * Fixed where clause inversion for NULL-safe comparison * Renaming "null_safe_eq" to "is_not_distinct_from", "null_safe_not_eq" to "is_distinct_from" [Dmytro Shteflyuk + Rafael Mendonça França]
* | | | | | Merge pull request #34437 from kbrock/union_all_parenRafael Mendonça França2018-11-134-42/+41
|\ \ \ \ \ \ | | | | | | | | | | | | | | | | | | | | | Fix: Arel now emits a single pair of parens for UNION and UNION ALL
| * | | | | | Emit single pair of parens for UNION and UNION ALLKeenan Brock2018-11-134-42/+41
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | mysql has a great implementation to suppress multiple parens for union sql statements. This moves that functionality to the generic implementation This also introduces that functionality for UNION ALL
* | | | | | | Merge pull request #34436 from gmcgibbon/fix_default_max_bind_length_sqliteRafael França2018-11-132-0/+26
|\ \ \ \ \ \ \ | |/ / / / / / |/| | | | | | Adjust bind length of SQLite to default (999)
| * | | | | | Adjust bind length of SQLite to default (999)Gannon McGibbon2018-11-132-0/+26
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Change `#bind_params_length` in SQLite adapter to return the default maximum amount (999). See https://www.sqlite.org/limits.html
* | | | | | | Merge pull request #34429 from ↵Rafael França2018-11-131-3/+21
|\ \ \ \ \ \ \ | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | bogdanvlviv/ensure-that-connected_to-establish_connection Ensure that `ActiveRecord::Base#connected_to` with `:database` establishes connection
| * | | | | | | Ensure that `ActiveRecord::Base#connected_to` with `:database` establishes ↵bogdanvlviv2018-11-121-3/+21
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | connection Related to #34052
* | | | | | | | Add support for UNLOGGED Postgresql tablesJacob Evelyn2018-11-135-1/+110
| |/ / / / / / |/| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This commit adds support for the `ActiveRecord::ConnectionAdapters::PostgreSQLAdapter.create_unlogged_tables` setting, which turns `CREATE TABLE` SQL statements into `CREATE UNLOGGED TABLE` statements. This can improve PostgreSQL performance but at the cost of data durability, and thus it is highly recommended that you *DO NOT* enable this in a production environment.
* | | | | | | Remove ensure from with_transaction_returning_statusEugene Kenny2018-11-111-4/+0
|/ / / / / / | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The test added in 12b0b26df7560ab5199ba830586864085441508f passes even without this code since 9b8c7796a9c2048208aa843ad3dc477dffa8bdee, as the call to `id` in `remember_transaction_record_state` now triggers a `sync_with_transaction_state` which discards the leftover state from the previous transaction. This issue had already been fixed for `save!`, `destroy` and `touch` in caae79a385ce112245262a17414bcd96bea013c2, but continued to affect `save` because the call to `rollback_active_record_state!` in that method would increment the transaction level before `add_to_transaction` could clear it, preventing the fix from working correctly. As `rollback_active_record_state!` was removed entirely in 48007d5390db47fc1223f57c8e7ab3ebb7c3a3d7, this code is no longer needed.
* | | | | | Fix test case for money schema defaultRyuta Kamizono2018-11-121-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Follow up a741208f80dd33420a56486bd9ed2b0b9862234a. Since a741208, `Decimal#serialize` which is superclass of `Money` type is no longer no-op, so it consistently serialize/deserialize a value as a decimal even if schema default.
* | | | | | Ensure casting by decimal attribute when queryingRyuta Kamizono2018-11-121-2/+8
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Related 34cc301f03aea2e579d6687a9ea9782afc1089a0. `QueryAttribute#value_for_database` calls only `type.serialize`, and `Decimal#serialize` is a no-op unlike other attribute types. Whether or not `serialize` will invoke `cast` is undefined in our test cases, but it actually does not work properly unless it does so for now.
* | | | | | Deprecate `t.indexes = [...]` which is not by designRyuta Kamizono2018-11-091-2/+5
| | | | | | | | | | | | | | | | | | | | | | | | Use `t.index ...` instead.
* | | | | | Refactor to initialize `TableDefinition` by kwargsRyuta Kamizono2018-11-092-4/+14
| | | | | |
* | | | | | Test prepared statement cache only if prepared statements is enabledRyuta Kamizono2018-11-091-1/+1
| | | | | |
* | | | | | PostgreSQL: Properly quote all `Infinity` and `NaN`Ryuta Kamizono2018-11-092-6/+26
| | | | | | | | | | | | | | | | | | | | | | | | Since quoted `Infinity` and `NaN` are valid data for PostgreSQL.
* | | | | | Add an :if_not_exists option to create_tablefatkodima2018-11-085-4/+59
| | | | | | | | | | | | | | | | | | | | | | | | [fatkodima & Stefan Kanev]
* | | | | | Guard Enums against definitions with blank label namesChristophe Maximin2018-11-073-1/+27
| | | | | |
* | | | | | Add multi-db support to schema cache dump and clearGannon McGibbon2018-11-073-5/+26
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Adds support for multiple databases to `rails db:schema:cache:dump` and `rails db:schema:cache:clear`.
* | | | | | Always add records to parent of nested transactionEugene Kenny2018-11-072-1/+12
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | When a record with transactional callbacks is saved, it's attached to the current transaction so that the callbacks can be run when the transaction is committed. Records can also be added manually with `add_transaction_record`, even if they have no transactional callbacks. When a nested transaction is committed, its records are transferred to the parent transaction, as transactional callbacks should only be run when the outermost transaction is committed (the "real" transaction). However, this currently only happens when the record has transactional callbacks, and not when added manually with `add_transaction_record`. If a record is added to a nested transaction, we should always attach it to the parent transaction when the nested transaction is committed, regardless of whether it has any transactional callbacks. [Eugene Kenny & Ryuta Kamizono]
* | | | | | Amend CVE note and security guide section wordingsGannon McGibbon2018-11-061-3/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Reword first sentence of dep management and CVE section of security guide. Also, reword and move gemspec notes above deps. [ci skip]
* | | | | | Add CVE note to security guide and gemspecsGannon McGibbon2018-11-061-0/+3
|/ / / / / | | | | | | | | | | | | | | | [ci skip]
* | | | | Fix inspect with non-primary key id attributeEugene Kenny2018-11-065-3/+26
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The `read_attribute` method always returns the primary key when asked to read the `id` attribute, even if the primary key isn't named `id`, and even if another attribute named `id` exists. For the `inspect`, `attribute_for_inspect` and `pretty_print` methods, this behaviour is undesirable, as they're used to examine the internal state of the record. By using `_read_attribute` instead, we'll get the real value of the `id` attribute.
* | | | | Move `resolve_sti_reflections` which is table row related code into `TableRow`Ryuta Kamizono2018-11-032-89/+78
| | | | |
* | | | | Don't pass useless `table_name` to `ModelMetadata.new`Ryuta Kamizono2018-11-033-13/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The `model_metadata` is only used if `model_class` is given. If `model_class` is given, the `table_name` is always `model_class.table_name`.
* | | | | Don't pass unused `connection` to `FixtureSet.new`Ryuta Kamizono2018-11-032-14/+11
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The `@connection` is no longer used since ee5ab22. Originally the `@connection` was useless because it is only used in `timestamp_column_names`, which is only used if `model_class` is given. If `model_class` is given, the `@connection` is always `model_class.connection`.