activerecord 7.1.0 → 7.1.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (63) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +194 -0
  3. data/README.rdoc +1 -0
  4. data/lib/active_record/associations/association.rb +2 -1
  5. data/lib/active_record/associations/preloader/association.rb +4 -1
  6. data/lib/active_record/associations.rb +15 -15
  7. data/lib/active_record/attribute_methods/before_type_cast.rb +1 -1
  8. data/lib/active_record/attribute_methods/dirty.rb +14 -10
  9. data/lib/active_record/attribute_methods.rb +1 -1
  10. data/lib/active_record/callbacks.rb +2 -2
  11. data/lib/active_record/connection_adapters/abstract/connection_pool.rb +11 -8
  12. data/lib/active_record/connection_adapters/abstract/database_statements.rb +5 -3
  13. data/lib/active_record/connection_adapters/abstract/query_cache.rb +2 -1
  14. data/lib/active_record/connection_adapters/abstract/schema_statements.rb +1 -3
  15. data/lib/active_record/connection_adapters/abstract_adapter.rb +13 -4
  16. data/lib/active_record/connection_adapters/mysql2/database_statements.rb +3 -0
  17. data/lib/active_record/connection_adapters/postgresql/column.rb +14 -2
  18. data/lib/active_record/connection_adapters/postgresql/database_statements.rb +4 -1
  19. data/lib/active_record/connection_adapters/postgresql/oid/money.rb +3 -2
  20. data/lib/active_record/connection_adapters/postgresql/oid/timestamp_with_time_zone.rb +1 -1
  21. data/lib/active_record/connection_adapters/postgresql/schema_statements.rb +14 -6
  22. data/lib/active_record/connection_adapters/postgresql_adapter.rb +32 -32
  23. data/lib/active_record/connection_adapters/sqlite3/database_statements.rb +10 -3
  24. data/lib/active_record/connection_adapters/trilogy/database_statements.rb +1 -0
  25. data/lib/active_record/connection_adapters/trilogy_adapter.rb +9 -1
  26. data/lib/active_record/connection_handling.rb +1 -1
  27. data/lib/active_record/core.rb +62 -28
  28. data/lib/active_record/delegated_type.rb +1 -1
  29. data/lib/active_record/encryption/encryptable_record.rb +7 -1
  30. data/lib/active_record/encryption/encrypted_attribute_type.rb +4 -0
  31. data/lib/active_record/encryption/extended_deterministic_queries.rb +0 -15
  32. data/lib/active_record/enum.rb +6 -9
  33. data/lib/active_record/errors.rb +5 -4
  34. data/lib/active_record/fixtures.rb +16 -0
  35. data/lib/active_record/future_result.rb +1 -0
  36. data/lib/active_record/gem_version.rb +1 -1
  37. data/lib/active_record/insert_all.rb +3 -3
  38. data/lib/active_record/internal_metadata.rb +3 -1
  39. data/lib/active_record/middleware/database_selector.rb +1 -1
  40. data/lib/active_record/migration/command_recorder.rb +4 -1
  41. data/lib/active_record/migration/compatibility.rb +8 -0
  42. data/lib/active_record/migration/pending_migration_connection.rb +21 -0
  43. data/lib/active_record/migration.rb +9 -5
  44. data/lib/active_record/model_schema.rb +5 -5
  45. data/lib/active_record/nested_attributes.rb +7 -9
  46. data/lib/active_record/normalization.rb +8 -0
  47. data/lib/active_record/persistence.rb +4 -3
  48. data/lib/active_record/promise.rb +1 -1
  49. data/lib/active_record/railtie.rb +1 -1
  50. data/lib/active_record/railties/controller_runtime.rb +2 -1
  51. data/lib/active_record/railties/databases.rake +5 -5
  52. data/lib/active_record/reflection.rb +13 -1
  53. data/lib/active_record/relation/calculations.rb +44 -9
  54. data/lib/active_record/relation/delegation.rb +1 -1
  55. data/lib/active_record/relation/query_methods.rb +1 -1
  56. data/lib/active_record/relation.rb +18 -3
  57. data/lib/active_record/runtime_registry.rb +15 -1
  58. data/lib/active_record/schema_migration.rb +1 -1
  59. data/lib/active_record/secure_token.rb +1 -1
  60. data/lib/active_record/tasks/database_tasks.rb +5 -5
  61. data/lib/active_record/timestamp.rb +1 -1
  62. data/lib/arel/nodes/homogeneous_in.rb +1 -1
  63. metadata +10 -9
@@ -164,8 +164,8 @@ module ActiveRecord
164
164
  #
165
165
  # If creation failed because of a unique constraint, this method will
166
166
  # assume it encountered a race condition and will try finding the record
167
- # once more If somehow the second find still find no record because a
168
- # concurrent DELETE happened, it will then raise an
167
+ # once more. If somehow the second find still does not find a record
168
+ # because a concurrent DELETE happened, it will then raise an
169
169
  # ActiveRecord::RecordNotFound exception.
170
170
  #
171
171
  # Please note <b>this method is not atomic</b>, it runs first a SELECT,
@@ -291,6 +291,11 @@ module ActiveRecord
291
291
  end
292
292
 
293
293
  # Returns true if there are no records.
294
+ #
295
+ # When a pattern argument is given, this method checks whether elements in
296
+ # the Enumerable match the pattern via the case-equality operator (<tt>===</tt>).
297
+ #
298
+ # posts.none?(Comment) # => true or false
294
299
  def none?(*args)
295
300
  return true if @none
296
301
 
@@ -299,6 +304,11 @@ module ActiveRecord
299
304
  end
300
305
 
301
306
  # Returns true if there are any records.
307
+ #
308
+ # When a pattern argument is given, this method checks whether elements in
309
+ # the Enumerable match the pattern via the case-equality operator (<tt>===</tt>).
310
+ #
311
+ # posts.any?(Post) # => true or false
302
312
  def any?(*args)
303
313
  return false if @none
304
314
 
@@ -307,6 +317,11 @@ module ActiveRecord
307
317
  end
308
318
 
309
319
  # Returns true if there is exactly one record.
320
+ #
321
+ # When a pattern argument is given, this method checks whether elements in
322
+ # the Enumerable match the pattern via the case-equality operator (<tt>===</tt>).
323
+ #
324
+ # posts.one?(Post) # => true or false
310
325
  def one?(*args)
311
326
  return false if @none
312
327
 
@@ -960,7 +975,7 @@ module ActiveRecord
960
975
  def exec_main_query(async: false)
961
976
  if @none
962
977
  if async
963
- return Promise::Complete.new([])
978
+ return FutureResult::Complete.new([])
964
979
  else
965
980
  return []
966
981
  end
@@ -17,13 +17,27 @@ module ActiveRecord
17
17
  ActiveSupport::IsolatedExecutionState[:active_record_sql_runtime] = runtime
18
18
  end
19
19
 
20
+ def async_sql_runtime
21
+ ActiveSupport::IsolatedExecutionState[:active_record_async_sql_runtime] ||= 0.0
22
+ end
23
+
24
+ def async_sql_runtime=(runtime)
25
+ ActiveSupport::IsolatedExecutionState[:active_record_async_sql_runtime] = runtime
26
+ end
27
+
20
28
  def reset
21
29
  rt, self.sql_runtime = sql_runtime, 0.0
30
+ self.async_sql_runtime = 0.0
22
31
  rt
23
32
  end
24
33
  end
25
34
  end
26
35
 
27
36
  ActiveSupport::Notifications.monotonic_subscribe("sql.active_record") do |name, start, finish, id, payload|
28
- ActiveRecord::RuntimeRegistry.sql_runtime += (finish - start) * 1_000.0
37
+ runtime = (finish - start) * 1_000.0
38
+
39
+ if payload[:async]
40
+ ActiveRecord::RuntimeRegistry.async_sql_runtime += (runtime - payload[:lock_wait])
41
+ end
42
+ ActiveRecord::RuntimeRegistry.sql_runtime += runtime
29
43
  end
@@ -6,7 +6,7 @@ module ActiveRecord
6
6
  # number is inserted in to the schema migrations table so it doesn't need
7
7
  # to be executed the next time.
8
8
  class SchemaMigration # :nodoc:
9
- class NullSchemaMigration
9
+ class NullSchemaMigration # :nodoc:
10
10
  end
11
11
 
12
12
  attr_reader :connection, :arel_table
@@ -53,7 +53,7 @@ module ActiveRecord
53
53
  define_method("regenerate_#{attribute}") { update! attribute => self.class.generate_unique_secure_token(length: length) }
54
54
  set_callback on, on == :initialize ? :after : :before do
55
55
  if new_record? && !query_attribute(attribute)
56
- write_attribute(attribute, self.class.generate_unique_secure_token(length: length))
56
+ send("#{attribute}=", self.class.generate_unique_secure_token(length: length))
57
57
  end
58
58
  end
59
59
  end
@@ -125,11 +125,11 @@ module ActiveRecord
125
125
  end
126
126
 
127
127
  def create_all
128
- db_config = migration_connection.pool.db_config
129
-
130
- each_local_configuration { |db_config| create(db_config) }
131
-
132
- migration_class.establish_connection(db_config)
128
+ each_local_configuration do |db_config|
129
+ with_temporary_connection(db_config) do
130
+ create(db_config)
131
+ end
132
+ end
133
133
  end
134
134
 
135
135
  def setup_initial_database_yaml # :nodoc:
@@ -30,7 +30,7 @@ module ActiveRecord
30
30
  #
31
31
  # ActiveRecord::Base.time_zone_aware_types = [:datetime]
32
32
  #
33
- # You can also add database specific timezone aware types. For example, for PostgreSQL:
33
+ # You can also add database-specific timezone aware types. For example, for PostgreSQL:
34
34
  #
35
35
  # ActiveRecord::Base.time_zone_aware_types += [:tsrange, :tstzrange]
36
36
  #
@@ -48,7 +48,7 @@ module Arel # :nodoc: all
48
48
  end
49
49
 
50
50
  def proc_for_binds
51
- -> value { ActiveModel::Attribute.with_cast_value(attribute.name, value, attribute.type_caster) }
51
+ -> value { ActiveModel::Attribute.with_cast_value(attribute.name, value, ActiveModel::Type.default_value) }
52
52
  end
53
53
 
54
54
  def fetch_attribute(&block)
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: 7.1.0
4
+ version: 7.1.3
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: 2023-10-05 00:00:00.000000000 Z
11
+ date: 2024-01-16 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: 7.1.0
19
+ version: 7.1.3
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: 7.1.0
26
+ version: 7.1.3
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: 7.1.0
33
+ version: 7.1.3
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: 7.1.0
40
+ version: 7.1.3
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: timeout
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -279,6 +279,7 @@ files:
279
279
  - lib/active_record/migration/default_strategy.rb
280
280
  - lib/active_record/migration/execution_strategy.rb
281
281
  - lib/active_record/migration/join_table.rb
282
+ - lib/active_record/migration/pending_migration_connection.rb
282
283
  - lib/active_record/model_schema.rb
283
284
  - lib/active_record/nested_attributes.rb
284
285
  - lib/active_record/no_touching.rb
@@ -469,10 +470,10 @@ licenses:
469
470
  - MIT
470
471
  metadata:
471
472
  bug_tracker_uri: https://github.com/rails/rails/issues
472
- changelog_uri: https://github.com/rails/rails/blob/v7.1.0/activerecord/CHANGELOG.md
473
- documentation_uri: https://api.rubyonrails.org/v7.1.0/
473
+ changelog_uri: https://github.com/rails/rails/blob/v7.1.3/activerecord/CHANGELOG.md
474
+ documentation_uri: https://api.rubyonrails.org/v7.1.3/
474
475
  mailing_list_uri: https://discuss.rubyonrails.org/c/rubyonrails-talk
475
- source_code_uri: https://github.com/rails/rails/tree/v7.1.0/activerecord
476
+ source_code_uri: https://github.com/rails/rails/tree/v7.1.3/activerecord
476
477
  rubygems_mfa_required: 'true'
477
478
  post_install_message:
478
479
  rdoc_options: