activerecord 7.0.2.4 → 7.0.4

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of activerecord might be problematic. Click here for more details.

Files changed (75) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +172 -0
  3. data/lib/active_record/associations/collection_association.rb +1 -2
  4. data/lib/active_record/associations/collection_proxy.rb +2 -2
  5. data/lib/active_record/associations/has_many_association.rb +7 -4
  6. data/lib/active_record/associations/join_dependency.rb +17 -13
  7. data/lib/active_record/associations.rb +15 -15
  8. data/lib/active_record/attribute_methods/serialization.rb +34 -50
  9. data/lib/active_record/attribute_methods/time_zone_conversion.rb +4 -0
  10. data/lib/active_record/attribute_methods.rb +1 -1
  11. data/lib/active_record/base.rb +3 -3
  12. data/lib/active_record/coders/yaml_column.rb +10 -2
  13. data/lib/active_record/connection_adapters/abstract/connection_handler.rb +1 -1
  14. data/lib/active_record/connection_adapters/abstract/schema_definitions.rb +4 -0
  15. data/lib/active_record/connection_adapters/abstract/schema_statements.rb +3 -3
  16. data/lib/active_record/connection_adapters/abstract_adapter.rb +5 -5
  17. data/lib/active_record/connection_adapters/abstract_mysql_adapter.rb +9 -1
  18. data/lib/active_record/connection_adapters/mysql/quoting.rb +3 -1
  19. data/lib/active_record/connection_adapters/mysql/schema_statements.rb +19 -1
  20. data/lib/active_record/connection_adapters/postgresql/oid/hstore.rb +2 -2
  21. data/lib/active_record/connection_adapters/postgresql/quoting.rb +1 -1
  22. data/lib/active_record/connection_adapters/postgresql/referential_integrity.rb +3 -1
  23. data/lib/active_record/connection_adapters/postgresql/schema_statements.rb +2 -0
  24. data/lib/active_record/connection_adapters/postgresql_adapter.rb +4 -3
  25. data/lib/active_record/connection_adapters/sqlite3/schema_statements.rb +2 -2
  26. data/lib/active_record/connection_adapters/sqlite3_adapter.rb +7 -2
  27. data/lib/active_record/connection_handling.rb +2 -2
  28. data/lib/active_record/core.rb +3 -3
  29. data/lib/active_record/delegated_type.rb +1 -1
  30. data/lib/active_record/encryption/configurable.rb +8 -2
  31. data/lib/active_record/encryption/contexts.rb +3 -3
  32. data/lib/active_record/encryption/derived_secret_key_provider.rb +1 -1
  33. data/lib/active_record/encryption/deterministic_key_provider.rb +1 -1
  34. data/lib/active_record/encryption/encryptable_record.rb +2 -4
  35. data/lib/active_record/encryption/encrypted_attribute_type.rb +2 -2
  36. data/lib/active_record/encryption/encryptor.rb +7 -7
  37. data/lib/active_record/encryption/envelope_encryption_key_provider.rb +3 -3
  38. data/lib/active_record/encryption/extended_deterministic_queries.rb +4 -4
  39. data/lib/active_record/encryption/message.rb +1 -1
  40. data/lib/active_record/encryption/properties.rb +1 -1
  41. data/lib/active_record/encryption/scheme.rb +1 -1
  42. data/lib/active_record/enum.rb +1 -1
  43. data/lib/active_record/fixtures.rb +4 -4
  44. data/lib/active_record/gem_version.rb +3 -3
  45. data/lib/active_record/locking/pessimistic.rb +3 -3
  46. data/lib/active_record/log_subscriber.rb +10 -5
  47. data/lib/active_record/middleware/database_selector.rb +13 -6
  48. data/lib/active_record/middleware/shard_selector.rb +4 -4
  49. data/lib/active_record/migration/command_recorder.rb +3 -3
  50. data/lib/active_record/migration/compatibility.rb +7 -26
  51. data/lib/active_record/migration.rb +5 -4
  52. data/lib/active_record/model_schema.rb +22 -10
  53. data/lib/active_record/persistence.rb +9 -8
  54. data/lib/active_record/querying.rb +1 -1
  55. data/lib/active_record/railtie.rb +20 -16
  56. data/lib/active_record/railties/databases.rake +16 -11
  57. data/lib/active_record/reflection.rb +6 -0
  58. data/lib/active_record/relation/batches.rb +3 -3
  59. data/lib/active_record/relation/query_methods.rb +27 -6
  60. data/lib/active_record/relation.rb +7 -6
  61. data/lib/active_record/sanitization.rb +6 -5
  62. data/lib/active_record/scoping/default.rb +5 -7
  63. data/lib/active_record/serialization.rb +5 -0
  64. data/lib/active_record/signed_id.rb +2 -2
  65. data/lib/active_record/store.rb +7 -2
  66. data/lib/active_record/tasks/database_tasks.rb +26 -21
  67. data/lib/active_record/tasks/postgresql_database_tasks.rb +1 -2
  68. data/lib/active_record/test_fixtures.rb +12 -5
  69. data/lib/active_record/translation.rb +1 -1
  70. data/lib/active_record/validations/associated.rb +3 -3
  71. data/lib/active_record/validations/presence.rb +2 -2
  72. data/lib/active_record/validations/uniqueness.rb +3 -3
  73. data/lib/active_record/version.rb +1 -1
  74. data/lib/active_record.rb +14 -0
  75. metadata +10 -10
@@ -59,7 +59,7 @@ module ActiveRecord
59
59
  # u.color = 'green'
60
60
  # u.color_changed? # => true
61
61
  # u.color_was # => 'black'
62
- # u.color_change # => ['black', 'red']
62
+ # u.color_change # => ['black', 'green']
63
63
  #
64
64
  # # Add additional accessors to an existing store through store_accessor
65
65
  # class SuperUser < User
@@ -268,7 +268,7 @@ module ActiveRecord
268
268
  end
269
269
 
270
270
  def dump(obj)
271
- @coder.dump self.class.as_indifferent_hash(obj)
271
+ @coder.dump as_regular_hash(obj)
272
272
  end
273
273
 
274
274
  def load(yaml)
@@ -285,6 +285,11 @@ module ActiveRecord
285
285
  ActiveSupport::HashWithIndifferentAccess.new
286
286
  end
287
287
  end
288
+
289
+ private
290
+ def as_regular_hash(obj)
291
+ obj.respond_to?(:to_hash) ? obj.to_hash : {}
292
+ end
288
293
  end
289
294
  end
290
295
  end
@@ -188,29 +188,31 @@ module ActiveRecord
188
188
  def prepare_all
189
189
  seed = false
190
190
 
191
- configs_for(env_name: env).each do |db_config|
191
+ each_current_configuration(env) do |db_config|
192
192
  ActiveRecord::Base.establish_connection(db_config)
193
193
 
194
- # Skipped when no database
195
- migrate
196
-
197
- if ActiveRecord.dump_schema_after_migration
198
- dump_schema(db_config, ActiveRecord.schema_format)
199
- end
200
- rescue ActiveRecord::NoDatabaseError
201
- create_current(db_config.env_name, db_config.name)
202
-
203
- if File.exist?(schema_dump_path(db_config))
204
- load_schema(
205
- db_config,
206
- ActiveRecord.schema_format,
207
- nil
208
- )
209
- else
194
+ begin
195
+ # Skipped when no database
210
196
  migrate
211
- end
212
197
 
213
- seed = true
198
+ if ActiveRecord.dump_schema_after_migration
199
+ dump_schema(db_config, ActiveRecord.schema_format)
200
+ end
201
+ rescue ActiveRecord::NoDatabaseError
202
+ create(db_config)
203
+
204
+ if File.exist?(schema_dump_path(db_config))
205
+ load_schema(
206
+ db_config,
207
+ ActiveRecord.schema_format,
208
+ nil
209
+ )
210
+ else
211
+ migrate
212
+ end
213
+
214
+ seed = true
215
+ end
214
216
  end
215
217
 
216
218
  ActiveRecord::Base.establish_connection
@@ -364,6 +366,7 @@ module ActiveRecord
364
366
 
365
367
  def load_schema(db_config, format = ActiveRecord.schema_format, file = nil) # :nodoc:
366
368
  file ||= schema_dump_path(db_config, format)
369
+ return unless file
367
370
 
368
371
  verbose_was, Migration.verbose = Migration.verbose, verbose? && ENV["VERBOSE"]
369
372
  check_schema_file(file)
@@ -389,7 +392,7 @@ module ActiveRecord
389
392
 
390
393
  file ||= schema_dump_path(db_config)
391
394
 
392
- return true unless File.exist?(file)
395
+ return true unless file && File.exist?(file)
393
396
 
394
397
  ActiveRecord::Base.establish_connection(db_config)
395
398
 
@@ -402,7 +405,7 @@ module ActiveRecord
402
405
  def reconstruct_from_schema(db_config, format = ActiveRecord.schema_format, file = nil) # :nodoc:
403
406
  file ||= schema_dump_path(db_config, format)
404
407
 
405
- check_schema_file(file)
408
+ check_schema_file(file) if file
406
409
 
407
410
  ActiveRecord::Base.establish_connection(db_config)
408
411
 
@@ -420,6 +423,8 @@ module ActiveRecord
420
423
  def dump_schema(db_config, format = ActiveRecord.schema_format) # :nodoc:
421
424
  require "active_record/schema_dumper"
422
425
  filename = schema_dump_path(db_config, format)
426
+ return unless filename
427
+
423
428
  connection = ActiveRecord::Base.connection
424
429
 
425
430
  FileUtils.mkdir_p(db_dir)
@@ -58,7 +58,6 @@ module ActiveRecord
58
58
  end
59
59
 
60
60
  args = ["--schema-only", "--no-privileges", "--no-owner"]
61
- args << "--no-comments" if connection.database_version >= 110_000
62
61
  args.concat(["--file", filename])
63
62
 
64
63
  args.concat(Array(extra_flags)) if extra_flags
@@ -81,7 +80,7 @@ module ActiveRecord
81
80
  end
82
81
 
83
82
  def structure_load(filename, extra_flags)
84
- args = ["--set", ON_ERROR_STOP_1, "--quiet", "--no-psqlrc", "--file", filename]
83
+ args = ["--set", ON_ERROR_STOP_1, "--quiet", "--no-psqlrc", "--output", File::NULL, "--file", filename]
85
84
  args.concat(Array(extra_flags)) if extra_flags
86
85
  args << db_config.database
87
86
  run_cmd("psql", args, "loading")
@@ -86,6 +86,9 @@ module ActiveRecord
86
86
  include methods
87
87
  end
88
88
 
89
+ # Prevents automatically wrapping each specified test in a transaction,
90
+ # to allow application logic transactions to be tested in a top-level
91
+ # (non-nested) context.
89
92
  def uses_transaction(*methods)
90
93
  @uses_transaction = [] unless defined?(@uses_transaction)
91
94
  @uses_transaction.concat methods.map(&:to_s)
@@ -134,7 +137,7 @@ module ActiveRecord
134
137
  @connection_subscriber = ActiveSupport::Notifications.subscribe("!connection.active_record") do |_, _, _, _, payload|
135
138
  spec_name = payload[:spec_name] if payload.key?(:spec_name)
136
139
  shard = payload[:shard] if payload.key?(:shard)
137
- setup_shared_connection_pool
140
+ setup_shared_connection_pool if ActiveRecord.legacy_connection_handling
138
141
 
139
142
  if spec_name
140
143
  begin
@@ -143,10 +146,14 @@ module ActiveRecord
143
146
  connection = nil
144
147
  end
145
148
 
146
- if connection && !@fixture_connections.include?(connection)
147
- connection.begin_transaction joinable: false, _lazy: false
148
- connection.pool.lock_thread = true if lock_threads
149
- @fixture_connections << connection
149
+ if connection
150
+ setup_shared_connection_pool unless ActiveRecord.legacy_connection_handling
151
+
152
+ if !@fixture_connections.include?(connection)
153
+ connection.begin_transaction joinable: false, _lazy: false
154
+ connection.pool.lock_thread = true if lock_threads
155
+ @fixture_connections << connection
156
+ end
150
157
  end
151
158
  end
152
159
  end
@@ -16,7 +16,7 @@ module ActiveRecord
16
16
  classes
17
17
  end
18
18
 
19
- # Set the i18n scope to overwrite ActiveModel.
19
+ # Set the i18n scope to override ActiveModel.
20
20
  def i18n_scope # :nodoc:
21
21
  :activerecord
22
22
  end
@@ -42,14 +42,14 @@ module ActiveRecord
42
42
  # or an array of symbols. (e.g. <tt>on: :create</tt> or
43
43
  # <tt>on: :custom_validation_context</tt> or
44
44
  # <tt>on: [:create, :custom_validation_context]</tt>)
45
- # * <tt>:if</tt> - Specifies a method, proc or string to call to determine
45
+ # * <tt>:if</tt> - Specifies a method, proc, or string to call to determine
46
46
  # if the validation should occur (e.g. <tt>if: :allow_validation</tt>,
47
47
  # or <tt>if: Proc.new { |user| user.signup_step > 2 }</tt>). The method,
48
48
  # proc or string should return or evaluate to a +true+ or +false+ value.
49
- # * <tt>:unless</tt> - Specifies a method, proc or string to call to
49
+ # * <tt>:unless</tt> - Specifies a method, proc, or string to call to
50
50
  # determine if the validation should not occur (e.g. <tt>unless: :skip_validation</tt>,
51
51
  # or <tt>unless: Proc.new { |user| user.signup_step <= 2 }</tt>). The
52
- # method, proc or string should return or evaluate to a +true+ or +false+
52
+ # method, proc, or string should return or evaluate to a +true+ or +false+
53
53
  # value.
54
54
  def validates_associated(*attr_names)
55
55
  validates_with AssociatedValidator, _merge_attributes(attr_names)
@@ -50,11 +50,11 @@ module ActiveRecord
50
50
  # or an array of symbols. (e.g. <tt>on: :create</tt> or
51
51
  # <tt>on: :custom_validation_context</tt> or
52
52
  # <tt>on: [:create, :custom_validation_context]</tt>)
53
- # * <tt>:if</tt> - Specifies a method, proc or string to call to determine if
53
+ # * <tt>:if</tt> - Specifies a method, proc, or string to call to determine if
54
54
  # the validation should occur (e.g. <tt>if: :allow_validation</tt>, or
55
55
  # <tt>if: Proc.new { |user| user.signup_step > 2 }</tt>). The method, proc
56
56
  # or string should return or evaluate to a +true+ or +false+ value.
57
- # * <tt>:unless</tt> - Specifies a method, proc or string to call to determine
57
+ # * <tt>:unless</tt> - Specifies a method, proc, or string to call to determine
58
58
  # if the validation should not occur (e.g. <tt>unless: :skip_validation</tt>,
59
59
  # or <tt>unless: Proc.new { |user| user.signup_step <= 2 }</tt>). The method,
60
60
  # proc or string should return or evaluate to a +true+ or +false+ value.
@@ -166,14 +166,14 @@ module ActiveRecord
166
166
  # attribute is +nil+ (default is +false+).
167
167
  # * <tt>:allow_blank</tt> - If set to +true+, skips this validation if the
168
168
  # attribute is blank (default is +false+).
169
- # * <tt>:if</tt> - Specifies a method, proc or string to call to determine
169
+ # * <tt>:if</tt> - Specifies a method, proc, or string to call to determine
170
170
  # if the validation should occur (e.g. <tt>if: :allow_validation</tt>,
171
171
  # or <tt>if: Proc.new { |user| user.signup_step > 2 }</tt>). The method,
172
172
  # proc or string should return or evaluate to a +true+ or +false+ value.
173
- # * <tt>:unless</tt> - Specifies a method, proc or string to call to
173
+ # * <tt>:unless</tt> - Specifies a method, proc, or string to call to
174
174
  # determine if the validation should not occur (e.g. <tt>unless: :skip_validation</tt>,
175
175
  # or <tt>unless: Proc.new { |user| user.signup_step <= 2 }</tt>). The
176
- # method, proc or string should return or evaluate to a +true+ or +false+
176
+ # method, proc, or string should return or evaluate to a +true+ or +false+
177
177
  # value.
178
178
  #
179
179
  # === Concurrency and integrity
@@ -3,7 +3,7 @@
3
3
  require_relative "gem_version"
4
4
 
5
5
  module ActiveRecord
6
- # Returns the version of the currently loaded ActiveRecord as a <tt>Gem::Version</tt>
6
+ # Returns the currently loaded version of Active Record as a <tt>Gem::Version</tt>.
7
7
  def self.version
8
8
  gem_version
9
9
  end
data/lib/active_record.rb CHANGED
@@ -340,6 +340,20 @@ module ActiveRecord
340
340
  singleton_class.attr_accessor :query_transformers
341
341
  self.query_transformers = []
342
342
 
343
+ ##
344
+ # :singleton-method:
345
+ # Application configurable boolean that instructs the YAML Coder to use
346
+ # an unsafe load if set to true.
347
+ singleton_class.attr_accessor :use_yaml_unsafe_load
348
+ self.use_yaml_unsafe_load = false
349
+
350
+ ##
351
+ # :singleton-method:
352
+ # Application configurable array that provides additional permitted classes
353
+ # to Psych safe_load in the YAML Coder
354
+ singleton_class.attr_accessor :yaml_column_permitted_classes
355
+ self.yaml_column_permitted_classes = [Symbol]
356
+
343
357
  def self.eager_load!
344
358
  super
345
359
  ActiveRecord::Locking.eager_load!
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.0.2.4
4
+ version: 7.0.4
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: 2022-04-26 00:00:00.000000000 Z
11
+ date: 2022-09-09 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.0.2.4
19
+ version: 7.0.4
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.0.2.4
26
+ version: 7.0.4
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.0.2.4
33
+ version: 7.0.4
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.0.2.4
40
+ version: 7.0.4
41
41
  description: Databases on Rails. Build a persistent domain model by mapping database
42
42
  tables to Ruby classes. Strong conventions for associations, validations, aggregations,
43
43
  migrations, and testing come baked-in.
@@ -434,10 +434,10 @@ licenses:
434
434
  - MIT
435
435
  metadata:
436
436
  bug_tracker_uri: https://github.com/rails/rails/issues
437
- changelog_uri: https://github.com/rails/rails/blob/v7.0.2.4/activerecord/CHANGELOG.md
438
- documentation_uri: https://api.rubyonrails.org/v7.0.2.4/
437
+ changelog_uri: https://github.com/rails/rails/blob/v7.0.4/activerecord/CHANGELOG.md
438
+ documentation_uri: https://api.rubyonrails.org/v7.0.4/
439
439
  mailing_list_uri: https://discuss.rubyonrails.org/c/rubyonrails-talk
440
- source_code_uri: https://github.com/rails/rails/tree/v7.0.2.4/activerecord
440
+ source_code_uri: https://github.com/rails/rails/tree/v7.0.4/activerecord
441
441
  rubygems_mfa_required: 'true'
442
442
  post_install_message:
443
443
  rdoc_options:
@@ -456,7 +456,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
456
456
  - !ruby/object:Gem::Version
457
457
  version: '0'
458
458
  requirements: []
459
- rubygems_version: 3.1.6
459
+ rubygems_version: 3.3.3
460
460
  signing_key:
461
461
  specification_version: 4
462
462
  summary: Object-relational mapper framework (part of Rails).