💇♀️
Fix specs
Update activerecord/lib/active_record/relation.rb
Co-authored-by: Eugene Kenny <elkenny@gmail.com>
Update activerecord/lib/active_record/relation.rb
Co-authored-by: Viktar Basharymau <6alliapumob@gmail.com>
Use class attribute instead of mattr_accessor
Add destroy all test case around value returned
add Rails.application.config.active_record.destroy_all_in_batches too new defaults framework
Reset Active Record Relation
Document ActiveRecord::Relation#destroy_all
Add changelog entry and update docs
💇♀️
Update method signature and argument docs
Apply suggestions from code review
Co-authored-by: Viktar Basharymau <6alliapumob@gmail.com>
Co-authored-by: Alberto Almagro <albertoalmagro@gmail.com>
Applications can set their migrations to ignore exceptions raised when adding a foreign key that already exists or when removing a foreign key that does not exist.
Add test cases
💇♀️
Previously if there were 2 migrations in one db and 1 migration in the
other db all the migrations for db one would run and then all migrations
for db two would run. If a migration in one database depended on a
migration in another database then it could fail. This is probably
pretty rare, however in a multi-db application that's moving tables from
one db to another, running them out of order could result in a migration
error.
In this this change we collect all the versions for each migration and
the corresponding db_config so we can run them in the order they are
created rather than per-db.
Closes#41664
Related #41538
Co-authored-by: John Crepezzi <john.crepezzi@gmail.com>
Co-authored-by: Kiril Dokh <dsounded@gmail.com>
This reverts commit 951deecc52f191ca85bd5c0416b382f4852c6f72.
This change prevents applications from testing replicas and would
require explicitly setting `prevent_writes` when connecting to reading
roles in `connected_to`. For now we'll revert this until there's a
longer term fix in place
💇♀️
Set precision 6 by detauls for datime columns when using sqlite3_adapter
Set precision 6 by detauls for datime columns when using postgresql_adapter
Update activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb
Co-authored-by: Zachary Scott <zzakscott@gmail.com>
Update tests precision
Add datetime precision by using the migration compatibility layer
Add default precision when adding new column for a table
Fix compatibility tests
Add changelog entry
Update postgres test cases
Custom type does not support precision
Typo ⌨️
Fix specific mysql2 schema
💇♀️
When a model has an STI enum type, the type wasn't properly applied when
disable joins was set to true. In this case we need to apply the scope
from the association in `add_constraints` so that `type` is included in
the query. Otherwise in a `has_one :through` with `type` all records
will be returned because we're not filtering on type.
Long term I think this might be in the wrong place and that we want to
do this in a new definition of `target_scope` but that's a future
refactoring that needs to be done.
Strict loading mode `:n_plus_one_only` is only
supported on single records, not associations or
models. Using an ivar instead of class_attribute
ensures that this cannot be set globally. This
fixes a bug where setting `strict_loading_mode`
caused errors to be silent when
`strict_loading_by_default` is true.
Fixes#42576
Co-Authored-By: John Hawthorn <john@hawthorn.email>
This is a followup to #42537 because that PR only fixed the bug for the
new connection handling but not legacy connection handling.
In #41549 a user was getting an error that the `pool_config` was `nil`
so the `all_connection_pools` method would raise an error. After getting
a reproduction application I saw that if the application is
misconfigured this can happen. For example, if an application uses
`:all` for the writing role but does not set
`config.active_record.writing_role = :all` then the
`setup_shared_connection_pool` pool method will get a `nil` value for
the `writing_pool_config` and set that in `set_pool_config`. I
considered fixing this in `setup_shared_connection_pool` directly and
raising an error there, but there's a possibility this _can_ happen in
an external gem or application code if they're using these private APIs
and realistically we never want any code, Rails or otherwise, to be able
to set a `nil` pool config in the pools.
This test is about connection swapping but not nested connections so it
fits better in the connection handler test. Additionally I renamed the
tests to make more sense and removed unnecessary parts like using
ApplicationRecord, the bug is reproducible on ActiveRecord::Base alone.
Instance dependent associations are associations which are defined with
a scope taking an argument which makes the scope they are selected from
dependent on the owner record.
This presented a challenge for preloading and eager_loading, since each
record's association being loaded could require a different scope.
Previously this raised an exception if attempted.
This commit adds the ability to preload instance dependent scopes (eager
loading is still unsupported). This is done by detecting instance
dependent scopes in the preloader and building the scope and
Preloader::Association for each record. Because we now merge similar
scopes later in the preloading process, any records which end up with
the same instance dependent scope will be loaded from a single query.
In the case that there's a different scope for each record, this will
perform N+1 queries. I think it's up to the app developer to consider
this (this is essentially the same as preloading polymorphic scopes).
Co-authored-by: John Crepezzi <john.crepezzi@gmail.com>
Co-authored-by: Adam Hess <HParker@github.com>
Co-authored-by: Eileen M. Uchitelle <eileencodes@gmail.com>
Co-authored-by: Dinah Shi <dinahshi@github.com>
In #41549 a user was getting an error that the `pool_config` was `nil`
so the `all_connection_pools` method would raise an error. After getting
a reproduction application I saw that if the application is
misconfigured this can happen. For example, if an application uses
`:all` for the writing role but does not set
`config.active_record.writing_role = :all` then the
`setup_shared_connection_pool` pool method will get a `nil` value for
the `writing_pool_config` and set that in `set_pool_config`. I
considered fixing this in `setup_shared_connection_pool` directly and
raising an error there, but there's a possibility this _can_ happen in
an external gem or application code if they're using these private APIs
and realistically we never want any code, Rails or otherwise, to be able
to set a `nil` pool config in the pools.
Note: In the test I made a new connection handler so that we have
isolated pools to test against. Otherwise we'll be testing against the
existing pools but we don't want to mess those up.
Closes#41549