activerecord 7.2.4 → 8.1.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +1013 -878
- data/README.rdoc +1 -1
- data/lib/active_record/association_relation.rb +2 -1
- data/lib/active_record/associations/association.rb +69 -27
- data/lib/active_record/associations/association_scope.rb +1 -1
- data/lib/active_record/associations/belongs_to_association.rb +2 -2
- data/lib/active_record/associations/builder/association.rb +23 -11
- data/lib/active_record/associations/builder/belongs_to.rb +36 -8
- data/lib/active_record/associations/builder/collection_association.rb +7 -3
- data/lib/active_record/associations/builder/has_one.rb +1 -1
- data/lib/active_record/associations/builder/singular_association.rb +33 -5
- data/lib/active_record/associations/collection_association.rb +7 -3
- data/lib/active_record/associations/collection_proxy.rb +26 -4
- data/lib/active_record/associations/deprecation.rb +88 -0
- data/lib/active_record/associations/disable_joins_association_scope.rb +1 -1
- data/lib/active_record/associations/errors.rb +3 -0
- data/lib/active_record/associations/foreign_association.rb +3 -1
- data/lib/active_record/associations/has_many_through_association.rb +3 -2
- data/lib/active_record/associations/has_one_association.rb +1 -0
- data/lib/active_record/associations/join_dependency.rb +3 -2
- data/lib/active_record/associations/preloader/association.rb +3 -3
- data/lib/active_record/associations/preloader/batch.rb +7 -1
- data/lib/active_record/associations/preloader/branch.rb +1 -0
- data/lib/active_record/associations/singular_association.rb +8 -3
- data/lib/active_record/associations.rb +192 -24
- data/lib/active_record/asynchronous_queries_tracker.rb +28 -24
- data/lib/active_record/attribute_methods/primary_key.rb +4 -8
- data/lib/active_record/attribute_methods/query.rb +34 -0
- data/lib/active_record/attribute_methods/serialization.rb +18 -5
- data/lib/active_record/attribute_methods/time_zone_conversion.rb +12 -14
- data/lib/active_record/attributes.rb +3 -0
- data/lib/active_record/autosave_association.rb +69 -27
- data/lib/active_record/base.rb +1 -2
- data/lib/active_record/callbacks.rb +1 -2
- data/lib/active_record/coders/column_serializer.rb +1 -1
- data/lib/active_record/coders/json.rb +16 -6
- data/lib/active_record/coders/yaml_column.rb +2 -2
- data/lib/active_record/connection_adapters/abstract/connection_handler.rb +35 -28
- data/lib/active_record/connection_adapters/abstract/connection_pool/queue.rb +16 -4
- data/lib/active_record/connection_adapters/abstract/connection_pool/reaper.rb +68 -13
- data/lib/active_record/connection_adapters/abstract/connection_pool.rb +429 -93
- data/lib/active_record/connection_adapters/abstract/database_statements.rb +148 -74
- data/lib/active_record/connection_adapters/abstract/query_cache.rb +27 -5
- data/lib/active_record/connection_adapters/abstract/quoting.rb +16 -25
- data/lib/active_record/connection_adapters/abstract/schema_creation.rb +11 -7
- data/lib/active_record/connection_adapters/abstract/schema_definitions.rb +32 -35
- data/lib/active_record/connection_adapters/abstract/schema_dumper.rb +2 -1
- data/lib/active_record/connection_adapters/abstract/schema_statements.rb +124 -34
- data/lib/active_record/connection_adapters/abstract/transaction.rb +40 -8
- data/lib/active_record/connection_adapters/abstract_adapter.rb +129 -63
- data/lib/active_record/connection_adapters/abstract_mysql_adapter.rb +132 -65
- data/lib/active_record/connection_adapters/column.rb +14 -4
- data/lib/active_record/connection_adapters/mysql/database_statements.rb +4 -4
- data/lib/active_record/connection_adapters/mysql/quoting.rb +0 -8
- data/lib/active_record/connection_adapters/mysql/schema_creation.rb +2 -0
- data/lib/active_record/connection_adapters/mysql/schema_definitions.rb +41 -10
- data/lib/active_record/connection_adapters/mysql/schema_statements.rb +79 -66
- data/lib/active_record/connection_adapters/mysql2/database_statements.rb +89 -94
- data/lib/active_record/connection_adapters/mysql2_adapter.rb +2 -10
- data/lib/active_record/connection_adapters/pool_config.rb +7 -7
- data/lib/active_record/connection_adapters/postgresql/column.rb +8 -2
- data/lib/active_record/connection_adapters/postgresql/database_statements.rb +79 -61
- data/lib/active_record/connection_adapters/postgresql/oid/array.rb +3 -3
- data/lib/active_record/connection_adapters/postgresql/oid/point.rb +10 -0
- data/lib/active_record/connection_adapters/postgresql/oid/range.rb +46 -3
- data/lib/active_record/connection_adapters/postgresql/oid/type_map_initializer.rb +1 -1
- data/lib/active_record/connection_adapters/postgresql/quoting.rb +21 -10
- data/lib/active_record/connection_adapters/postgresql/referential_integrity.rb +2 -4
- data/lib/active_record/connection_adapters/postgresql/schema_creation.rb +9 -17
- data/lib/active_record/connection_adapters/postgresql/schema_definitions.rb +14 -33
- data/lib/active_record/connection_adapters/postgresql/schema_dumper.rb +71 -32
- data/lib/active_record/connection_adapters/postgresql/schema_statements.rb +156 -68
- data/lib/active_record/connection_adapters/postgresql_adapter.rb +78 -105
- data/lib/active_record/connection_adapters/schema_cache.rb +1 -3
- data/lib/active_record/connection_adapters/sqlite3/column.rb +8 -2
- data/lib/active_record/connection_adapters/sqlite3/database_statements.rb +90 -98
- data/lib/active_record/connection_adapters/sqlite3/quoting.rb +0 -8
- data/lib/active_record/connection_adapters/sqlite3/schema_creation.rb +0 -6
- data/lib/active_record/connection_adapters/sqlite3/schema_dumper.rb +27 -2
- data/lib/active_record/connection_adapters/sqlite3/schema_statements.rb +15 -16
- data/lib/active_record/connection_adapters/sqlite3_adapter.rb +104 -37
- data/lib/active_record/connection_adapters/statement_pool.rb +4 -2
- data/lib/active_record/connection_adapters/trilogy/database_statements.rb +41 -66
- data/lib/active_record/connection_adapters/trilogy_adapter.rb +15 -18
- data/lib/active_record/connection_adapters.rb +1 -56
- data/lib/active_record/connection_handling.rb +25 -2
- data/lib/active_record/core.rb +33 -17
- data/lib/active_record/counter_cache.rb +35 -8
- data/lib/active_record/database_configurations/database_config.rb +9 -1
- data/lib/active_record/database_configurations/hash_config.rb +74 -9
- data/lib/active_record/database_configurations/url_config.rb +15 -3
- data/lib/active_record/database_configurations.rb +7 -3
- data/lib/active_record/delegated_type.rb +1 -1
- data/lib/active_record/disable_joins_association_relation.rb +5 -1
- data/lib/active_record/dynamic_matchers.rb +54 -69
- data/lib/active_record/encryption/config.rb +3 -1
- data/lib/active_record/encryption/encryptable_record.rb +8 -8
- data/lib/active_record/encryption/encrypted_attribute_type.rb +11 -2
- data/lib/active_record/encryption/encrypted_fixtures.rb +12 -7
- data/lib/active_record/encryption/encryptor.rb +28 -8
- data/lib/active_record/encryption/extended_deterministic_queries.rb +4 -2
- data/lib/active_record/encryption/scheme.rb +9 -2
- data/lib/active_record/enum.rb +33 -30
- data/lib/active_record/errors.rb +33 -9
- data/lib/active_record/explain.rb +1 -1
- data/lib/active_record/explain_registry.rb +51 -2
- data/lib/active_record/filter_attribute_handler.rb +76 -0
- data/lib/active_record/fixtures.rb +2 -4
- data/lib/active_record/future_result.rb +15 -9
- data/lib/active_record/gem_version.rb +2 -2
- data/lib/active_record/inheritance.rb +9 -4
- data/lib/active_record/insert_all.rb +14 -9
- data/lib/active_record/locking/optimistic.rb +8 -1
- data/lib/active_record/locking/pessimistic.rb +5 -0
- data/lib/active_record/log_subscriber.rb +31 -29
- data/lib/active_record/message_pack.rb +13 -0
- data/lib/active_record/middleware/shard_selector.rb +34 -17
- data/lib/active_record/migration/command_recorder.rb +56 -13
- data/lib/active_record/migration/compatibility.rb +37 -24
- data/lib/active_record/migration/default_schema_versions_formatter.rb +30 -0
- data/lib/active_record/migration.rb +48 -42
- data/lib/active_record/model_schema.rb +40 -15
- data/lib/active_record/nested_attributes.rb +14 -12
- data/lib/active_record/persistence.rb +163 -133
- data/lib/active_record/query_cache.rb +22 -15
- data/lib/active_record/query_logs.rb +100 -52
- data/lib/active_record/query_logs_formatter.rb +17 -28
- data/lib/active_record/querying.rb +21 -9
- data/lib/active_record/railtie.rb +35 -30
- data/lib/active_record/railties/controller_runtime.rb +11 -6
- data/lib/active_record/railties/databases.rake +26 -38
- data/lib/active_record/railties/job_checkpoints.rb +15 -0
- data/lib/active_record/railties/job_runtime.rb +10 -11
- data/lib/active_record/reflection.rb +54 -22
- data/lib/active_record/relation/batches/batch_enumerator.rb +4 -3
- data/lib/active_record/relation/batches.rb +147 -73
- data/lib/active_record/relation/calculations.rb +60 -43
- data/lib/active_record/relation/delegation.rb +25 -15
- data/lib/active_record/relation/finder_methods.rb +73 -43
- data/lib/active_record/relation/merger.rb +12 -10
- data/lib/active_record/relation/predicate_builder/array_handler.rb +3 -1
- data/lib/active_record/relation/predicate_builder/association_query_value.rb +9 -9
- data/lib/active_record/relation/predicate_builder/polymorphic_array_value.rb +8 -8
- data/lib/active_record/relation/predicate_builder/relation_handler.rb +4 -3
- data/lib/active_record/relation/predicate_builder.rb +23 -8
- data/lib/active_record/relation/query_attribute.rb +3 -1
- data/lib/active_record/relation/query_methods.rb +200 -96
- data/lib/active_record/relation/spawn_methods.rb +7 -7
- data/lib/active_record/relation/where_clause.rb +2 -9
- data/lib/active_record/relation.rb +127 -87
- data/lib/active_record/result.rb +109 -24
- data/lib/active_record/runtime_registry.rb +42 -58
- data/lib/active_record/sanitization.rb +9 -6
- data/lib/active_record/schema.rb +1 -1
- data/lib/active_record/schema_dumper.rb +17 -10
- data/lib/active_record/schema_migration.rb +2 -1
- data/lib/active_record/scoping/named.rb +5 -2
- data/lib/active_record/scoping.rb +0 -1
- data/lib/active_record/signed_id.rb +44 -16
- data/lib/active_record/statement_cache.rb +24 -20
- data/lib/active_record/store.rb +53 -22
- data/lib/active_record/structured_event_subscriber.rb +85 -0
- data/lib/active_record/table_metadata.rb +6 -23
- data/lib/active_record/tasks/abstract_tasks.rb +83 -0
- data/lib/active_record/tasks/database_tasks.rb +85 -85
- data/lib/active_record/tasks/mysql_database_tasks.rb +4 -58
- data/lib/active_record/tasks/postgresql_database_tasks.rb +7 -40
- data/lib/active_record/tasks/sqlite_database_tasks.rb +16 -28
- data/lib/active_record/test_databases.rb +18 -4
- data/lib/active_record/test_fixtures.rb +52 -6
- data/lib/active_record/testing/query_assertions.rb +8 -2
- data/lib/active_record/timestamp.rb +4 -2
- data/lib/active_record/token_for.rb +1 -1
- data/lib/active_record/transaction.rb +2 -5
- data/lib/active_record/transactions.rb +56 -32
- data/lib/active_record/type/hash_lookup_type_map.rb +2 -1
- data/lib/active_record/type/internal/timezone.rb +7 -0
- data/lib/active_record/type/json.rb +13 -2
- data/lib/active_record/type/serialized.rb +16 -4
- data/lib/active_record/type/type_map.rb +1 -1
- data/lib/active_record/type_caster/connection.rb +2 -1
- data/lib/active_record/validations/associated.rb +1 -1
- data/lib/active_record/validations/uniqueness.rb +8 -8
- data/lib/active_record.rb +85 -50
- data/lib/arel/alias_predication.rb +2 -0
- data/lib/arel/collectors/bind.rb +2 -2
- data/lib/arel/collectors/sql_string.rb +1 -1
- data/lib/arel/collectors/substitute_binds.rb +2 -2
- data/lib/arel/crud.rb +6 -11
- data/lib/arel/nodes/binary.rb +1 -1
- data/lib/arel/nodes/count.rb +2 -2
- data/lib/arel/nodes/function.rb +4 -10
- data/lib/arel/nodes/named_function.rb +2 -2
- data/lib/arel/nodes/node.rb +2 -2
- data/lib/arel/nodes/sql_literal.rb +1 -1
- data/lib/arel/nodes.rb +0 -2
- data/lib/arel/predications.rb +1 -3
- data/lib/arel/select_manager.rb +7 -2
- data/lib/arel/table.rb +3 -7
- data/lib/arel/visitors/dot.rb +0 -3
- data/lib/arel/visitors/postgresql.rb +55 -0
- data/lib/arel/visitors/sqlite.rb +55 -8
- data/lib/arel/visitors/to_sql.rb +4 -22
- data/lib/arel.rb +3 -1
- data/lib/rails/generators/active_record/application_record/USAGE +1 -1
- metadata +15 -12
- data/lib/active_record/explain_subscriber.rb +0 -34
- data/lib/active_record/normalization.rb +0 -163
- data/lib/active_record/relation/record_fetch_warning.rb +0 -52
data/lib/arel/visitors/to_sql.rb
CHANGED
|
@@ -77,13 +77,7 @@ module Arel # :nodoc: all
|
|
|
77
77
|
|
|
78
78
|
def visit_Arel_Nodes_Exists(o, collector)
|
|
79
79
|
collector << "EXISTS ("
|
|
80
|
-
|
|
81
|
-
if o.alias
|
|
82
|
-
collector << " AS "
|
|
83
|
-
visit o.alias, collector
|
|
84
|
-
else
|
|
85
|
-
collector
|
|
86
|
-
end
|
|
80
|
+
visit(o.expressions, collector) << ")"
|
|
87
81
|
end
|
|
88
82
|
|
|
89
83
|
def visit_Arel_Nodes_Casted(o, collector)
|
|
@@ -390,13 +384,7 @@ module Arel # :nodoc: all
|
|
|
390
384
|
collector << o.name
|
|
391
385
|
collector << "("
|
|
392
386
|
collector << "DISTINCT " if o.distinct
|
|
393
|
-
|
|
394
|
-
if o.alias
|
|
395
|
-
collector << " AS "
|
|
396
|
-
visit o.alias, collector
|
|
397
|
-
else
|
|
398
|
-
collector
|
|
399
|
-
end
|
|
387
|
+
inject_join(o.expressions, collector, ", ") << ")"
|
|
400
388
|
end
|
|
401
389
|
|
|
402
390
|
def visit_Arel_Nodes_Extract(o, collector)
|
|
@@ -924,7 +912,7 @@ module Arel # :nodoc: all
|
|
|
924
912
|
# on MySQL (even when aliasing the tables), but MySQL allows using JOIN directly in
|
|
925
913
|
# an UPDATE statement, so in the MySQL visitor we redefine this to do that.
|
|
926
914
|
def prepare_update_statement(o)
|
|
927
|
-
if o.key && (has_limit_or_offset_or_orders?(o) || has_join_sources?(o))
|
|
915
|
+
if o.key && (has_limit_or_offset_or_orders?(o) || has_join_sources?(o) || has_group_by_and_having?(o))
|
|
928
916
|
stmt = o.clone
|
|
929
917
|
stmt.limit = nil
|
|
930
918
|
stmt.offset = nil
|
|
@@ -1000,13 +988,7 @@ module Arel # :nodoc: all
|
|
|
1000
988
|
if o.distinct
|
|
1001
989
|
collector << "DISTINCT "
|
|
1002
990
|
end
|
|
1003
|
-
|
|
1004
|
-
if o.alias
|
|
1005
|
-
collector << " AS "
|
|
1006
|
-
visit o.alias, collector
|
|
1007
|
-
else
|
|
1008
|
-
collector
|
|
1009
|
-
end
|
|
991
|
+
inject_join(o.expressions, collector, ", ") << ")"
|
|
1010
992
|
end
|
|
1011
993
|
|
|
1012
994
|
def is_distinct_from(o, collector)
|
data/lib/arel.rb
CHANGED
|
@@ -50,7 +50,9 @@ module Arel
|
|
|
50
50
|
# Use this option only if the SQL is idempotent, as it could be executed
|
|
51
51
|
# more than once.
|
|
52
52
|
def self.sql(sql_string, *positional_binds, retryable: false, **named_binds)
|
|
53
|
-
if
|
|
53
|
+
if Arel::Nodes::SqlLiteral === sql_string
|
|
54
|
+
sql_string
|
|
55
|
+
elsif positional_binds.empty? && named_binds.empty?
|
|
54
56
|
Arel::Nodes::SqlLiteral.new(sql_string, retryable: retryable)
|
|
55
57
|
else
|
|
56
58
|
Arel::Nodes::BoundSqlLiteral.new sql_string, positional_binds, named_binds
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: activerecord
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version:
|
|
4
|
+
version: 8.1.4
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- David Heinemeier Hansson
|
|
@@ -15,28 +15,28 @@ dependencies:
|
|
|
15
15
|
requirements:
|
|
16
16
|
- - '='
|
|
17
17
|
- !ruby/object:Gem::Version
|
|
18
|
-
version:
|
|
18
|
+
version: 8.1.4
|
|
19
19
|
type: :runtime
|
|
20
20
|
prerelease: false
|
|
21
21
|
version_requirements: !ruby/object:Gem::Requirement
|
|
22
22
|
requirements:
|
|
23
23
|
- - '='
|
|
24
24
|
- !ruby/object:Gem::Version
|
|
25
|
-
version:
|
|
25
|
+
version: 8.1.4
|
|
26
26
|
- !ruby/object:Gem::Dependency
|
|
27
27
|
name: activemodel
|
|
28
28
|
requirement: !ruby/object:Gem::Requirement
|
|
29
29
|
requirements:
|
|
30
30
|
- - '='
|
|
31
31
|
- !ruby/object:Gem::Version
|
|
32
|
-
version:
|
|
32
|
+
version: 8.1.4
|
|
33
33
|
type: :runtime
|
|
34
34
|
prerelease: false
|
|
35
35
|
version_requirements: !ruby/object:Gem::Requirement
|
|
36
36
|
requirements:
|
|
37
37
|
- - '='
|
|
38
38
|
- !ruby/object:Gem::Version
|
|
39
|
-
version:
|
|
39
|
+
version: 8.1.4
|
|
40
40
|
- !ruby/object:Gem::Dependency
|
|
41
41
|
name: timeout
|
|
42
42
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -83,6 +83,7 @@ files:
|
|
|
83
83
|
- lib/active_record/associations/builder/singular_association.rb
|
|
84
84
|
- lib/active_record/associations/collection_association.rb
|
|
85
85
|
- lib/active_record/associations/collection_proxy.rb
|
|
86
|
+
- lib/active_record/associations/deprecation.rb
|
|
86
87
|
- lib/active_record/associations/disable_joins_association_scope.rb
|
|
87
88
|
- lib/active_record/associations/errors.rb
|
|
88
89
|
- lib/active_record/associations/foreign_association.rb
|
|
@@ -252,7 +253,7 @@ files:
|
|
|
252
253
|
- lib/active_record/errors.rb
|
|
253
254
|
- lib/active_record/explain.rb
|
|
254
255
|
- lib/active_record/explain_registry.rb
|
|
255
|
-
- lib/active_record/
|
|
256
|
+
- lib/active_record/filter_attribute_handler.rb
|
|
256
257
|
- lib/active_record/fixture_set/file.rb
|
|
257
258
|
- lib/active_record/fixture_set/model_metadata.rb
|
|
258
259
|
- lib/active_record/fixture_set/render_context.rb
|
|
@@ -279,6 +280,7 @@ files:
|
|
|
279
280
|
- lib/active_record/migration.rb
|
|
280
281
|
- lib/active_record/migration/command_recorder.rb
|
|
281
282
|
- lib/active_record/migration/compatibility.rb
|
|
283
|
+
- lib/active_record/migration/default_schema_versions_formatter.rb
|
|
282
284
|
- lib/active_record/migration/default_strategy.rb
|
|
283
285
|
- lib/active_record/migration/execution_strategy.rb
|
|
284
286
|
- lib/active_record/migration/join_table.rb
|
|
@@ -286,7 +288,6 @@ files:
|
|
|
286
288
|
- lib/active_record/model_schema.rb
|
|
287
289
|
- lib/active_record/nested_attributes.rb
|
|
288
290
|
- lib/active_record/no_touching.rb
|
|
289
|
-
- lib/active_record/normalization.rb
|
|
290
291
|
- lib/active_record/persistence.rb
|
|
291
292
|
- lib/active_record/promise.rb
|
|
292
293
|
- lib/active_record/query_cache.rb
|
|
@@ -297,6 +298,7 @@ files:
|
|
|
297
298
|
- lib/active_record/railties/console_sandbox.rb
|
|
298
299
|
- lib/active_record/railties/controller_runtime.rb
|
|
299
300
|
- lib/active_record/railties/databases.rake
|
|
301
|
+
- lib/active_record/railties/job_checkpoints.rb
|
|
300
302
|
- lib/active_record/railties/job_runtime.rb
|
|
301
303
|
- lib/active_record/readonly_attributes.rb
|
|
302
304
|
- lib/active_record/reflection.rb
|
|
@@ -317,7 +319,6 @@ files:
|
|
|
317
319
|
- lib/active_record/relation/predicate_builder/relation_handler.rb
|
|
318
320
|
- lib/active_record/relation/query_attribute.rb
|
|
319
321
|
- lib/active_record/relation/query_methods.rb
|
|
320
|
-
- lib/active_record/relation/record_fetch_warning.rb
|
|
321
322
|
- lib/active_record/relation/spawn_methods.rb
|
|
322
323
|
- lib/active_record/relation/where_clause.rb
|
|
323
324
|
- lib/active_record/result.rb
|
|
@@ -335,8 +336,10 @@ files:
|
|
|
335
336
|
- lib/active_record/signed_id.rb
|
|
336
337
|
- lib/active_record/statement_cache.rb
|
|
337
338
|
- lib/active_record/store.rb
|
|
339
|
+
- lib/active_record/structured_event_subscriber.rb
|
|
338
340
|
- lib/active_record/suppressor.rb
|
|
339
341
|
- lib/active_record/table_metadata.rb
|
|
342
|
+
- lib/active_record/tasks/abstract_tasks.rb
|
|
340
343
|
- lib/active_record/tasks/database_tasks.rb
|
|
341
344
|
- lib/active_record/tasks/mysql_database_tasks.rb
|
|
342
345
|
- lib/active_record/tasks/postgresql_database_tasks.rb
|
|
@@ -475,10 +478,10 @@ licenses:
|
|
|
475
478
|
- MIT
|
|
476
479
|
metadata:
|
|
477
480
|
bug_tracker_uri: https://github.com/rails/rails/issues
|
|
478
|
-
changelog_uri: https://github.com/rails/rails/blob/
|
|
479
|
-
documentation_uri: https://api.rubyonrails.org/
|
|
481
|
+
changelog_uri: https://github.com/rails/rails/blob/v8.1.4/activerecord/CHANGELOG.md
|
|
482
|
+
documentation_uri: https://api.rubyonrails.org/v8.1.4/
|
|
480
483
|
mailing_list_uri: https://discuss.rubyonrails.org/c/rubyonrails-talk
|
|
481
|
-
source_code_uri: https://github.com/rails/rails/tree/
|
|
484
|
+
source_code_uri: https://github.com/rails/rails/tree/v8.1.4/activerecord
|
|
482
485
|
rubygems_mfa_required: 'true'
|
|
483
486
|
rdoc_options:
|
|
484
487
|
- "--main"
|
|
@@ -489,7 +492,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
|
489
492
|
requirements:
|
|
490
493
|
- - ">="
|
|
491
494
|
- !ruby/object:Gem::Version
|
|
492
|
-
version: 3.
|
|
495
|
+
version: 3.2.0
|
|
493
496
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
494
497
|
requirements:
|
|
495
498
|
- - ">="
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
require "active_support/notifications"
|
|
4
|
-
require "active_record/explain_registry"
|
|
5
|
-
|
|
6
|
-
module ActiveRecord
|
|
7
|
-
class ExplainSubscriber # :nodoc:
|
|
8
|
-
def start(name, id, payload)
|
|
9
|
-
# unused
|
|
10
|
-
end
|
|
11
|
-
|
|
12
|
-
def finish(name, id, payload)
|
|
13
|
-
if ExplainRegistry.collect? && !ignore_payload?(payload)
|
|
14
|
-
ExplainRegistry.queries << payload.values_at(:sql, :binds)
|
|
15
|
-
end
|
|
16
|
-
end
|
|
17
|
-
|
|
18
|
-
# SCHEMA queries cannot be EXPLAINed, also we do not want to run EXPLAIN on
|
|
19
|
-
# our own EXPLAINs no matter how loopingly beautiful that would be.
|
|
20
|
-
#
|
|
21
|
-
# On the other hand, we want to monitor the performance of our real database
|
|
22
|
-
# queries, not the performance of the access to the query cache.
|
|
23
|
-
IGNORED_PAYLOADS = %w(SCHEMA EXPLAIN)
|
|
24
|
-
EXPLAINED_SQLS = /\A\s*(\/\*.*\*\/)?\s*(with|select|update|delete|insert)\b/i
|
|
25
|
-
def ignore_payload?(payload)
|
|
26
|
-
payload[:exception] ||
|
|
27
|
-
payload[:cached] ||
|
|
28
|
-
IGNORED_PAYLOADS.include?(payload[:name]) ||
|
|
29
|
-
!payload[:sql].match?(EXPLAINED_SQLS)
|
|
30
|
-
end
|
|
31
|
-
|
|
32
|
-
ActiveSupport::Notifications.subscribe("sql.active_record", new)
|
|
33
|
-
end
|
|
34
|
-
end
|
|
@@ -1,163 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
module ActiveRecord # :nodoc:
|
|
4
|
-
module Normalization
|
|
5
|
-
extend ActiveSupport::Concern
|
|
6
|
-
|
|
7
|
-
included do
|
|
8
|
-
class_attribute :normalized_attributes, default: Set.new
|
|
9
|
-
|
|
10
|
-
before_validation :normalize_changed_in_place_attributes
|
|
11
|
-
end
|
|
12
|
-
|
|
13
|
-
# Normalizes a specified attribute using its declared normalizations.
|
|
14
|
-
#
|
|
15
|
-
# ==== Examples
|
|
16
|
-
#
|
|
17
|
-
# class User < ActiveRecord::Base
|
|
18
|
-
# normalizes :email, with: -> email { email.strip.downcase }
|
|
19
|
-
# end
|
|
20
|
-
#
|
|
21
|
-
# legacy_user = User.find(1)
|
|
22
|
-
# legacy_user.email # => " CRUISE-CONTROL@EXAMPLE.COM\n"
|
|
23
|
-
# legacy_user.normalize_attribute(:email)
|
|
24
|
-
# legacy_user.email # => "cruise-control@example.com"
|
|
25
|
-
# legacy_user.save
|
|
26
|
-
def normalize_attribute(name)
|
|
27
|
-
# Treat the value as a new, unnormalized value.
|
|
28
|
-
self[name] = self[name]
|
|
29
|
-
end
|
|
30
|
-
|
|
31
|
-
module ClassMethods
|
|
32
|
-
# Declares a normalization for one or more attributes. The normalization
|
|
33
|
-
# is applied when the attribute is assigned or updated, and the normalized
|
|
34
|
-
# value will be persisted to the database. The normalization is also
|
|
35
|
-
# applied to the corresponding keyword argument of query methods. This
|
|
36
|
-
# allows a record to be created and later queried using unnormalized
|
|
37
|
-
# values.
|
|
38
|
-
#
|
|
39
|
-
# However, to prevent confusion, the normalization will not be applied
|
|
40
|
-
# when the attribute is fetched from the database. This means that if a
|
|
41
|
-
# record was persisted before the normalization was declared, the record's
|
|
42
|
-
# attribute will not be normalized until either it is assigned a new
|
|
43
|
-
# value, or it is explicitly migrated via Normalization#normalize_attribute.
|
|
44
|
-
#
|
|
45
|
-
# Because the normalization may be applied multiple times, it should be
|
|
46
|
-
# _idempotent_. In other words, applying the normalization more than once
|
|
47
|
-
# should have the same result as applying it only once.
|
|
48
|
-
#
|
|
49
|
-
# By default, the normalization will not be applied to +nil+ values. This
|
|
50
|
-
# behavior can be changed with the +:apply_to_nil+ option.
|
|
51
|
-
#
|
|
52
|
-
# Be aware that if your app was created before Rails 7.1, and your app
|
|
53
|
-
# marshals instances of the targeted model (for example, when caching),
|
|
54
|
-
# then you should set ActiveRecord.marshalling_format_version to +7.1+ or
|
|
55
|
-
# higher via either <tt>config.load_defaults 7.1</tt> or
|
|
56
|
-
# <tt>config.active_record.marshalling_format_version = 7.1</tt>.
|
|
57
|
-
# Otherwise, +Marshal+ may attempt to serialize the normalization +Proc+
|
|
58
|
-
# and raise +TypeError+.
|
|
59
|
-
#
|
|
60
|
-
# ==== Options
|
|
61
|
-
#
|
|
62
|
-
# * +:with+ - Any callable object that accepts the attribute's value as
|
|
63
|
-
# its sole argument, and returns it normalized.
|
|
64
|
-
# * +:apply_to_nil+ - Whether to apply the normalization to +nil+ values.
|
|
65
|
-
# Defaults to +false+.
|
|
66
|
-
#
|
|
67
|
-
# ==== Examples
|
|
68
|
-
#
|
|
69
|
-
# class User < ActiveRecord::Base
|
|
70
|
-
# normalizes :email, with: -> email { email.strip.downcase }
|
|
71
|
-
# normalizes :phone, with: -> phone { phone.delete("^0-9").delete_prefix("1") }
|
|
72
|
-
# end
|
|
73
|
-
#
|
|
74
|
-
# user = User.create(email: " CRUISE-CONTROL@EXAMPLE.COM\n")
|
|
75
|
-
# user.email # => "cruise-control@example.com"
|
|
76
|
-
#
|
|
77
|
-
# user = User.find_by(email: "\tCRUISE-CONTROL@EXAMPLE.COM ")
|
|
78
|
-
# user.email # => "cruise-control@example.com"
|
|
79
|
-
# user.email_before_type_cast # => "cruise-control@example.com"
|
|
80
|
-
#
|
|
81
|
-
# User.where(email: "\tCRUISE-CONTROL@EXAMPLE.COM ").count # => 1
|
|
82
|
-
# User.where(["email = ?", "\tCRUISE-CONTROL@EXAMPLE.COM "]).count # => 0
|
|
83
|
-
#
|
|
84
|
-
# User.exists?(email: "\tCRUISE-CONTROL@EXAMPLE.COM ") # => true
|
|
85
|
-
# User.exists?(["email = ?", "\tCRUISE-CONTROL@EXAMPLE.COM "]) # => false
|
|
86
|
-
#
|
|
87
|
-
# User.normalize_value_for(:phone, "+1 (555) 867-5309") # => "5558675309"
|
|
88
|
-
def normalizes(*names, with:, apply_to_nil: false)
|
|
89
|
-
decorate_attributes(names) do |name, cast_type|
|
|
90
|
-
NormalizedValueType.new(cast_type: cast_type, normalizer: with, normalize_nil: apply_to_nil)
|
|
91
|
-
end
|
|
92
|
-
|
|
93
|
-
self.normalized_attributes += names.map(&:to_sym)
|
|
94
|
-
end
|
|
95
|
-
|
|
96
|
-
# Normalizes a given +value+ using normalizations declared for +name+.
|
|
97
|
-
#
|
|
98
|
-
# ==== Examples
|
|
99
|
-
#
|
|
100
|
-
# class User < ActiveRecord::Base
|
|
101
|
-
# normalizes :email, with: -> email { email.strip.downcase }
|
|
102
|
-
# end
|
|
103
|
-
#
|
|
104
|
-
# User.normalize_value_for(:email, " CRUISE-CONTROL@EXAMPLE.COM\n")
|
|
105
|
-
# # => "cruise-control@example.com"
|
|
106
|
-
def normalize_value_for(name, value)
|
|
107
|
-
type_for_attribute(name).cast(value)
|
|
108
|
-
end
|
|
109
|
-
end
|
|
110
|
-
|
|
111
|
-
private
|
|
112
|
-
def normalize_changed_in_place_attributes
|
|
113
|
-
self.class.normalized_attributes.each do |name|
|
|
114
|
-
normalize_attribute(name) if attribute_changed_in_place?(name)
|
|
115
|
-
end
|
|
116
|
-
end
|
|
117
|
-
|
|
118
|
-
class NormalizedValueType < DelegateClass(ActiveModel::Type::Value) # :nodoc:
|
|
119
|
-
include ActiveModel::Type::SerializeCastValue
|
|
120
|
-
|
|
121
|
-
attr_reader :cast_type, :normalizer, :normalize_nil
|
|
122
|
-
alias :normalize_nil? :normalize_nil
|
|
123
|
-
|
|
124
|
-
def initialize(cast_type:, normalizer:, normalize_nil:)
|
|
125
|
-
@cast_type = cast_type
|
|
126
|
-
@normalizer = normalizer
|
|
127
|
-
@normalize_nil = normalize_nil
|
|
128
|
-
super(cast_type)
|
|
129
|
-
end
|
|
130
|
-
|
|
131
|
-
def cast(value)
|
|
132
|
-
normalize(super(value))
|
|
133
|
-
end
|
|
134
|
-
|
|
135
|
-
def serialize(value)
|
|
136
|
-
serialize_cast_value(cast(value))
|
|
137
|
-
end
|
|
138
|
-
|
|
139
|
-
def serialize_cast_value(value)
|
|
140
|
-
ActiveModel::Type::SerializeCastValue.serialize(cast_type, value)
|
|
141
|
-
end
|
|
142
|
-
|
|
143
|
-
def ==(other)
|
|
144
|
-
self.class == other.class &&
|
|
145
|
-
normalize_nil? == other.normalize_nil? &&
|
|
146
|
-
normalizer == other.normalizer &&
|
|
147
|
-
cast_type == other.cast_type
|
|
148
|
-
end
|
|
149
|
-
alias eql? ==
|
|
150
|
-
|
|
151
|
-
def hash
|
|
152
|
-
[self.class, cast_type, normalizer, normalize_nil?].hash
|
|
153
|
-
end
|
|
154
|
-
|
|
155
|
-
define_method(:inspect, Kernel.instance_method(:inspect))
|
|
156
|
-
|
|
157
|
-
private
|
|
158
|
-
def normalize(value)
|
|
159
|
-
normalizer.call(value) unless value.nil? && !normalize_nil?
|
|
160
|
-
end
|
|
161
|
-
end
|
|
162
|
-
end
|
|
163
|
-
end
|
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
module ActiveRecord
|
|
4
|
-
class Relation
|
|
5
|
-
module RecordFetchWarning
|
|
6
|
-
# Deprecated: subscribe to sql.active_record notifications and
|
|
7
|
-
# access the row count field to detect large result set sizes.
|
|
8
|
-
#
|
|
9
|
-
# When this module is prepended to ActiveRecord::Relation and
|
|
10
|
-
# +config.active_record.warn_on_records_fetched_greater_than+ is
|
|
11
|
-
# set to an integer, if the number of records a query returns is
|
|
12
|
-
# greater than the value of +warn_on_records_fetched_greater_than+,
|
|
13
|
-
# a warning is logged. This allows for the detection of queries that
|
|
14
|
-
# return a large number of records, which could cause memory bloat.
|
|
15
|
-
#
|
|
16
|
-
# In most cases, fetching large number of records can be performed
|
|
17
|
-
# efficiently using the ActiveRecord::Batches methods.
|
|
18
|
-
# See ActiveRecord::Batches for more information.
|
|
19
|
-
def exec_queries
|
|
20
|
-
QueryRegistry.reset
|
|
21
|
-
|
|
22
|
-
super.tap do |records|
|
|
23
|
-
if logger && ActiveRecord.warn_on_records_fetched_greater_than
|
|
24
|
-
if records.length > ActiveRecord.warn_on_records_fetched_greater_than
|
|
25
|
-
logger.warn "Query fetched #{records.size} #{@klass} records: #{QueryRegistry.queries.join(";")}"
|
|
26
|
-
end
|
|
27
|
-
end
|
|
28
|
-
end
|
|
29
|
-
end
|
|
30
|
-
|
|
31
|
-
# :stopdoc:
|
|
32
|
-
ActiveSupport::Notifications.subscribe("sql.active_record") do |*, payload|
|
|
33
|
-
QueryRegistry.queries << payload[:sql]
|
|
34
|
-
end
|
|
35
|
-
# :startdoc:
|
|
36
|
-
|
|
37
|
-
module QueryRegistry # :nodoc:
|
|
38
|
-
extend self
|
|
39
|
-
|
|
40
|
-
def queries
|
|
41
|
-
ActiveSupport::IsolatedExecutionState[:active_record_query_registry] ||= []
|
|
42
|
-
end
|
|
43
|
-
|
|
44
|
-
def reset
|
|
45
|
-
queries.clear
|
|
46
|
-
end
|
|
47
|
-
end
|
|
48
|
-
end
|
|
49
|
-
end
|
|
50
|
-
end
|
|
51
|
-
|
|
52
|
-
ActiveRecord::Relation.prepend ActiveRecord::Relation::RecordFetchWarning
|