Commit Graph

22654 Commits

Author SHA1 Message Date
zzak
722d4f6582
Unlink Rails constant from READMEs 2023-05-29 15:14:44 +09:00
zzak
3b1f1580ab
Trick RDoc to pickup ActiveRecord::Core#values_at 2023-05-29 10:36:27 +09:00
Guillermo Iguaran
c49bd00a4a
Merge pull request #48303 from ryanhertz/transaction-after-commit
fix after_commit callback when record is destroyed twice
2023-05-26 11:00:57 -07:00
fatkodima
4e0079f09a Preserve existing column default functions when altering table in SQLite 2023-05-26 14:09:52 +03:00
Rafael Mendonça França
54ec908a2d
Merge pull request #47940 from fatkodima/fix-alias-where-missing
Remove table alias added when using `where.missing` or `where.associated`
2023-05-25 23:04:37 -04:00
Ryan Hertz
e8ae4ecd5c
fix after_commit callback when record is destroyed twice
When `destroy` is called twice on a persisted record inside a
transaction, the after_commit callbacks fail to run. The second
time `destroy` is called, `@_trigger_destroy_callback` is set to false
because the record has already been deleted, even though the
transaction hasn't completed yet, and the after_commit callbacks haven't
had a chance to run from the first `destroy`.
2023-05-25 14:58:02 -07:00
Eileen M. Uchitelle
58827663e2
Merge pull request #48300 from eileencodes/fix-deprecation-message-for-connection-pool-methods
Fix deprecation message for connection pool methods
2023-05-25 14:41:19 -04:00
Jon Zeppieri
6debbcae78 Remove changelog entry for Arel feature
As @rafaelfranca points out, Arel is private, so changes to it
don't go in the changelog.
2023-05-25 09:27:34 -04:00
eileencodes
6bd812326c
Fix deprecation message for connection pool methods
This deprecation was added in main as of 7.1 so the message shouldn't
mention 7.1, it should mention the next version of Rails.
2023-05-25 08:54:01 -04:00
Aaron Patterson
2dbc7dbac8
Merge pull request #48261 from 97jaz/arel-cte-node
Adds Arel::Nodes::Cte for use in WITH expressions
2023-05-24 16:53:29 -07:00
Rafael Mendonça França
8f9fb1e042
Merge pull request #47181 from spencerneste/model_generator_custom_migration_template
Model Generator Source Paths Should Allow for Customization
2023-05-24 19:28:05 -04:00
Jon Zeppieri
355b65ddb4 Adds Arel::Nodes::Cte for use in WITH expressions
SelectManager#with currently accepts As and TableAlias nodes.
Neither of these support materialization hints for the query
planner. Both Postgres and SQLite support such hints.

This commit adds a Cte node that does support materialization
hints. It continues to support As and TableAlias nodes by
translating them into Cte nodes.
2023-05-24 19:19:21 -04:00
Rafael Mendonça França
b070c4d610
Simplify the implementation to register the correct source_path for the migration template 2023-05-24 22:54:12 +00:00
zzak
073269c9b9
Merge pull request #48288 from zzak/rdoc-fixed-width-namespaces
Use short-form fixed-width RDoc form for namespaces
2023-05-25 07:14:47 +09:00
Spencer Neste
a8fe415f85
Model Generator Source Paths Should Allow for Customization
Co-authored-by: Joshua Flanagan <joshuaflanagan@gmail.com>
2023-05-24 22:13:45 +00:00
zzak
38bef29064
Replace all occurrences of '<tt>(\w+::\w+::\w+)</tt>' with '+$1+'
E.g.:

* <tt>Rails::Command::NotesCommand</tt> -> +Rails::Command::NotesCommand+

Co-authored-by: Hartley McGuire <skipkayhil@gmail.com>
2023-05-25 06:56:17 +09:00
zzak
e3c73fd183
Replace all occurrences of '<tt>(\w+::\w+)</tt>' with '+$1+'
E.g.:

* <tt>ActiveRecord::Base</tt> -> +ActiveRecord::Base+

Co-authored-by: Hartley McGuire <skipkayhil@gmail.com>
Co-authored-by: Petrik de Heus <petrik@deheus.net>
2023-05-25 06:52:32 +09:00
Chris Salzberg
908f1c9bbc Automatically add test/fixtures in engines to fixture_paths
Introduces a new engine initializer, `add_fixture_paths`, which
automatically adds a `test/fixtures` folder under the engine root to
`fixture_paths` if such a folder exists.
2023-05-24 17:01:25 +09:00
Hartley McGuire
2ba2090eac
Fix NameError in Mysql2::DatabaseStatements
The recent [refactor][1] to the MySQL DatabaseStatements classes renamed
Mysql::DatabaseStatements to Mysql2::DatabaseStatements. That commit
also updated most of the references to the top level Mysql2 to be
explicit since Ruby will now assume they refer to
ActiveRecord::ConnectionAdapters::Mysql2. However, Mysql2::Error was not
updated, and that rescue will currently raise:

```
NameError: uninitialized constant ActiveRecord::ConnectionAdapters::Mysql2::Error
```

if the execute raises any error.

To fix this, Mysql2 must be changed to explicitly refer to the top level
namespace.

[1]: 93b5fc1f95e04b6a51f3e8dd2c885ba9ddd139a6
2023-05-23 13:42:32 -04:00
Jean Boussier
108617eb74 Fix change_in_place? for binary serialized columns
Followup: https://github.com/rails/rails/pull/40383
Fix: https://github.com/rails/rails/issues/48255
Fix: https://github.com/rails/rails/pull/48262

If the serialized attribute is backed by a binary column, we must ensure
that both the `raw_old_value` and the `raw_new_value` are casted to
`Binary::Data`.

Additionally, `Binary::Data` must cast it's backing string in
`Encoding::BINARY` otherwise comparison of strings containing bytes
outside the ASCII range will fail.
2023-05-22 13:01:42 +02:00
Jean Boussier
a3587cd6f9
Merge pull request #48271 from piecehealth/fix_ar_conn_verify
Rescue Exception while the connection pool 'checkout_and_verify'
2023-05-22 11:54:03 +02:00
Jean Boussier
785f65680b TrilogyAdapter: translate Trilogy::TimeoutError in AdapterTimeout
Prior to this patch it would translate it to `InvalidStatement` which
is the catch all and is hard to work with.
2023-05-22 10:05:11 +02:00
Kang Zhang
3b814f9866 Rescue Exception while the connection pool 'checkout_and_verify' 2023-05-22 14:23:58 +08:00
Hartley McGuire
2d98df02f9
Fixup links for CollectionProxy docs
Add some link and code blocks, and correct some docs referring to
methods on ActiveRecord::Base that are not.
2023-05-19 18:49:55 -04:00
Jean Boussier
f1b15971a5 Implement ActiveRecord.disconnect_all! to close all connections
This is basically a multi-db aware version of `ActiveRecord::Base.connection.disconnect!`.
It also avoid connecting to the database if we weren't already.

This can be useful to reset state after `establish_connection` has been used.
2023-05-19 13:19:31 +02:00
Yasuo Honda
a6bfa6c6e3
Merge pull request #48237 from a5-stable/fix-precision-maximum-for-mysql
fix a comment on `add_column` regarding the maximum value of precision in MySQL
2023-05-18 08:58:17 +09:00
a5-stable
ac1184d637 fix precision explanation for mysql 2023-05-17 01:26:03 +09:00
a5-stable
271562d82c call eq when begin and end are the same 2023-05-16 23:37:49 +09:00
zzak
9d2c6597cb
Use RDoc syntax for :uuid argument (re #47949) 2023-05-16 18:27:14 +09:00
Guillermo Iguaran
92d29fe0f9
Merge pull request #48231 from Shopify/conver-auto-population-of-auto-generated-uuid
[Tests only] Populate auto-generated UUID primary key
2023-05-15 20:25:09 -07:00
Nikita Vasilevsky
2f29722e7f
[Tests only] Populate auto-generated UUID primary key 2023-05-15 21:20:01 +00:00
Eileen M. Uchitelle
91481b180f
Merge pull request #48037 from fatkodima/index-include-as-strings
Return `INCLUDE` columns in PostgreSQL indexes as strings
2023-05-15 14:49:51 -04:00
eileencodes
942785fb8b
Revert "Merge pull request #48188 from eileencodes/revert-48069"
This reverts commit 6adaeb864946718f71746958d3463e5c0a266b30, reversing
changes made to a792a62080b82f776ca62bbc85af45ee73fe368e.

We're going to forward fix this in our application rather than keep this
revert in. Reverting other changes has turned out to be too difficult to
get back to a state where our application is retrying queries.
2023-05-15 10:38:36 -04:00
Nick Dower
bdd0015873 Discard connections which may be left in a transaction
Partially Fixes #48164

Today, connections are discarded in `within_transaction` if rolling back
fails after the call to `yield` raises. This is done to prevent a
connection from being left in a transaction if the rollback actually
failed.

This change causes connections to be discarded in the following
additional cases where the connection may be left in a transaction:
- If beginning the transaction fails.
- If rolling back the transaction fails.
- If committing the transaction fails, then rolling back fails.

This is accomplished by rescuing all exceptions raised in
`within_transaction` and discarding the connection if the transaction
has not been been both initialized and completed.
2023-05-13 11:41:05 +02:00
Olivier
e394c38f3e
Update ActiveRecord CHANGELOG.md 2023-05-11 10:54:13 -04:00
Scott Holden
c5a99e044e Allow PredicateBuilder to recognize schema namespaced table names. [Fix #48172] 2023-05-10 17:47:14 -07:00
eileencodes
338e1f785a
Revert "Merge pull request #48069 from Shopify/ar-exec-query-flush-cache"
This reverts commit 663df3aa095cc90b1a2f1616ba472672ea606f73, reversing
changes made to 9b4fff264e035f08b263c189f5899b114c4feadd.

The changes here forced our code through a different codepath,
circumventing the patch on `execute` to retry queries. Since we also
patch `execute` from Semian it's not clear the correct path forward and
we're going to revert for now.
2023-05-10 14:17:48 -04:00
Jonathan Hefner
b3cecf09d6 Prevent duplicate filters for encrypted attributes
When an Active Record encrypted attribute is declared, a filter for it
is automatically added to `config.filter_parameters`.  Prior to this
commit, the filter would be re-added every time the model was reloaded:

  ```ruby
  class Post < ActiveRecord::Base
    encrypts :title
  end
  ```

  ```irb
  irb> Rails.application.config.filter_parameters
  # => [:passw, ..., :ssn]

  irb> Post

  irb> Rails.application.config.filter_parameters
  # => [:passw, ..., :ssn, "post.title"]

  irb> reload!
  irb> Post

  irb> Rails.application.config.filter_parameters
  # => [:passw, ..., :ssn, "post.title", "post.title"]
  ```

This commit ensures filters are only added once so that
`config.filter_parameters` does not grow unbounded.
2023-05-09 16:28:30 -05:00
fatkodima
05a45c17bd
Merge pull request #48082 from ybakos/ar_counter_cache_examples
Use pluralized counter names in the ActiveRecord `update_counters` method docs
2023-05-09 19:45:04 +03:00
Jonathan Hefner
d6da86a476 Prevent non-anonymous modules from becoming frozen
In #48106, `Module#deep_dup` was changed to return the module itself
(not a copy) when the module is not anonymous.  However, that causes
non-anonymous modules to become frozen via `value.deep_dup.freeze` when
passed to `ActiveModel::Type::Helpers::Mutable#immutable_value`.  So,
for example, class attributes can no longer be set on the module.

To prevent such issues, this commit removes the `freeze` from
`immutable_value`.  `immutable_value` is only called by
`ActiveRecord::PredicateBuilder#build_bind_attribute`, which only cares
that other code cannot mutate the value, not that the value is actually
frozen.
2023-05-09 10:51:00 -05:00
eileencodes
74898d9b54
Clean up docs and code using mysql2
This PR does the following:

* Adds `trilogy` to lists of adapters where applicable
* Uses `MySQL` instead of adatper names where applicable
* Splits type information into adapters code so that the adapter is set
correctly.
* Fix tests that were using mysql2 when they should be abstract
* Add load hook for trilogy to match mysql2
2023-05-09 10:41:27 -04:00
Jonathan Hefner
016b796ee9 Link to QueryMethods#and [ci-skip]
Specifying `QueryMethods#and` instead of merely `and` avoids ambiguity
with Ruby's `and` operator, and the `QueryMethods#and` documentation
provides a usage example.
2023-05-08 12:05:13 -05:00
Petrik de Heus
ef2ea118dc
Merge pull request #48153 from JoeDupuis/fix-arel-doc-code-block
Fix a code block in the Arel documentation
2023-05-07 19:45:32 +02:00
sampatbadhe
85dc814fd6 Update changelog for https://github.com/rails/rails/pull/48110 2023-05-07 08:54:30 +05:30
Jean Boussier
89a5d6ada5 Make Active Record's query cache an LRU
I don't know how prevalent this really is, but I heard several time
about users having memory exhaustion issues caused by the query cache
when dealing with long running jobs.

Overall it seems sensible for this cache not to be entirely unbounded.
2023-05-07 11:16:56 +09:00
Joe Dupuis
4ab06e21de Fix a code block in the Arel documentation
`+?+` doesn't compile to a code block.
2023-05-06 18:57:12 -07:00
Joe Dupuis
dd1761e6bb Fix a Gem::Version Comparison
Gem::Version comparison against strings breaks for older versions of
RubyGems.
2023-05-06 17:08:44 -07:00
Guillermo Iguaran
74e24aef41
Merge pull request #48140 from btoews/merge-docs
[ci skip] Clarify difference in docs between AR #and and #merge methods
2023-05-06 01:00:37 -07:00
sampatbadhe
821c7df07c correct typo 2023-05-06 06:43:40 +05:30
eileencodes
03379d1f59
Deprecate check_pending! in favor of check_all_pending!
`check_pending!` takes a connection that defaults to `Base.connection`
(or migration_connection but right now that's always Base.connection).
This means that we aren't able to loop through all the configs for an
environment because this is a public API that accepts a single
connection. To fix this I've deprecated `check_pending!` in favor of
`check_all_pending!` which will loop through the configs and check for
pending migrations on all the connections.

Example results:

```
Migrations are pending. To resolve this issue, run:

        bin/rails db:migrate

You have 3 pending migrations:

db/migrate/20221213152217_create_posts.rb
db/migrate/20230503150812_add_active_column_to_posts.rb
db/secondary_migrate/20230503173111_create_dogs.rb
```

Before this change, only migrations in `db/migrate` or
`db/secondary_migrate` would be output by `ActiveRecord::Migration.check_pending!`.
I chose not to accept a connection or db_config argument for this new
method because it's not super useful. It's more useful to know all
pending migrations. If it becomes problematic, we can reimplement the
connection option on this method (or reintroduce `check_pending!`.
2023-05-05 13:55:58 -04:00