activerecord 7.2.1.1 → 8.0.0.rc1
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 +220 -756
- data/README.rdoc +1 -1
- data/lib/active_record/associations/association.rb +25 -5
- data/lib/active_record/associations/builder/association.rb +7 -6
- data/lib/active_record/associations/collection_association.rb +10 -8
- data/lib/active_record/associations/disable_joins_association_scope.rb +1 -1
- data/lib/active_record/associations/has_many_through_association.rb +10 -3
- data/lib/active_record/associations/join_dependency/join_association.rb +3 -2
- data/lib/active_record/associations/join_dependency.rb +4 -4
- data/lib/active_record/associations/preloader/association.rb +2 -2
- data/lib/active_record/associations/singular_association.rb +8 -3
- data/lib/active_record/associations.rb +34 -4
- data/lib/active_record/asynchronous_queries_tracker.rb +28 -24
- data/lib/active_record/attribute_assignment.rb +9 -1
- data/lib/active_record/attribute_methods/primary_key.rb +2 -7
- data/lib/active_record/attribute_methods/time_zone_conversion.rb +6 -12
- data/lib/active_record/attributes.rb +1 -2
- data/lib/active_record/autosave_association.rb +69 -27
- data/lib/active_record/callbacks.rb +1 -1
- data/lib/active_record/connection_adapters/abstract/connection_handler.rb +16 -10
- data/lib/active_record/connection_adapters/abstract/connection_pool/queue.rb +0 -1
- data/lib/active_record/connection_adapters/abstract/connection_pool/reaper.rb +0 -1
- data/lib/active_record/connection_adapters/abstract/connection_pool.rb +26 -9
- data/lib/active_record/connection_adapters/abstract/database_statements.rb +90 -43
- data/lib/active_record/connection_adapters/abstract/query_cache.rb +12 -4
- data/lib/active_record/connection_adapters/abstract/quoting.rb +1 -1
- data/lib/active_record/connection_adapters/abstract/schema_creation.rb +4 -5
- data/lib/active_record/connection_adapters/abstract/schema_definitions.rb +7 -2
- data/lib/active_record/connection_adapters/abstract/schema_statements.rb +34 -7
- data/lib/active_record/connection_adapters/abstract/transaction.rb +15 -5
- data/lib/active_record/connection_adapters/abstract_adapter.rb +24 -26
- data/lib/active_record/connection_adapters/abstract_mysql_adapter.rb +28 -42
- data/lib/active_record/connection_adapters/mysql/quoting.rb +0 -8
- data/lib/active_record/connection_adapters/mysql/schema_definitions.rb +2 -8
- data/lib/active_record/connection_adapters/mysql/schema_statements.rb +43 -45
- data/lib/active_record/connection_adapters/mysql2/database_statements.rb +42 -98
- data/lib/active_record/connection_adapters/mysql2_adapter.rb +1 -8
- data/lib/active_record/connection_adapters/postgresql/database_statements.rb +64 -42
- data/lib/active_record/connection_adapters/postgresql/oid/array.rb +1 -1
- data/lib/active_record/connection_adapters/postgresql/oid/cidr.rb +1 -1
- data/lib/active_record/connection_adapters/postgresql/oid/point.rb +10 -0
- data/lib/active_record/connection_adapters/postgresql/referential_integrity.rb +2 -4
- data/lib/active_record/connection_adapters/postgresql/schema_creation.rb +0 -11
- data/lib/active_record/connection_adapters/postgresql/schema_definitions.rb +1 -11
- data/lib/active_record/connection_adapters/postgresql/schema_dumper.rb +1 -1
- data/lib/active_record/connection_adapters/postgresql/schema_statements.rb +54 -14
- data/lib/active_record/connection_adapters/postgresql_adapter.rb +45 -97
- data/lib/active_record/connection_adapters/schema_cache.rb +1 -3
- data/lib/active_record/connection_adapters/sqlite3/database_statements.rb +76 -100
- data/lib/active_record/connection_adapters/sqlite3/schema_creation.rb +0 -6
- data/lib/active_record/connection_adapters/sqlite3/schema_dumper.rb +13 -0
- data/lib/active_record/connection_adapters/sqlite3/schema_statements.rb +8 -1
- data/lib/active_record/connection_adapters/sqlite3_adapter.rb +53 -12
- data/lib/active_record/connection_adapters/trilogy/database_statements.rb +37 -67
- data/lib/active_record/connection_adapters/trilogy_adapter.rb +0 -17
- data/lib/active_record/connection_adapters.rb +0 -56
- data/lib/active_record/connection_handling.rb +22 -0
- data/lib/active_record/core.rb +28 -18
- data/lib/active_record/database_configurations/connection_url_resolver.rb +1 -1
- data/lib/active_record/encryption/config.rb +3 -1
- data/lib/active_record/encryption/encryptable_record.rb +4 -4
- data/lib/active_record/encryption/encrypted_attribute_type.rb +10 -1
- data/lib/active_record/encryption/encryptor.rb +15 -8
- data/lib/active_record/encryption/extended_deterministic_queries.rb +4 -2
- data/lib/active_record/encryption/key_provider.rb +1 -1
- data/lib/active_record/encryption/scheme.rb +8 -1
- data/lib/active_record/encryption.rb +2 -0
- data/lib/active_record/enum.rb +54 -75
- data/lib/active_record/errors.rb +13 -5
- data/lib/active_record/fixtures.rb +0 -2
- data/lib/active_record/future_result.rb +14 -10
- data/lib/active_record/gem_version.rb +4 -4
- data/lib/active_record/insert_all.rb +1 -1
- data/lib/active_record/locking/optimistic.rb +1 -1
- data/lib/active_record/log_subscriber.rb +5 -11
- data/lib/active_record/marshalling.rb +4 -1
- data/lib/active_record/migration/command_recorder.rb +22 -5
- data/lib/active_record/migration/compatibility.rb +5 -2
- data/lib/active_record/migration.rb +35 -38
- data/lib/active_record/model_schema.rb +4 -6
- data/lib/active_record/nested_attributes.rb +11 -2
- data/lib/active_record/persistence.rb +128 -130
- data/lib/active_record/query_cache.rb +0 -4
- data/lib/active_record/query_logs.rb +102 -50
- data/lib/active_record/query_logs_formatter.rb +17 -28
- data/lib/active_record/querying.rb +8 -8
- data/lib/active_record/railtie.rb +9 -38
- data/lib/active_record/railties/databases.rake +1 -1
- data/lib/active_record/reflection.rb +23 -23
- data/lib/active_record/relation/batches/batch_enumerator.rb +4 -3
- data/lib/active_record/relation/batches.rb +132 -72
- data/lib/active_record/relation/calculations.rb +41 -40
- data/lib/active_record/relation/delegation.rb +25 -14
- data/lib/active_record/relation/finder_methods.rb +18 -18
- data/lib/active_record/relation/merger.rb +8 -8
- data/lib/active_record/relation/predicate_builder/polymorphic_array_value.rb +1 -1
- data/lib/active_record/relation/predicate_builder/relation_handler.rb +4 -3
- data/lib/active_record/relation/predicate_builder.rb +14 -1
- data/lib/active_record/relation/query_methods.rb +122 -71
- data/lib/active_record/relation/spawn_methods.rb +1 -1
- data/lib/active_record/relation.rb +79 -61
- data/lib/active_record/result.rb +66 -4
- data/lib/active_record/sanitization.rb +7 -6
- data/lib/active_record/schema_dumper.rb +5 -0
- data/lib/active_record/schema_migration.rb +2 -1
- data/lib/active_record/scoping/named.rb +5 -2
- data/lib/active_record/statement_cache.rb +12 -12
- data/lib/active_record/store.rb +7 -3
- data/lib/active_record/table_metadata.rb +1 -3
- data/lib/active_record/tasks/database_tasks.rb +40 -47
- data/lib/active_record/tasks/mysql_database_tasks.rb +0 -2
- data/lib/active_record/tasks/sqlite_database_tasks.rb +2 -2
- data/lib/active_record/test_fixtures.rb +12 -0
- data/lib/active_record/testing/query_assertions.rb +2 -2
- data/lib/active_record/token_for.rb +1 -1
- data/lib/active_record/validations/uniqueness.rb +9 -8
- data/lib/active_record.rb +15 -45
- data/lib/arel/collectors/bind.rb +1 -1
- data/lib/arel/table.rb +3 -7
- data/lib/arel/visitors/sqlite.rb +25 -0
- metadata +10 -11
- data/lib/active_record/relation/record_fetch_warning.rb +0 -52
@@ -175,37 +175,35 @@ module ActiveRecord
|
|
175
175
|
|
176
176
|
def prepare_all
|
177
177
|
seed = false
|
178
|
+
dump_db_configs = []
|
178
179
|
|
179
180
|
each_current_configuration(env) do |db_config|
|
180
|
-
|
181
|
-
begin
|
182
|
-
database_initialized = migration_connection_pool.schema_migration.table_exists?
|
183
|
-
rescue ActiveRecord::NoDatabaseError
|
184
|
-
create(db_config)
|
185
|
-
retry
|
186
|
-
end
|
181
|
+
database_initialized = initialize_database(db_config)
|
187
182
|
|
188
|
-
|
189
|
-
if File.exist?(schema_dump_path(db_config))
|
190
|
-
load_schema(db_config, ActiveRecord.schema_format, nil)
|
191
|
-
end
|
192
|
-
|
193
|
-
seed = true
|
194
|
-
end
|
195
|
-
end
|
183
|
+
seed = true if database_initialized
|
196
184
|
end
|
197
185
|
|
198
186
|
each_current_environment(env) do |environment|
|
199
187
|
db_configs_with_versions(environment).sort.each do |version, db_configs|
|
188
|
+
dump_db_configs |= db_configs
|
189
|
+
|
200
190
|
db_configs.each do |db_config|
|
201
191
|
with_temporary_pool(db_config) do
|
202
192
|
migrate(version)
|
203
|
-
dump_schema(db_config) if ActiveRecord.dump_schema_after_migration
|
204
193
|
end
|
205
194
|
end
|
206
195
|
end
|
207
196
|
end
|
208
197
|
|
198
|
+
# Dump schema for databases that were migrated.
|
199
|
+
if ActiveRecord.dump_schema_after_migration
|
200
|
+
dump_db_configs.each do |db_config|
|
201
|
+
with_temporary_pool(db_config) do
|
202
|
+
dump_schema(db_config)
|
203
|
+
end
|
204
|
+
end
|
205
|
+
end
|
206
|
+
|
209
207
|
load_seed if seed
|
210
208
|
end
|
211
209
|
|
@@ -248,6 +246,8 @@ module ActiveRecord
|
|
248
246
|
|
249
247
|
check_target_version
|
250
248
|
|
249
|
+
initialize_database(migration_connection_pool.db_config)
|
250
|
+
|
251
251
|
migration_connection_pool.migration_context.migrate(target_version) do |migration|
|
252
252
|
if version.blank?
|
253
253
|
scope.blank? || scope == migration.scope
|
@@ -446,26 +446,10 @@ module ActiveRecord
|
|
446
446
|
end
|
447
447
|
end
|
448
448
|
|
449
|
-
def cache_dump_filename(
|
450
|
-
|
451
|
-
schema_cache_path ||
|
452
|
-
|
453
|
-
schema_cache_env ||
|
454
|
-
db_config_or_name.default_schema_cache_path(ActiveRecord::Tasks::DatabaseTasks.db_dir)
|
455
|
-
else
|
456
|
-
ActiveRecord.deprecator.warn(<<~MSG.squish)
|
457
|
-
Passing a database name to `cache_dump_filename` is deprecated and will be removed in Rails 8.0. Pass a
|
458
|
-
`ActiveRecord::DatabaseConfigurations::DatabaseConfig` object instead.
|
459
|
-
MSG
|
460
|
-
|
461
|
-
filename = if ActiveRecord::Base.configurations.primary?(db_config_or_name)
|
462
|
-
"schema_cache.yml"
|
463
|
-
else
|
464
|
-
"#{db_config_or_name}_schema_cache.yml"
|
465
|
-
end
|
466
|
-
|
467
|
-
schema_cache_path || schema_cache_env || File.join(ActiveRecord::Tasks::DatabaseTasks.db_dir, filename)
|
468
|
-
end
|
449
|
+
def cache_dump_filename(db_config, schema_cache_path: nil)
|
450
|
+
schema_cache_path ||
|
451
|
+
db_config.schema_cache_path ||
|
452
|
+
db_config.default_schema_cache_path(ActiveRecord::Tasks::DatabaseTasks.db_dir)
|
469
453
|
end
|
470
454
|
|
471
455
|
def load_schema_current(format = ActiveRecord.schema_format, file = nil, environment = env)
|
@@ -536,17 +520,6 @@ module ActiveRecord
|
|
536
520
|
end
|
537
521
|
|
538
522
|
private
|
539
|
-
def schema_cache_env
|
540
|
-
if ENV["SCHEMA_CACHE"]
|
541
|
-
ActiveRecord.deprecator.warn(<<~MSG.squish)
|
542
|
-
Setting `ENV["SCHEMA_CACHE"]` is deprecated and will be removed in Rails 8.0.
|
543
|
-
Configure the `:schema_cache_path` in the database configuration instead.
|
544
|
-
MSG
|
545
|
-
|
546
|
-
nil
|
547
|
-
end
|
548
|
-
end
|
549
|
-
|
550
523
|
def with_temporary_pool(db_config, clobber: false)
|
551
524
|
original_db_config = migration_class.connection_db_config
|
552
525
|
pool = migration_class.connection_handler.establish_connection(db_config, clobber: clobber)
|
@@ -656,6 +629,26 @@ module ActiveRecord
|
|
656
629
|
rescue ActiveRecord::NoDatabaseError
|
657
630
|
end
|
658
631
|
end
|
632
|
+
|
633
|
+
def initialize_database(db_config)
|
634
|
+
with_temporary_pool(db_config) do
|
635
|
+
begin
|
636
|
+
database_already_initialized = migration_connection_pool.schema_migration.table_exists?
|
637
|
+
rescue ActiveRecord::NoDatabaseError
|
638
|
+
create(db_config)
|
639
|
+
retry
|
640
|
+
end
|
641
|
+
|
642
|
+
unless database_already_initialized
|
643
|
+
schema_dump_path = schema_dump_path(db_config)
|
644
|
+
if schema_dump_path && File.exist?(schema_dump_path)
|
645
|
+
load_schema(db_config, ActiveRecord.schema_format, nil)
|
646
|
+
end
|
647
|
+
end
|
648
|
+
|
649
|
+
!database_already_initialized
|
650
|
+
end
|
651
|
+
end
|
659
652
|
end
|
660
653
|
end
|
661
654
|
end
|
@@ -50,9 +50,9 @@ module ActiveRecord
|
|
50
50
|
if ignore_tables.any?
|
51
51
|
ignore_tables = connection.data_sources.select { |table| ignore_tables.any? { |pattern| pattern === table } }
|
52
52
|
condition = ignore_tables.map { |table| connection.quote(table) }.join(", ")
|
53
|
-
args << "SELECT sql FROM sqlite_master WHERE tbl_name NOT IN (#{condition}) ORDER BY tbl_name, type DESC, name"
|
53
|
+
args << "SELECT sql || ';' FROM sqlite_master WHERE tbl_name NOT IN (#{condition}) ORDER BY tbl_name, type DESC, name"
|
54
54
|
else
|
55
|
-
args << ".schema"
|
55
|
+
args << ".schema --nosys"
|
56
56
|
end
|
57
57
|
run_cmd("sqlite3", args, filename)
|
58
58
|
end
|
@@ -137,12 +137,15 @@ module ActiveRecord
|
|
137
137
|
invalidate_already_loaded_fixtures
|
138
138
|
@loaded_fixtures = load_fixtures(config)
|
139
139
|
end
|
140
|
+
setup_asynchronous_queries_session
|
140
141
|
|
141
142
|
# Instantiate fixtures for every test if requested.
|
142
143
|
instantiate_fixtures if use_instantiated_fixtures
|
143
144
|
end
|
144
145
|
|
145
146
|
def teardown_fixtures
|
147
|
+
teardown_asynchronous_queries_session
|
148
|
+
|
146
149
|
# Rollback changes if a transaction is active.
|
147
150
|
if run_in_transaction?
|
148
151
|
teardown_transactional_fixtures
|
@@ -154,6 +157,14 @@ module ActiveRecord
|
|
154
157
|
ActiveRecord::Base.connection_handler.clear_active_connections!(:all)
|
155
158
|
end
|
156
159
|
|
160
|
+
def setup_asynchronous_queries_session
|
161
|
+
@_async_queries_session = ActiveRecord::Base.asynchronous_queries_tracker.start_session
|
162
|
+
end
|
163
|
+
|
164
|
+
def teardown_asynchronous_queries_session
|
165
|
+
ActiveRecord::Base.asynchronous_queries_tracker.finalize_session(true) if @_async_queries_session
|
166
|
+
end
|
167
|
+
|
157
168
|
def invalidate_already_loaded_fixtures
|
158
169
|
@@already_loaded_fixtures.clear
|
159
170
|
end
|
@@ -190,6 +201,7 @@ module ActiveRecord
|
|
190
201
|
|
191
202
|
def teardown_transactional_fixtures
|
192
203
|
ActiveSupport::Notifications.unsubscribe(@connection_subscriber) if @connection_subscriber
|
204
|
+
|
193
205
|
unless @fixture_connection_pools.map(&:unpin_connection!).all?
|
194
206
|
# Something caused the transaction to be committed or rolled back
|
195
207
|
# We can no longer trust the database is in a clean state.
|
@@ -52,7 +52,7 @@ module ActiveRecord
|
|
52
52
|
# assert_queries_match(/LIMIT \?/) { Post.first }
|
53
53
|
#
|
54
54
|
# If the +:include_schema+ option is provided, any queries (including schema related)
|
55
|
-
#
|
55
|
+
# that match the matcher are considered.
|
56
56
|
#
|
57
57
|
# assert_queries_match(/FROM pg_attribute/i, include_schema: true) { Post.columns }
|
58
58
|
#
|
@@ -80,7 +80,7 @@ module ActiveRecord
|
|
80
80
|
# assert_no_queries_match(/SELECT/i) { post.comments }
|
81
81
|
#
|
82
82
|
# If the +:include_schema+ option is provided, any queries (including schema related)
|
83
|
-
#
|
83
|
+
# that match the matcher are counted.
|
84
84
|
#
|
85
85
|
# assert_no_queries_match(/FROM pg_attribute/i, include_schema: true) { Post.columns }
|
86
86
|
#
|
@@ -40,7 +40,7 @@ module ActiveRecord
|
|
40
40
|
# +nil+ if the token is invalid or the record was not found.
|
41
41
|
def find_by_token_for(purpose, token)
|
42
42
|
raise UnknownPrimaryKey.new(self) unless model.primary_key
|
43
|
-
model.token_definitions.fetch(purpose).resolve_token(token) { |id| find_by(model.primary_key => id) }
|
43
|
+
model.token_definitions.fetch(purpose).resolve_token(token) { |id| find_by(model.primary_key => [id]) }
|
44
44
|
end
|
45
45
|
|
46
46
|
# Finds a record using a given +token+ for a predefined +purpose+. Raises
|
@@ -14,6 +14,7 @@ module ActiveRecord
|
|
14
14
|
end
|
15
15
|
super
|
16
16
|
@klass = options[:class]
|
17
|
+
@klass = @klass.superclass if @klass.singleton_class?
|
17
18
|
end
|
18
19
|
|
19
20
|
def validate_each(record, attribute, value)
|
@@ -53,17 +54,17 @@ module ActiveRecord
|
|
53
54
|
private
|
54
55
|
# The check for an existing value should be run from a class that
|
55
56
|
# isn't abstract. This means working down from the current class
|
56
|
-
# (self), to the first non-abstract class.
|
57
|
-
# their subclasses, we have to build the hierarchy between self and
|
58
|
-
# the record's class.
|
57
|
+
# (self), to the first non-abstract class.
|
59
58
|
def find_finder_class_for(record)
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
59
|
+
current_class = record.class
|
60
|
+
found_class = nil
|
61
|
+
loop do
|
62
|
+
found_class = current_class unless current_class.abstract_class?
|
63
|
+
break if current_class == @klass
|
64
|
+
current_class = current_class.superclass
|
64
65
|
end
|
65
66
|
|
66
|
-
|
67
|
+
found_class
|
67
68
|
end
|
68
69
|
|
69
70
|
def validation_needed?(klass, record, attribute)
|
data/lib/active_record.rb
CHANGED
@@ -29,6 +29,7 @@ require "active_support/ordered_options"
|
|
29
29
|
require "active_model"
|
30
30
|
require "arel"
|
31
31
|
require "yaml"
|
32
|
+
require "zlib"
|
32
33
|
|
33
34
|
require "active_record/version"
|
34
35
|
require "active_record/deprecator"
|
@@ -196,6 +197,20 @@ module ActiveRecord
|
|
196
197
|
singleton_class.attr_accessor :schema_cache_ignored_tables
|
197
198
|
self.schema_cache_ignored_tables = []
|
198
199
|
|
200
|
+
# Checks to see if the +table_name+ is ignored by checking
|
201
|
+
# against the +schema_cache_ignored_tables+ option.
|
202
|
+
#
|
203
|
+
# ActiveRecord.schema_cache_ignored_table?(:developers)
|
204
|
+
#
|
205
|
+
def self.schema_cache_ignored_table?(table_name)
|
206
|
+
ActiveRecord.schema_cache_ignored_tables.any? do |ignored|
|
207
|
+
ignored === table_name
|
208
|
+
end
|
209
|
+
end
|
210
|
+
|
211
|
+
singleton_class.attr_accessor :database_cli
|
212
|
+
self.database_cli = { postgresql: "psql", mysql: %w[mysql mysql5], sqlite: "sqlite3" }
|
213
|
+
|
199
214
|
singleton_class.attr_reader :default_timezone
|
200
215
|
|
201
216
|
# Determines whether to use Time.utc (using :utc) or Time.local (using :local) when pulling
|
@@ -253,14 +268,6 @@ module ActiveRecord
|
|
253
268
|
singleton_class.attr_accessor :reading_role
|
254
269
|
self.reading_role = :reading
|
255
270
|
|
256
|
-
def self.legacy_connection_handling=(_)
|
257
|
-
raise ArgumentError, <<~MSG.squish
|
258
|
-
The `legacy_connection_handling` setter was deprecated in 7.0 and removed in 7.1,
|
259
|
-
but is still defined in your configuration. Please remove this call as it no longer
|
260
|
-
has any effect."
|
261
|
-
MSG
|
262
|
-
end
|
263
|
-
|
264
271
|
##
|
265
272
|
# :singleton-method: async_query_executor
|
266
273
|
# Sets the async_query_executor for an application. By default the thread pool executor
|
@@ -344,29 +351,6 @@ module ActiveRecord
|
|
344
351
|
singleton_class.attr_accessor :run_after_transaction_callbacks_in_order_defined
|
345
352
|
self.run_after_transaction_callbacks_in_order_defined = false
|
346
353
|
|
347
|
-
def self.commit_transaction_on_non_local_return
|
348
|
-
ActiveRecord.deprecator.warn <<-WARNING.squish
|
349
|
-
`Rails.application.config.active_record.commit_transaction_on_non_local_return`
|
350
|
-
is deprecated and will be removed in Rails 8.0.
|
351
|
-
WARNING
|
352
|
-
end
|
353
|
-
|
354
|
-
def self.commit_transaction_on_non_local_return=(value)
|
355
|
-
ActiveRecord.deprecator.warn <<-WARNING.squish
|
356
|
-
`Rails.application.config.active_record.commit_transaction_on_non_local_return`
|
357
|
-
is deprecated and will be removed in Rails 8.0.
|
358
|
-
WARNING
|
359
|
-
end
|
360
|
-
|
361
|
-
##
|
362
|
-
# :singleton-method: warn_on_records_fetched_greater_than
|
363
|
-
# Specify a threshold for the size of query result sets. If the number of
|
364
|
-
# records in the set exceeds the threshold, a warning is logged. This can
|
365
|
-
# be used to identify queries which load thousands of records and
|
366
|
-
# potentially cause memory bloat.
|
367
|
-
singleton_class.attr_accessor :warn_on_records_fetched_greater_than
|
368
|
-
self.warn_on_records_fetched_greater_than = false
|
369
|
-
|
370
354
|
singleton_class.attr_accessor :application_record_class
|
371
355
|
self.application_record_class = nil
|
372
356
|
|
@@ -444,20 +428,6 @@ module ActiveRecord
|
|
444
428
|
singleton_class.attr_accessor :verify_foreign_keys_for_fixtures
|
445
429
|
self.verify_foreign_keys_for_fixtures = false
|
446
430
|
|
447
|
-
def self.allow_deprecated_singular_associations_name
|
448
|
-
ActiveRecord.deprecator.warn <<-WARNING.squish
|
449
|
-
`Rails.application.config.active_record.allow_deprecated_singular_associations_name`
|
450
|
-
is deprecated and will be removed in Rails 8.0.
|
451
|
-
WARNING
|
452
|
-
end
|
453
|
-
|
454
|
-
def self.allow_deprecated_singular_associations_name=(value)
|
455
|
-
ActiveRecord.deprecator.warn <<-WARNING.squish
|
456
|
-
`Rails.application.config.active_record.allow_deprecated_singular_associations_name`
|
457
|
-
is deprecated and will be removed in Rails 8.0.
|
458
|
-
WARNING
|
459
|
-
end
|
460
|
-
|
461
431
|
singleton_class.attr_accessor :query_transformers
|
462
432
|
self.query_transformers = []
|
463
433
|
|
data/lib/arel/collectors/bind.rb
CHANGED
data/lib/arel/table.rb
CHANGED
@@ -12,13 +12,9 @@ module Arel # :nodoc: all
|
|
12
12
|
attr_reader :table_alias
|
13
13
|
|
14
14
|
def initialize(name, as: nil, klass: nil, type_caster: klass&.type_caster)
|
15
|
-
|
16
|
-
case name
|
17
|
-
when Symbol then name.to_s
|
18
|
-
else
|
19
|
-
name
|
20
|
-
end
|
15
|
+
name = name.name if name.is_a?(Symbol)
|
21
16
|
|
17
|
+
@name = name
|
22
18
|
@klass = klass
|
23
19
|
@type_caster = type_caster
|
24
20
|
|
@@ -84,7 +80,7 @@ module Arel # :nodoc: all
|
|
84
80
|
end
|
85
81
|
|
86
82
|
def [](name, table = self)
|
87
|
-
name = name.
|
83
|
+
name = name.name if name.is_a?(Symbol)
|
88
84
|
name = @klass.attribute_aliases[name] || name if @klass
|
89
85
|
Attribute.new(table, name)
|
90
86
|
end
|
data/lib/arel/visitors/sqlite.rb
CHANGED
@@ -33,6 +33,31 @@ module Arel # :nodoc: all
|
|
33
33
|
collector << " IS NOT "
|
34
34
|
visit o.right, collector
|
35
35
|
end
|
36
|
+
|
37
|
+
# Queries used in UNION should not be wrapped by parentheses,
|
38
|
+
# because it is an invalid syntax in SQLite.
|
39
|
+
def infix_value_with_paren(o, collector, value, suppress_parens = false)
|
40
|
+
collector << "( " unless suppress_parens
|
41
|
+
|
42
|
+
left = o.left.is_a?(Nodes::Grouping) ? o.left.expr : o.left
|
43
|
+
collector = if left.class == o.class
|
44
|
+
infix_value_with_paren(left, collector, value, true)
|
45
|
+
else
|
46
|
+
grouping_parentheses left, collector, false
|
47
|
+
end
|
48
|
+
|
49
|
+
collector << value
|
50
|
+
|
51
|
+
right = o.right.is_a?(Nodes::Grouping) ? o.right.expr : o.right
|
52
|
+
collector = if right.class == o.class
|
53
|
+
infix_value_with_paren(right, collector, value, true)
|
54
|
+
else
|
55
|
+
grouping_parentheses right, collector, false
|
56
|
+
end
|
57
|
+
|
58
|
+
collector << " )" unless suppress_parens
|
59
|
+
collector
|
60
|
+
end
|
36
61
|
end
|
37
62
|
end
|
38
63
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: activerecord
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 8.0.0.rc1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- David Heinemeier Hansson
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-10-
|
11
|
+
date: 2024-10-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -16,28 +16,28 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - '='
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version:
|
19
|
+
version: 8.0.0.rc1
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - '='
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version:
|
26
|
+
version: 8.0.0.rc1
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: activemodel
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
31
|
- - '='
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version:
|
33
|
+
version: 8.0.0.rc1
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - '='
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version:
|
40
|
+
version: 8.0.0.rc1
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: timeout
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -318,7 +318,6 @@ files:
|
|
318
318
|
- lib/active_record/relation/predicate_builder/relation_handler.rb
|
319
319
|
- lib/active_record/relation/query_attribute.rb
|
320
320
|
- lib/active_record/relation/query_methods.rb
|
321
|
-
- lib/active_record/relation/record_fetch_warning.rb
|
322
321
|
- lib/active_record/relation/spawn_methods.rb
|
323
322
|
- lib/active_record/relation/where_clause.rb
|
324
323
|
- lib/active_record/result.rb
|
@@ -476,10 +475,10 @@ licenses:
|
|
476
475
|
- MIT
|
477
476
|
metadata:
|
478
477
|
bug_tracker_uri: https://github.com/rails/rails/issues
|
479
|
-
changelog_uri: https://github.com/rails/rails/blob/
|
480
|
-
documentation_uri: https://api.rubyonrails.org/
|
478
|
+
changelog_uri: https://github.com/rails/rails/blob/v8.0.0.rc1/activerecord/CHANGELOG.md
|
479
|
+
documentation_uri: https://api.rubyonrails.org/v8.0.0.rc1/
|
481
480
|
mailing_list_uri: https://discuss.rubyonrails.org/c/rubyonrails-talk
|
482
|
-
source_code_uri: https://github.com/rails/rails/tree/
|
481
|
+
source_code_uri: https://github.com/rails/rails/tree/v8.0.0.rc1/activerecord
|
483
482
|
rubygems_mfa_required: 'true'
|
484
483
|
post_install_message:
|
485
484
|
rdoc_options:
|
@@ -491,7 +490,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
491
490
|
requirements:
|
492
491
|
- - ">="
|
493
492
|
- !ruby/object:Gem::Version
|
494
|
-
version: 3.
|
493
|
+
version: 3.2.0
|
495
494
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
496
495
|
requirements:
|
497
496
|
- - ">="
|
@@ -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
|