Commit Graph

19387 Commits

Author SHA1 Message Date
Kevin Deisz
b8ae104318
Support strict_loading on association declarations 2020-02-21 13:11:24 -05:00
Eugene Kenny
9e40348645 Enable HashTransformKeys and HashTransformValues cops
Followup to 88fe76e69328d38942130e16fb65f4aa1b5d1a6b.

These are new in RuboCop 0.80.0, and enforce a style we already prefer
for performance reasons (see df81f2e5f5df46c9c1db27530bbd301b6e23c4a7).
2020-02-20 22:37:32 +00:00
Gannon McGibbon
89d1d39c8f
Merge pull request #38394 from javiyu/fix-double-object-on-inverse-creation
Fix: on accessing the parent record before creation with has_many_inv…
2020-02-20 15:53:21 -05:00
Carlos Antonio da Silva
3656bd81c3 Fix/improve strict_loading examples [ci skip]
Follow-up of ac9b11a830c98b48f2b08c32fc28873abcaed313.
2020-02-20 13:25:22 -03:00
eileencodes
dbb92f8a77
Add strict_loading mode to prevent lazy loading
Add `#strict_loading` to any record to prevent lazy loading of associations.
`strict_loading` will cascade down from the parent record to all the
associations to help you catch any places where you may want to use
`preload` instead of lazy loading. This is useful for preventing N+1's.

Co-authored-by: Aaron Patterson <aaron.patterson@gmail.com>
2020-02-20 08:32:48 -05:00
Javier Jimenez
3f86157732 Fix: on accessing the parent record before creation with has_many_inversing adds two records to association 2020-02-20 09:26:47 +01:00
Eugene Kenny
4f92aa6741 Copy argument in AttributeAssignment#attributes=
Before df186bd16f0d4a798e626297277fc6b490c1419e, `assign_attributes` and
`attributes=` were both defined in Active Model and both made a copy of
their argument. Now `assign_attributes` is overridden in Active Record
and the copy happens there instead, but `attributes=` isn't overridden.

This meant that assigning nested or multi-parameters via `attributes=`
would mutate the argument, which the copying was meant to prevent.
2020-02-16 23:40:03 +00:00
Kasper Timm Hansen
bb6607aa1c
Merge pull request #38469
Closes #38469
2020-02-17 00:26:24 +01:00
Andrey Koleshko
2299414f54
[ci skip] Improve docs for :foreign_key in migrations 2020-02-17 00:26:10 +01:00
davidauza-engineer
e3d496acf9 Update examples Migration versions to 6.0 [ci skip] 2020-02-16 15:38:51 -05:00
Rafael França
df186bd16f
Merge pull request #38401 from vinistock/stop_stringifying_during_attribute_assignment
Do not stringify attributes in assign_attributes
2020-02-13 16:54:35 -05:00
Rafael França
40c7c5e991
Merge pull request #38432 from kytrinyx/schema-cache-serialization-strategy-2
Expose Marshal as a legit SchemaCache serialization strategy
2020-02-13 14:57:41 -05:00
Katrina Owen
9a356fcd42
Support marshal as a schema cache serialization strategy 2020-02-13 11:59:35 -07:00
Katrina Owen
b71c1cdddd
Push schema cache loading into schema cache class 2020-02-13 11:59:11 -07:00
Kasper Timm Hansen
d632a51bfd
Merge pull request #37729 from anderscarling/patch-1
Respect config.log_level in console
2020-02-13 18:36:44 +01:00
Ryuta Kamizono
ac7eee44f0
Merge pull request #38438 from kamipo/fix_association_query_with_custom_handler
Registered predicate handler should be used for association queries
2020-02-13 11:47:53 +09:00
Ryuta Kamizono
f330f37c7a Registered predicate handler should be used for association queries
This issue is caused due to association queries uses newly created fresh
onetime predicate builder, it doesn't realize registered predicate
handler. To fix the issue, dup the predicate builder for the klass
instead of newly creating.

Fixes #38239.
2020-02-12 17:09:20 +09:00
Ryuta Kamizono
a8398e0e5b OID type should accept a value range of unsigned integers
Related #38425.
2020-02-12 16:42:33 +09:00
Ryuta Kamizono
8d57cb39a8
Merge pull request #38425 from everwise/oid-overflow
Fix load_additional_types handling of large OIDs
2020-02-12 16:27:48 +09:00
Katrina Owen
0a51442722
Push db schema cache dump into schema cache class 2020-02-11 15:11:46 -07:00
Katrina Owen
c565cbe738
Use correct fallback in schema cache initializer
Hopefully third time's a charm.

Originally, the schema cache initializer railtie was loading
the 'schema_cache.yml' file by hard-coding the path.

Since it's possible to override the schema cache path either by
providing an ENV variable, or by adding a configuration entry to
the database.yml config file, this means that we could potentially
end up not loading a cache that is configured to use a non-default
file.

The first attempt at fixing this (#38348) assumed that the
db config must contain a spec named 'primary'. This is not the case.
A second attempt at fixing this (#38383) bailed if no db config
was found.

This however, means that for an app without a db config named
'primary', we would not be attempting to load a schema cache
at all, even if they were using the default schema cache path.

Instead of bailing, here we go get the filename, passing a 'nil'
for the schema_cache_path, which will fall back to the default
path.
2020-02-11 10:17:27 -07:00
Chandan Jhunjhunwal
09ddc083d8 [ci skip] ActiveRecord::Querying-find_by_sql-documentation-fix 2020-02-11 17:25:16 +05:30
Rocky Meza
8d57457fb8 Fix load_additional_types handling of large OIDs
In Postgres, OIDs are *unsigned* 4 byte integers. Postgres allows
casting oids to integers so that you can have access to more operators;
however, doing this could lead to some issues if the oids are very large
as they might around to the negative number range.

From the Postgres docs:

> The oid type itself has few operations beyond comparison. It can be
> cast to integer, however, and then manipulated using the standard
> integer operators. (Beware of possible signed-versus-unsigned
> confusion if you do this.)

In most real-world databases this is never going to be a problem. In
order to reach the overflow, you have to have 2,147,483,648 objects in
your database (not rows, but relations, types, views, etc.). In extreme
cases though it is possible to reach that number and encounter some
buggy behavior.

See: https://www.postgresql.org/docs/12/datatype-oid.html
2020-02-10 11:00:22 -05:00
Kurtis Rainbolt-Greene
ef7599fe91
Extract internal ActiveSupport::ConfigurationFile object
Rails has a number of places where a YAML configuration file is read,
then ERB is evaluated and finally the YAML is parsed.

This consolidates that into one common class.

Co-authored-by: Kasper Timm Hansen <kaspth@gmail.com>
2020-02-10 02:50:12 +01:00
Kasper Timm Hansen
534fc4f0c8
Merge pull request #37627
Closes #37627
2020-02-10 01:00:30 +01:00
Bob Lail
3a8668bd73
Touch updated_at when upsert_all modifies a record
- When a user passes `updated_at` to `upsert_all`, the given value is used.
- When a user omits `updated_at`, `upsert_all` touches the timestamp if (but only if) any upserted values differ.

Preserve Rails' ability to generate intelligent cache keys for ActiveRecord when using `upsert_all` frequently to sync imported data.
2020-02-10 01:00:03 +01:00
Vinicius Stock
d472111a81
Add ar assign_attributes to avoid unnecessary attributes dup 2020-02-07 16:40:48 -05:00
Vinicius Stock
2e9e940e22
Change safe guard to check for each_pair instead of stringify_keys 2020-02-07 11:36:35 -05:00
Vinicius Stock
112c3ec0f5
Only dup attributes in activerecord attribute_assignment 2020-02-06 17:02:56 -05:00
Vinicius Stock
8b59960cd4
Do not stringify attributes in assign_attributes 2020-02-06 16:27:24 -05:00
Erik Berlin
fdaa31896c Fix grammar and diction of NOR conditions warning message 2020-02-06 13:24:05 -08:00
Sebastián Palma
db6eb846eb This PR adds support to retrieve partitioned indexes when asking for
indexes in a table.

Currently the pg_class catalog is filtered out to retrieve the indexes in a
table by its relkind value. Which in versions lower than 11 of PostgreSQL
is always `i` (lower case). But since version 11, PostgreSQL
supports partitioned indexes referenced with a relkind value of `I`
(upper case). This makes any feature within the current code base to exclude those
partitioned indexes.

The solution proposed is to make use of the `IN` clause to filter those
relkind values of `i` and/or `I` when retrieving a table indexes.
2020-02-06 07:36:44 +02:00
Aaron Patterson
25c3807956
Merge pull request #38383 from kytrinyx/schema-spec-fallback-config
Add a fallback database config when loading schema cache
2020-02-05 08:52:51 -08:00
Katrina Owen
a13c134f64
Don't try to autoload cache if no primary spec is found 2020-02-05 08:08:37 -07:00
Ryuta Kamizono
6a80902663 Fix foreign_key_exists? in change_table to allow keyword arguments 2020-02-05 09:03:15 +09:00
T.J. Schuck
6af50a9067 Change all "can not"s to the correct "cannot"
It's been 6 years since [the original](https://github.com/rails/rails/pull/13584), so we're overdue for a sequel.

The correct word is "cannot", one word, not "can not", two words.
2020-02-04 16:46:55 -05:00
Katrina Owen
464d997076
Add a fallback database config when loading schema cache
The schema cache defaults to loading the 'primary' database config.
However, if an app doesn't have a db config with a spec name of
'primary' the filename lookup will blow up.

This adds a fallback for this case.
2020-02-04 13:00:05 -07:00
Ryuta Kamizono
db8e957c84 Fix non-condition elsif 2020-02-01 09:02:45 +09:00
Carlos Antonio da Silva
d3e6eea755 Fix markdown in Active Record changelog [ci skip]
Follow-up c280ae72c81a09f448a3853a7604a7368fc8b486.
2020-01-30 14:53:21 -03:00
Eileen M. Uchitelle
c280ae72c8
Merge pull request #38352 from eileencodes/add-support-for-if-exists
Add support for `if_exists/if_not_exists` on `remove_column/add_column`
2020-01-30 12:42:46 -05:00
eileencodes
95ed7e7809
Add support for if_exists/if_not_exists on remove_column/add_column
This PR adds support for `if_exists` on `remove_column` and
`if_not_exists` on `add_column` to support silently ignoring migrations
if the remove tries to remove a non-existent column or an add tries to
add an already existing column.

We (GitHub) have custom monkey-patched support for these features and
would like to upstream this behavior.

This matches the same behavior that is supported for `create_table` and
`drop_table`. The behavior for sqlite is different from mysql/postgres
and sqlite for remove column and that is reflected in the tests.
2020-01-30 09:50:44 -05:00
Eileen M. Uchitelle
e6f95ecfd3
Merge pull request #38348 from kytrinyx/schema-cache-load-correct-file
Use correct filename for schema cache on load
2020-01-30 08:17:44 -05:00
John Hawthorn
c801763628
Merge pull request #37614 from jhawthorn/transform_values
Use transform_values to build hash_rows
2020-01-29 15:11:54 -08:00
Katrina Owen
e95b3fd21f
Use correct filename for schema cache on load
The initializer that loads the default schema cache on the default
connection doesn't account for the case where an app overrides the
default filename either via ENV["SCHEMA_PATH"], or via the
:schema_cache_path defined in the db config.

Note that as discussed in #34449 this initializer doesn't work for
applications using multiple databases, and this change doesn't fix that.
2020-01-29 21:43:19 +00:00
Ryuta Kamizono
1f08fec27e Generalize FrozenError on write attribute 2020-01-29 11:23:41 +09:00
Ryuta Kamizono
21c89dcc75 Using define_attribute_method on ivar attrs is not officially supported
It doesn't work dirty tracking on Active Record. Use `attribute` API
instead.
2020-01-29 09:56:27 +09:00
Ryuta Kamizono
5aae2b2783 Simplify RUBY_VERSION checking in tests 2020-01-29 09:31:00 +09:00
Ryuta Kamizono
df9b61f38f Fix CI failure on Ruby master
Ref https://github.com/ruby/ruby/pull/2857.
2020-01-29 09:22:25 +09:00
Eileen M. Uchitelle
1795a2f5e8
Merge pull request #38339 from eileencodes/force-connected_to-to-load-the-relation
Force connected_to to load the records if it's a Relation
2020-01-28 14:40:57 -05:00
Ryuta Kamizono
c4edca3612 Fix test_with_abstract_class_scope_should_be_executed_in_correct_context
To allow MS SQL Server's quote.
2020-01-29 03:50:21 +09:00