aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord
Commit message (Collapse)AuthorAgeFilesLines
* Remove unused codebogdanvlviv2019-01-301-8/+0
| | | | | | | | - Remove `fragment_cache_key` helper declaration. It was removed in e70d3df7c9b05c129b0fdcca57f66eca316c5cfc - Remove `by_private_lifo`. It is unused since a7becf147afc85c354e5cfa519911a948d25fc4d
* Merge pull request #35071 from kamipo/text_without_limitRyuta Kamizono2019-01-297-13/+60
|\ | | | | MySQL: Support `:size` option to change text and blob size
| * Allow changing text and blob size without giving the `limit` optionRyuta Kamizono2019-01-297-13/+60
| | | | | | | | | | | | | | | | | | | | | | | | | | | | 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.
* | Pull `@template` in to a local variableAaron Patterson2019-01-281-2/+2
| | | | | | | | | | | | This gets the PartialRenderer to be a bit closer to the TemplateRenderer. TemplateRenderer already keeps its template in a local variable.
* | Remove `@view` instance variable from the partial rendererAaron Patterson2019-01-281-2/+2
|/ | | | Similar to 1853b0d0abf87dfdd4c3a277c3badb17ca19652e
* PostgreSQL: Use native timestamp decoders of pg-1.1Lars Kanis2019-01-262-3/+33
| | | | | This improves performance of timestamp conversion and avoids additional string allocations.
* Make `t.timestamps` with precision by defaultRyuta Kamizono2019-01-2611-62/+198
|
* Fix `t.timestamps` missing `null: false` in `change_table bulk: true`Ryuta Kamizono2019-01-264-0/+36
|
* Allow `column_exists?` giving options without typeRyuta Kamizono2019-01-263-13/+13
|
* Merge pull request #35042 from eileencodes/fix-error-message-for-missing-handlerEileen M. Uchitelle2019-01-254-8/+21
|\ | | | | Fix error raised when handler doesn't exist
| * Fix error raised when handler doesn't existEileen Uchitelle2019-01-254-8/+21
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | While working on another feature for multiple databases (auto-switching) I observed that in development the first request won't autoload the application record connection for the primary database and may not yet know about the replica connection. In my test application this caused the application to thrown an error if I tried to send the first request to the replica before the replica was connected. This wouldn't be an issue in production because the application is preloaded. In order to fix this I decided to leave the original error message and delete the new error message. I updated the original error message to include the `role` to make it a bit clearer that the connection isn't established for that particular role. The error now reads: ``` No connection pool with 'primary' found for the 'reading' role. ``` A single database application will continue uisng the original error message: ``` No connection pool with 'primary' found. ```
* | Make `And` and `Case` into expression nodesKevin Deisz2019-01-243-4/+11
|/ | | | Allows aliasing, predications, ordering, and various other functions on `And` and `Case` nodes. This brings them in line with other nodes like `Binary` and `Unary`.
* Allow `column_exists?` to be passed `type` argument as a stringRyuta Kamizono2019-01-242-10/+5
| | | | | | | | | | | Currently `conn.column_exists?("testings", "created_at", "datetime")` returns false even if the table has the `created_at` column. That reason is that `column.type` is a symbol but passed `type` is not normalized to symbol unlike `column_name`, it is surprising behavior to me. I've improved that to normalize a value before comparison.
* Tell the user what to use instead of update_attributes/!Xavier Noria2019-01-231-2/+2
|
* activerecord: Fix statement cache for strictly cast attributesDylan Thacker-Smith2019-01-232-1/+7
|
* MySQL 8.0.14 adds `ER_FK_INCOMPATIBLE_COLUMNS`Yasuo Honda2019-01-221-1/+2
| | | | | | | | | | | | https://dev.mysql.com/doc/relnotes/mysql/8.0/en/news-8-0-14.html > Error messages relating to creating and dropping foreign keys > were improved to be more specific and informative. (Bug #28526309, Bug #92087) https://dev.mysql.com/doc/refman/8.0/en/server-error-reference.html > Error number: 3780; Symbol: ER_FK_INCOMPATIBLE_COLUMNS; SQLSTATE: HY000 > Message: Referencing column '%s' and referenced column '%s' in foreign key constraint '%s' are incompatible. > ER_FK_INCOMPATIBLE_COLUMNS was added in 8.0.14.
* Merge pull request #35006 from kddeisz/alias-case-nodesRyuta Kamizono2019-01-222-0/+12
|\ | | | | Alias case nodes
| * Alias case nodesKevin Deisz2019-01-212-0/+12
| | | | | | | | When `Arel` was merged into `ActiveRecord` we lost the ability to alias case nodes. This adds it back.
* | Fix year value when casting a multiparameter time hashAndrew White2019-01-211-0/+22
|/ | | | | | | | | | | | | | | | | | | | | | | When assigning a hash to a time attribute that's missing a year component (e.g. a `time_select` with `:ignore_date` set to `true`) then the year defaults to 1970 instead of the expected 2000. This results in the attribute changing as a result of the save. Before: event = Event.new(start_time: { 4 => 20, 5 => 30 }) event.start_time # => 1970-01-01 20:30:00 UTC event.save event.reload event.start_time # => 2000-01-01 20:30:00 UTC After: event = Event.new(start_time: { 4 => 20, 5 => 30 }) event.start_time # => 2000-01-01 20:30:00 UTC event.save event.reload event.start_time # => 2000-01-01 20:30:00 UTC
* Fix type casting column default in `change_column`Ryuta Kamizono2019-01-204-28/+56
| | | | | | | | | | | | | | Since #31230, `change_column` is executed as a bulk statement. That caused incorrect type casting column default by looking up the before changed type, not the after changed type. In a bulk statement, we can't use `change_column_default_for_alter` if the statement changes the column type. This fixes the type casting to use the constructed target sql_type. Fixes #34938.
* Preparing for 6.0.0.beta1 releaseRafael Mendonça França2019-01-182-1/+3
|
* activerecord: Fix where nil condition on composed_of attributeDylan Thacker-Smith2019-01-182-4/+23
|
* Merge pull request #30000 from ↵Ryuta Kamizono2019-01-1814-37/+72
|\ | | | | | | | | kamipo/all_of_queries_should_return_correct_result All of queries should return correct result even if including large number
| * Ensure `StatementCache#execute` never raises `RangeError`Ryuta Kamizono2019-01-187-19/+19
| | | | | | | | | | | | | | | | | | | | | | | | | | Since 31ffbf8d, finder methods no longer raise `RangeError`. So `StatementCache#execute` is the only place to raise the exception for finder queries. `StatementCache` is used for simple equality queries in the codebase. This means that if `StatementCache#execute` raises `RangeError`, the result could always be regarded as empty. So `StatementCache#execute` just return nil in that range error case, and treat that as empty in the caller side, then we can avoid catching the exception in much places.
| * All of queries should return correct result even if including large numberRyuta Kamizono2019-01-187-18/+53
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Currently several queries cannot return correct result due to incorrect `RangeError` handling. First example: ```ruby assert_equal true, Topic.where(id: [1, 9223372036854775808]).exists? assert_equal true, Topic.where.not(id: 9223372036854775808).exists? ``` The first example is obviously to be true, but currently it returns false. Second example: ```ruby assert_equal topics(:first), Topic.where(id: 1..9223372036854775808).find(1) ``` The second example also should return the object, but currently it raises `RecordNotFound`. It can be seen from the examples, the queries including large number assuming empty result is not always correct. Therefore, This change handles `RangeError` to generate executable SQL instead of raising `RangeError` to users to always return correct result. By this change, it is no longer raised `RangeError` to users.
* | Merge pull request #34969 from eileencodes/fix-error-message-for-multi-db-appsEileen M. Uchitelle2019-01-181-1/+20
|\ \ | |/ |/| Fix error message when adapter is not specified
| * Fix error message when adapter is not specifiedEileen Uchitelle2019-01-171-1/+20
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | When we added support for multiple databases through a 3-tiered config and configuration objects this error message got a bit convoluted. Previously if you had an application with a missing configuation and multiple databases the error message would look like this: ``` 'doesnexist' database is not configured. Available: development, development, test, test, production, production (ActiveRecord::AdapterNotSpecified) ``` That's not very descriptive since it duplicates the environments (because there are multiple databases per environment for this application). To fix this I've constructed a bit more readable error message which now reads like this if you have a multi db app: ``` The `doesntexist` database is not configured for the `production` environment. (ActiveRecord::AdapterNotSpecified) Available databases configurations are: development: primary, primary_readonly test: primary, primary_readonly production: primary, primary_readonly ``` And like this if you have a single db app: ``` The `doesntexist` database is not configured for the `production` environment. (ActiveRecord::AdapterNotSpecified) Available databases configurations are: development test ``` This makes the error message more readable and presents the user all available options for the database connections.
* | Use `unboundable?` rather than `boundable?`Ryuta Kamizono2019-01-184-14/+19
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The `unboundable?` behaves like the `infinite?`. ```ruby inf = Topic.predicate_builder.build_bind_attribute(:id, Float::INFINITY) inf.infinite? # => 1 oob = Topic.predicate_builder.build_bind_attribute(:id, 9999999999999999999999999999999) oob.unboundable? # => 1 inf = Topic.predicate_builder.build_bind_attribute(:id, -Float::INFINITY) inf.infinite? # => -1 oob = Topic.predicate_builder.build_bind_attribute(:id, -9999999999999999999999999999999) oob.unboundable? # => -1 ```
* | Merge pull request #34963 from ↵Rafael França2019-01-172-8/+13
|\ \ | | | | | | | | | | | | dylanahsmith/better-composed-of-single-field-query activerecord: Use a simpler query condition for aggregates with one mapping
| * | Use public_send instead since respond_to? doesn't include private/protected ↵Ryuta Kamizono2019-01-171-1/+1
| | | | | | | | | | | | | | | methods by default Co-Authored-By: dylanahsmith <dylan.smith@shopify.com>
| * | Avoid using yield_self to make it easier to backportDylan Thacker-Smith2019-01-171-5/+4
| | |
| * | activerecord: Use a simpler query condition for aggregates with one mappingDylan Thacker-Smith2019-01-172-8/+14
| |/
* | Merge pull request #34966 from ↵Rafael Mendonça França2019-01-173-4/+14
|\ \ | | | | | | | | | | | | | | | 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-173-7/+17
| |/ | | | | | | | | Clarify changelog entry Related to #34891
* | Remove deprecated `#set_state` from the transaction objectRafael Mendonça França2019-01-173-29/+4
| |
* | Remove deprecated `#supports_statement_cache?` from the database adaptersRafael Mendonça França2019-01-173-11/+4
| |
* | Remove deprecated `#insert_fixtures` from the database adaptersRafael Mendonça França2019-01-175-43/+5
| |
* | Remove deprecated ↵Rafael Mendonça França2019-01-173-9/+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-173-9/+11
| |
* | Do not allow passing the column name to `count` when a block is passedRafael Mendonça França2019-01-173-9/+11
| |
* | Remove delegation of missing methods in a relation to arelRafael Mendonça França2019-01-173-20/+4
| |
* | Remove delegation of missing methods in a relation to private methods of the ↵Rafael Mendonça França2019-01-173-12/+4
| | | | | | | | class
* | Change `SQLite3Adapter` to always represent boolean values as integersRafael Mendonça França2019-01-175-63/+33
| |
* | Remove ability to specify a timestamp name for `#cache_key`Rafael Mendonça França2019-01-174-31/+10
| |
* | Remove deprecated `ActiveRecord::Migrator.migrations_path=`Rafael Mendonça França2019-01-173-17/+4
| |
* | Remove deprecated `expand_hash_conditions_for_aggregates`Rafael Mendonça França2019-01-173-46/+7
|/
* Add foreign key to active_storage_attachments for `blob_id` via new migrationbogdanvlviv2019-01-161-0/+4
| | | | | | | | | | | | | | | | | | We need this in order to be able to add this migration for users that use ActiveStorage during update their apps from Rails 5.2 to Rails 6.0. Related to #33405 `rake app:update` should update active_storage `rake app:update` should execute `rake active_storage:update` if it is used in the app that is being updated. It will add new active_storage's migrations to users' apps during update Rails. Context https://github.com/rails/rails/pull/33405#discussion_r204239399 Also, see a related discussion in the Campfire: https://3.basecamp.com/3076981/buckets/24956/chats/12416418@1236713081
* Refs #28025 nullify *_type column on polymorphic associations on :nu… ↵Laerti2019-01-159-4/+63
| | | | | | (#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.
* Remove public `prevent_writes` writerRyuta Kamizono2019-01-151-5/+5
| | | | | | The `@prevent_writes` should be updated only in the `while_preventing_writes`, it is not necessary to expose the attr writer.
* Deprecate `connection.visitor = ...` which is not released internal usageRyuta Kamizono2019-01-151-2/+6
| | | | | | | | | This attr writer was introduced at 7db90aa, but the usage is already removed at bd2f5c0 before v3.2.0.rc1 is released. If we'd like to customize the visitor in the connection, `arel_visitor` which is implemented in all adapters (mysql2, postgresql, sqlite3, oracle-enhanced, sqlserver) could be used for the purpose #23515.