aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record
Commit message (Collapse)AuthorAgeFilesLines
...
* | | MariaDB: Remove version checking lower the 5.5.8Ryuta Kamizono2019-01-021-10/+2
| | | | | | | | | | | | Since we already bumped the minimum version of MySQL to 5.5.8 at #33853.
* | | Add test case for `preventing_writes?`Ryuta Kamizono2019-01-021-1/+1
| | | | | | | | | | | | Since the `preventing_writes?` is public API.
* | | Bring ActiveRecord::Core's API document back [ci skip]yuuji.yaginuma2019-01-021-3/+1
|/ / | | | | | | | | If exist `:nodoc:` before method define, it affects all subsequent method definitions.
* | Fix TypeError: no implicit conversion of Arel::Attributes::Attribute into ↵Ryuta Kamizono2019-01-021-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | String properly This reverts 27c6c07 since `arel_attr.to_s` is not right way to avoid the type error. That to_s returns `"#<struct Arel::Attributes::Attribute ...>"`, there is no reason to match the regex to the inspect form. And also, the regex path is not covered by our test cases. I've tweaked the regex for redundant part and added assertions for the regex path.
* | Use high level API on `migration_context` instead of using low level API ↵Ryuta Kamizono2018-12-282-13/+11
| | | | | | | | | | | | | | | | directly Since `migration_context` has `migrations_paths` itself and provides methods which returning values from parsed migration files, so there is no reason to use the `parse_migration_filename` low level API directly.
* | Deprecate passing `migrations_paths` to ↵Ryuta Kamizono2018-12-282-12/+9
| | | | | | | | | | | | | | `connection.assume_migrated_upto_version` Since #31727, `migrations_paths` in `assume_migrated_upto_version` is no longer used.
* | Merge pull request #34806 from bogdan/reuse-find-targetRyuta Kamizono2018-12-274-30/+20
|\ \ | | | | | | | | | Reuse AR::Association#find_target method
| * | Reuse AR::Association#find_target methodBogdan Gusiev2018-12-274-29/+21
| | |
* | | Merge pull request #34753 from ↵Eileen M. Uchitelle2018-12-211-0/+4
|\ \ \ | | | | | | | | | | | | | | | | eileencodes/raise-less-confusing-error-if-handler-doesnt-exist Raise helpful error when role doesn't exist
| * | | Raise helpful error when role doesn't existEileen Uchitelle2018-12-211-0/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | If you try to call `connected_to` with a role that doesn't have an established connection you used to get an error that said: ``` >> ActiveRecord::Base.connected_to(role: :i_dont_exist) { Home.first } ActiveRecord::ConnectionNotEstablished Exception: No connection pool with 'primary' found. ``` This is confusing because the connection could be established but we spelled the role wrong. I've changed this to raise if the `role` used in `connected_to` doesn't have an associated handler. Users who encounter this should either check that the role is spelled correctly (writin -> writing), establish a connection to that role in the model with connects_to, or use the `database` keyword for the `role`. I think this will provide a less confusing error message for those starting out with multiple databases.
* | | | Merge pull request #34742 from kamipo/row_format_dynamic_by_defaultRyuta Kamizono2018-12-211-0/+18
|\ \ \ \ | | | | | | | | | | MySQL: `ROW_FORMAT=DYNAMIC` create table option by default
| * | | | MySQL: `ROW_FORMAT=DYNAMIC` create table option by defaultRyuta Kamizono2018-12-191-0/+18
| |/ / / | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Since MySQL 5.7.9, the `innodb_default_row_format` option defines the default row format for InnoDB tables. The default setting is `DYNAMIC`. The row format is required for indexing on `varchar(255)` with `utf8mb4` columns. As long as using MySQL 5.6, CI won't be passed even if MySQL server setting is properly configured the same as MySQL 5.7 (`innodb_file_per_table = 1`, `innodb_file_format = 'Barracuda'`, and `innodb_large_prefix = 1`) since InnoDB table is created as the row format `COMPACT` by default on MySQL 5.6, therefore indexing on string with `utf8mb4` columns aren't succeeded. Making `ROW_FORMAT=DYNAMIC` create table option by default for legacy MySQL version would mitigate the indexing issue on the user side, and it makes CI would be passed on MySQL 5.6 which is configured properly.
* | | | Enable `Style/RedundantBegin` cop to avoid newly adding redundant begin blockRyuta Kamizono2018-12-216-63/+49
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Currently we sometimes find a redundant begin block in code review (e.g. https://github.com/rails/rails/pull/33604#discussion_r209784205). I'd like to enable `Style/RedundantBegin` cop to avoid that, since rescue/else/ensure are allowed inside do/end blocks in Ruby 2.5 (https://bugs.ruby-lang.org/issues/12906), so we'd probably meets with that situation than before.
* | | | Module#{define_method,alias_method,undef_method,remove_method} become public ↵Ryuta Kamizono2018-12-213-4/+4
| | | | | | | | | | | | | | | | | | | | | | | | since Ruby 2.5 https://bugs.ruby-lang.org/issues/14133
* | | | Merge pull request #30973 from k0kubun/prefer-block-parameterRyuta Kamizono2018-12-201-10/+2
|\ \ \ \ | |/ / / |/| | | Unify _read_attribute definition to use &block
| * | | Unify _read_attribute definition to use &blockTakashi Kokubun2018-12-201-10/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Thanks to ko1, passing block parameter to another method is significantly optimized in Ruby 2.5. https://bugs.ruby-lang.org/issues/14045 Thus we no longer need to keep this ugly hack.
* | | | Use `utf8mb4` charset for internal tables if the row format `DYNAMIC` by defaultRyuta Kamizono2018-12-192-10/+10
| | | | | | | | | | | | | | | | The indexing issue on `utf8mb4` columns is resolved since MySQL 5.7.9.
* | | | Ensure that preventing writes is invoked before `materialize_transactions` ↵Ryuta Kamizono2018-12-121-4/+2
| | | | | | | | | | | | | | | | consistently
* | | | Add AR::Base.connected_to?John Hawthorn2018-12-111-0/+23
| | | | | | | | | | | | | | | | | | | | This can be used to check the currently connected role. It's meant to mirror AR::Base.connected_to
* | | | An empty transaction does not raise the `ReadOnlyError` if preventing writesRyuta Kamizono2018-12-113-3/+3
| | | | | | | | | | | | | | | | | | | | | | | | BEGIN transaction would cause COMMIT or ROLLBACK, so unless COMMIT and ROLLBACK aren't treated as write queries as well as BEGIN, the `ReadOnlyError` would be raised.
* | | | Merge pull request #34666 from vinistock/upgrade_rubocop_and_fix_offensesRafael França2018-12-102-36/+36
|\ \ \ \ | | | | | | | | | | Upgrade Rubocop to 0.61.1 and fix offenses
| * | | | Upgrade Rubocop to 0.61.1 and fix offensesVinicius Stock2018-12-102-36/+36
| | | | |
* | | | | An explain query does not raise the `ReadOnlyError` if preventing writesRyuta Kamizono2018-12-113-3/+3
| | | | |
* | | | | Don't treat begin and rollback transactions as write queriesRyuta Kamizono2018-12-113-3/+3
|/ / / / | | | | | | | | | | | | | | | | Otherwise `save` method would raise the `ReadOnlyError` against `BEGIN` and `ROLLBACK` queries.
* | | | Prevent write queries with prepared statements for mysql2 adapterRyuta Kamizono2018-12-111-0/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Without this change, mysql2 adapter with prepared statements won't pass `base_test.rb`. ``` % ARCONN=mysql2 be ruby -w -Itest test/cases/base_test.rb Using mysql2 Run options: --seed 27614 # Running: ....S..............................F Failure: BasicsTest#test_creating_a_record_raises_if_preventing_writes [test/cases/base_test.rb:1493]: ActiveRecord::ReadOnlyError expected but nothing was raised. rails test test/cases/base_test.rb:1492 ...F Failure: BasicsTest#test_deleting_a_record_raises_if_preventing_writes [test/cases/base_test.rb:1513]: ActiveRecord::ReadOnlyError expected but nothing was raised. rails test test/cases/base_test.rb:1510 ............................................................................................................F Failure: BasicsTest#test_updating_a_record_raises_if_preventing_writes [test/cases/base_test.rb:1503]: ActiveRecord::ReadOnlyError expected but nothing was raised. rails test test/cases/base_test.rb:1500 .......... Finished in 2.534490s, 62.7345 runs/s, 149.5370 assertions/s. 159 runs, 379 assertions, 3 failures, 0 errors, 1 skips ```
* | | | Prevent write queries for `exec_query`Ryuta Kamizono2018-12-112-1/+9
| | | | | | | | | | | | | | | | Follow up #34505.
* | | | Merge pull request #34632 from rails/rename-write-on-read-errorEileen M. Uchitelle2018-12-074-3/+7
|\ \ \ \ | | | | | | | | | | Rename error that occurs when writing on a read
| * | | | Rename error that occurs when writing on a readEileen Uchitelle2018-12-074-3/+7
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | I originally named this `StatementInvalid` because that's what we do in GitHub, but `@tenderlove` pointed out that this means apps can't test for or explitly rescue this error. `StatementInvalid` is pretty broad so I've renamed this to `ReadOnlyError`.
* | | | | #create_or_find_by/!: add more tests and fix docs (#34653)Bogdan2018-12-081-2/+2
|/ / / / | | | | | | | | | | | | | | | | | | | | | | | | | | | | * `#create_or_find_by/!`: add more tests * Fix docs of `create_or_find_by` This method uses `find_by!` internally.
* | | | Fix join table column quoting with SQLite.Gannon McGibbon2018-12-051-0/+4
| | | |
* | | | option to disable scopes that `ActiveRecord.enum` generates by defaultAlfred Dominic2018-12-041-2/+5
| | | |
* | | | Merge pull request #34609 from kamipo/delete_all_on_collection_proxyRyuta Kamizono2018-12-042-0/+3
|\ \ \ \ | | | | | | | | | | | | | | | Ensure that `delete_all` on collection proxy returns affected count
| * | | | Ensure that `delete_all` on collection proxy returns affected countRyuta Kamizono2018-12-042-0/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Unlike the `Relation#delete_all`, `delete_all` on collection proxy doesn't return affected count. Since the `CollectionProxy` is a subclass of the `Relation`, this inconsistency is probably not intended, so it should return the count consistently.
* | | | | Reset scope after collection deleteGannon McGibbon2018-12-041-4/+4
|/ / / / | | | | | | | | | | | | | | | | Reset scope after delete on collection association to clear stale offsets of removed records.
* | | | Merge pull request #34602 from guizmaii/masterRafael França2018-12-031-1/+2
|\ \ \ \ | | | | | | | | | | Pass the `connection` to the `@instrumenter.instrument` method call
| * | | | Pass the `connection` to the `@instrumenter.instrument` method calljules Ivanic2018-12-031-1/+2
| | | | |
* | | | | Address "warning: shadowing outer local variable - parts"Ryuta Kamizono2018-12-034-7/+8
|/ / / / | | | | | | | | | | | | And hide the `READ_QUERY` internal constant.
* | | | Clarify no support for non PK id columnsGannon McGibbon2018-11-301-5/+6
| | | | | | | | | | | | | | | | [ci skip]
* | | | Add ability to prevent writes to a databaseEileen Uchitelle2018-11-305-1/+64
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This PR adds the ability to prevent writes to a database even if the database user is able to write (ie the database is a primary and not a replica). This is useful for a few reasons: 1) when converting your database from a single db to a primary/replica setup - you can fix all the writes on reads early on, 2) when we implement automatic database switching or when an app is manually switching connections this feature can be used to ensure reads are reading and writes are writing. We want to make sure we raise if we ever try to write in read mode, regardless of database type and 3) for local development if you don't want to set up multiple databases but do want to support rw/ro queries. This should be used in conjunction with `connected_to` in write mode. For example: ``` ActiveRecord::Base.connected_to(role: :writing) do Dog.connection.while_preventing_writes do Dog.create! # will raise because we're preventing writes end end ActiveRecord::Base.connected_to(role: :reading) do Dog.connection.while_preventing_writes do Dog.first # will not raise because we're not writing end end ```
* | | | Merge pull request #34572 from kamipo/fix_scoping_with_query_methodRyuta Kamizono2018-11-301-1/+1
|\ \ \ \ | | | | | | | | | | Fix the scoping with query methods in the scope block
| * | | | Fix the scoping with query methods in the scope blockRyuta Kamizono2018-11-301-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Follow up #33394. #33394 only fixes the case of scoping with klass methods in the scope block which invokes `klass.all`. Query methods in the scope block also need to invoke `klass.all` to be affected by the scoping.
* | | | | Use the full link URL instead of bit.ly [ci skip]Ryuta Kamizono2018-11-301-1/+2
| | | | |
* | | | | Allow aliased attributes in updateGannon McGibbon2018-11-291-3/+7
| | | | | | | | | | | | | | | | | | | | Allow aliased attributes to be used in `#update_columns` and `#update`.
* | | | | Merge pull request #34562 from ruralocity/active-record-query-docs-improvementRafael França2018-11-281-7/+9
|\ \ \ \ \ | | | | | | | | | | | | Improve ActiveRecord::Querying documentation [ci skip]
| * | | | | Improve ActiveRecord::Querying documentation [ci skip]Aaron Sumner2018-11-281-7/+9
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * Break up long sentences * Reword some sentences to clarify subject, predicate, and object * Explain drawbacks of using count_by_sql
* | | | | | Allow spaces in postgres table namesGannon McGibbon2018-11-281-1/+1
|/ / / / / | | | | | | | | | | | | | | | | | | | | Fixes issue where "user post" is misinterpreted as "\"user\".\"post\"" when quoting table names with the postgres adapter.
* | | | | Merge pull request #34557 from sergioisidoro/sergio-patch-load-errorRafael França2018-11-281-2/+2
|\ \ \ \ \ | |_|_|/ / |/| | | | Patch load error in case GemSpecError
| * | | | Patch load error in case GemSpecErrorsergioisidoro2018-11-281-2/+2
| | | | |
* | | | | Merge pull request #33835 from schneems/schneems/faster_cache_versionSean Griffin2018-11-271-2/+50
|\ \ \ \ \ | | | | | | | | | | | | Use raw time string from DB to generate ActiveRecord#cache_version
| * | | | | Prefer String#ljust over String#<< for paddinglsylvester2018-10-171-3/+2
| | | | | |