aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord
Commit message (Collapse)AuthorAgeFilesLines
* Merge pull request #19090 from ↵Matthew Draper2017-12-019-20/+115
|\ | | | | | | | | gregnavis/support-postgresql-operator-classes-in-indexes Add support for PostgreSQL operator classes to add_index
| * Add support for PostgreSQL operator classes to add_indexGreg Navis2017-11-309-20/+115
| | | | | | | | | | | | | | | | | | | | | | | | Add support for specifying non-default operator classes in PostgreSQL indexes. An example CREATE INDEX query that becomes possible is: CREATE INDEX users_name ON users USING gist (name gist_trgm_ops); Previously it was possible to specify the `gist` index but not the custom operator class. The `add_index` call for the above query is: add_index :users, :name, using: :gist, opclasses: {name: :gist_trgm_ops}
* | Remove unnecessary scopingRyuta Kamizono2017-12-011-1/+1
| |
* | Class level `update` and `destroy` checks all the records exist before ↵Ryuta Kamizono2017-12-012-13/+41
| | | | | | | | | | making changes (#31306) It makes more sense than ignoring invalid IDs.
* | Maintain raising `RecordNotFound` for class level `update` and` destroy`Ryuta Kamizono2017-12-012-6/+21
| | | | | | | | | | | | | | | | | | | | | | In 35836019, class level `update` and `destroy` suppressed `RecordNotFound` to ensure returning affected objects. But `RecordNotFound` is a common exception caught by a `rescue_from` handler. So changing the behavior when a typical `params[:id]` is passed has a compatibility problem. The previous behavior should not be changed. Fixes #31301.
* | Add :nodoc: to `StatementPool` which is internal used [ci skip]Ryuta Kamizono2017-11-302-4/+2
|/ | | | | | In #30510, `StatementPool` in `AbstractMysqlAdapter` was hidden in the doc. But that class is also had in sqlite3 and postgresql adapters and the base class is :nodoc: class.
* Merge pull request #31214 from ↵Eileen M. Uchitelle2017-11-293-0/+17
|\ | | | | | | | | chopraanmol1/bug_fix_has_one_inverse_owner_reload_from_validation Inverse instance should not be reloaded during autosave if called in validation
| * Inverse instance should not be reloaded during autosave if called in validationAnmol Chopra2017-11-273-0/+17
| | | | | | | | | | Record saved in save_has_one_association already make call to association.loaded! via record's before_save callback of save_belongs_to_association, but this will reload object if accessed in record's validation.
* | Merge pull request #31179 from kinnrot/scoping-reserved-namesRafael Mendonça França2017-11-285-0/+49
|\ \ | | | | | | | | | Scoping reserved names
| * | Prevent scope named same as a ActiveRecord::Relation instance method.Chen Kinnrot2017-11-285-0/+48
| | | | | | | | | | | | | | | | | | | | | | | | | | | Due to inconsistent behavior when chaining scopes and one scope named after a Relation method Validation code added in 2 places: - scope, to prevent problematic scope names. - enum, cause it tries to auto define scope.
* | | Merge pull request #31254 from suginoy/update_doc_find_orderRafael França2017-11-281-3/+4
|\ \ \ | | | | | | | | [ci skip]Update docs `ActiveRecord::FinderMethods#find`
| * | | Update docs `ActiveRecord::FinderMethods#find`suginoy2017-11-281-3/+4
| |/ / | | | | | | | | | ref https://github.com/rails/rails/pull/22653
* | | Preparing for 5.2.0.beta2 releaseRafael Mendonça França2017-11-282-1/+6
| | |
* | | Fix typos and add a few suggestionsFatos Morina2017-11-281-1/+1
|/ /
* | Change how `AttributeSet::Builder` receives its defaultsSean Griffin2017-11-271-4/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | There are two concerns which are both being combined into one here, but both have the same goal. There are certain attributes which we want to always consider initialized. Previously, they were handled separately. The primary key (which is assumed to be backed by a database column) needs to be initialized, because there is a ton of code in Active Record that assumes `foo.id` will never raise. Additionally, we want attributes which aren't backed by a database column to always be initialized, since we would never receive a database value for them. Ultimately these two concerns can be combined into one. The old implementation hid a lot of inherent complexity, and is hard to optimize from the outside. We can simplify things significantly by just passing in a hash. This has slightly different semantics from the old behavior, in that `Foo.select(:bar).first.id` will return the default value for the primary key, rather than `nil` unconditionally -- however, the default value is always `nil` in practice.
* | Drop mysql2 version less than 0.4.3 to guarantee fork safety (#31244)Ryuta Kamizono2017-11-281-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Since #31173, mysql2 adapter depends on `automatic_close` which is introduced since mysql2 0.4.3. So the adapter with the mysql2 version before doesn't work with fork now. ``` % ARCONN=mysql2 be ruby -w -Itest test/cases/connection_adapters/connection_handler_test.rb -n test_forked_child_doesnt_mangle_parent_connection Using mysql2 Run options: -n test_forked_child_doesnt_mangle_parent_connection --seed 19988 /Users/kamipo/src/github.com/rails/rails/activerecord/lib/active_record/connection_adapters/mysql2_adapter.rb:108:in `discard!': undefined method `automatic_close=' for #<Mysql2::Client:0x00007fedaa91dfd0> (NoMethodError) ``` This drops mysql2 version less than 0.4.3 to guarantee fork safety.
* | Preparing for 5.2.0.beta1 releaseRafael Mendonça França2017-11-272-1/+3
| |
* | Add new error class `QueryCanceled` which will be raised when canceling ↵Ryuta Kamizono2017-11-276-3/+69
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | statement due to user request (#31235) This changes `StatementTimeout` to `QueryCanceled` for PostgreSQL. In MySQL, errno 1317 (`ER_QUERY_INTERRUPTED`) is only used when the query is manually cancelled. But in PostgreSQL, `QUERY_CANCELED` error code (57014) which is used `StatementTimeout` is also used when the both case. And, we can not tell which reason happened. So I decided to introduce new error class `QueryCanceled` closer to the error code name.
* | Rename `TransactionTimeout` to more descriptive `LockWaitTimeout` (#31223)Ryuta Kamizono2017-11-276-9/+9
| | | | | | | | | | | | Since #31129, new error class `StatementTimeout` has been added. `TransactionTimeout` is caused by the timeout shorter than `StatementTimeout`, but its name is too generic. I think that it should be a name that understands the difference with `StatementTimeout`.
* | Revert "Merge pull request #31006 from ↵eileencodes2017-11-262-17/+0
| | | | | | | | | | | | | | | | | | | | | | rails/kamipo/ordinal_methods_should_respect_loaded_records" This reverts commit 0f79ab91150b4cdb6c018530978a3395962c7a02, reversing changes made to d575f7f2e737739302a0e8210d01c10f5d4e2c35. This PR philosophically conflicts with #30800 and Matthew thinks we should hold off merging this until we find concensus. Reverting since we're about to cut a release for 5.2.
* | Merge pull request #31221 from matthewd/flush-idle-connectionsMatthew Draper2017-11-266-17/+129
|\ \ | | | | | | Flush idle database connections
| * | Flush idle database connectionsMatthew Draper2017-11-266-17/+129
| |/
* | Let rubygems handle our objection to mysql2 0.4.3Matthew Draper2017-11-261-2/+1
| |
* | Merge pull request #31184 from TheSmartnik/fix_record_not_found_on_reloadRafael França2017-11-254-7/+35
|\ \ | | | | | | Provide arguments to RecordNotFound
| * | Provide arguments to RecordNotFoundNikita Misharin2017-11-254-7/+35
| | |
* | | Merge pull request #30510 from yhirano55/add_nodoc_to_activerecordEileen M. Uchitelle2017-11-253-7/+7
|\ \ \ | | | | | | | | Add :nodoc: to activerecord [ci skip]
| * | | Add :nodoc: to activerecord [ci skip]Yoshiyuki Hirano2017-09-033-7/+7
| | | |
* | | | Merge pull request #31006 from ↵Eileen M. Uchitelle2017-11-252-0/+17
|\ \ \ \ | | | | | | | | | | | | | | | | | | | | rails/kamipo/ordinal_methods_should_respect_loaded_records Ordinal methods should respect loaded records
| * | | | Ordinal methods should respect loaded recordsRyuta Kamizono2017-10-282-0/+17
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | We should reset partially loaded `@offsets` cache when latest records has loaded because the cache has been staled and it may not be consistent with latest records.
* | | | | Merge pull request #31173 from matthewd/connection-fork-safetyMatthew Draper2017-11-255-0/+90
|\ \ \ \ \ | |_|_|_|/ |/| | | | Improve AR connection fork safety
| * | | | Improve AR connection fork safetyMatthew Draper2017-11-185-0/+90
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Use whatever adapter-provided means we have available to ensure forked children don't send quit/shutdown/goodbye messages to the server on connections that belonged to their parent.
* | | | | Merge pull request #31194 from ↵Yuji Yaginuma2017-11-231-6/+1
|\ \ \ \ \ | | | | | | | | | | | | | | | | | | | | | | | | yahonda/attributes_before_type_cast_on_boolean_with_jruby No difference between JRuby and CRuby at test_read_attributes_before_…
| * | | | | No difference between JRuby and CRuby at ↵Yasuo Honda2017-11-211-6/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | test_read_attributes_before_type_cast_on_a_boolean https://github.com/jruby/activerecord-jdbc-adapter ActiveRecord JDBC Adapter is actively developed and it supports Rails 5.1 now. This pull request addresses one of the failure when running ActiveRecord unit tests with ActiveRecord JDBC Adapter. As of right now, ActiveRecord JDBC Adapter supports Rails 5.1, not master branch then this test only can run on `5-1-stable` branch. But I have opened this pull request to `master` branch since this type cast should be going to work in the future versions of ActiveRecord JDBC Adapter . ```ruby $ ARCONN=jdbcmysql bin/test test/cases/attribute_methods_test.rb:203 Using jdbcmysql Run options: --seed 8874 F Finished in 0.709120s, 1.4102 runs/s, 1.4102 assertions/s. 1) Failure: AttributeMethodsTest#test_read_attributes_before_type_cast_on_a_boolean [/home/yahonda/git/rails/activerecord/test/cases/attribute_methods_test.rb:203]: Expected: "0" Actual: 0 1 runs, 1 assertions, 1 failures, 0 errors, 0 skips $ ```
* | | | | | Update incorrect backtick usage in RDoc to teletypeT.J. Schuck2017-11-221-2/+2
|/ / / / / | | | | | | | | | | [ci skip]
* | | | | Prevent extra `spawn` to make `klass.all` faster (#29009)Ryuta Kamizono2017-11-202-3/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | These extra `spawn` are called via `klass.all` and `klass.all` is called everywhere in the internal. Avoiding the extra `spawn` makes` klass.all` 30% faster for STI classes. https://gist.github.com/kamipo/684d03817a8115848cec8e8b079560b7 ``` Warming up -------------------------------------- fast relation 4.410k i/100ms slow relation 3.334k i/100ms Calculating ------------------------------------- fast relation 47.373k (± 5.2%) i/s - 238.140k in 5.041836s slow relation 35.757k (±15.9%) i/s - 176.702k in 5.104625s Comparison: fast relation: 47373.2 i/s slow relation: 35756.7 i/s - 1.32x slower ```
* | | | | Merge pull request #31035 from BrentWheeldon/bmw-db-load-deadlockMatthew Draper2017-11-181-1/+2
|\ \ \ \ \ | | | | | | | | | | | | Prevent deadlocks with load interlock and DB lock.
| * | | | | Prevent deadlocks with load interlock and DB lock.Brent Wheeldon2017-11-091-1/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This fixes an issue where competing threads deadlock each other. - Thread A holds the load interlock but is blocked on getting the DB lock - Thread B holds the DB lock but is blocked on getting the load interlock (for example when there is a `Model.transaction` block that needs to autoload) This solution allows for dependency loading in other threads while a thread is waiting to acquire the DB lock. Fixes #31019
* | | | | | Merge pull request #28742 from quixoten/stack_conn_poolMatthew Draper2017-11-172-6/+11
|\ \ \ \ \ \ | | | | | | | | | | | | | | Switch to LIFO for the connection pool
| * | | | | | Fix typosDevin Christensen2017-04-132-2/+2
| | | | | | |
| * | | | | | Improve documentation and add testDevin Christensen2017-04-132-7/+12
| | | | | | |
| * | | | | | Switch to LIFO for the connection poolDevin Christensen2017-04-121-2/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Using a FIFO for the connection pool can lead to issues when there are upstream components (pgbouncer, haproxy, etc.) that terminate connections that are idle after a period of time. Switching to a LIFO reduces the probability that a thread will checkout a connection that is about to be closed by an idle timeout in an upstream component.
* | | | | | | Merge pull request #28869 from eugeneius/query_cache_all_poolsMatthew Draper2017-11-172-6/+18
|\ \ \ \ \ \ \ | |_|_|/ / / / |/| | | | | | Enable query cache on all connection pools
| * | | | | | Enable query cache on all connection poolsEugene Kenny2017-04-242-6/+18
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Since the query cache no longer eagerly checks out a connection, we can enable it on all connection pools at the start of every request, and it will only take effect for requests that actually use those pools.
* | | | | | | Avoid creating extra `relation` and `build_arel` in `_create_record` and ↵Ryuta Kamizono2017-11-172-63/+41
| |_|_|_|_|/ |/| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | `_update_record` (#29999) Currently `_create_record` and `_update_record` in `Persistence` are creating extra `unscoped` and calling `build_arel` in the relation. But `compile_insert` and `compile_update` can be done without those expensive operation for `SelectManager` creation. So I moved the implementation to `Persistence` to avoid creating extra relation and refactored to avoid calling `build_arel`. https://gist.github.com/kamipo/8ed73d760112cfa5f6263c9413633419 Before: ``` Warming up -------------------------------------- _update_record 150.000 i/100ms Calculating ------------------------------------- _update_record 1.548k (±12.3%) i/s - 7.650k in 5.042603s ``` After: ``` Warming up -------------------------------------- _update_record 201.000 i/100ms Calculating ------------------------------------- _update_record 2.002k (±12.8%) i/s - 9.849k in 5.027681s ``` 30% faster for STI classes.
* | | | | | Allow test_ignored_columns_not_included_in_SELECT column names caseYasuo Honda2017-11-151-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | insensitive i.e. Oracle database identifier is UPPERCASE unlike other databases. ```ruby (byebug) query = Developer.all.to_sql "SELECT \"DEVELOPERS\".\"ID\", \"DEVELOPERS\".\"NAME\", \"DEVELOPERS\".\"SALARY\", \"DEVELOPERS\".\"FIRM_ID\", \"DEVELOPERS\".\"MENTOR_ID\", \"DEVELOPERS\".\"CREATED_AT\", \"DEVELOPERS\".\"UPDATED_AT\", \"DEVELOPERS\".\"CREATED_ON\", \"DEVELOPERS\".\"UPDATED_ON\" FROM \"DEVELOPERS\"" ```
* | | | | | Fix CI failure due to invalid `up_only` for MySQLRyuta Kamizono2017-11-151-5/+7
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | `oldie = 'true'` to `tinyint(1)` column is invalid value for MySQL: ``` Mysql2::Error: Incorrect integer value: 'true' for column 'oldie' at row 1: update horses set oldie = 'true' ```
* | | | | | Fix typo s/only_up/up_only/ [ci skip]Ryuta Kamizono2017-11-151-1/+1
| | | | | |
* | | | | | Fix migration version in doc of #up_onlybogdanvlviv2017-11-141-1/+1
| | | | | |
* | | | | | Use released arelRafael Mendonça França2017-11-141-1/+1
| | | | | |
* | | | | | Add a #populate method to migrations (#31082)Rich2017-11-143-0/+48
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * Add a #populate method to migrations * Address rubocop issues * Rename to #up_only and use #execute in the examples intead of the model * Update CHANGELOG [Rich Daley & Rafael Mendonça França]