activerecord 7.0.2.4 → 7.0.3

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 (63) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +47 -0
  3. data/lib/active_record/associations/collection_association.rb +1 -1
  4. data/lib/active_record/associations/collection_proxy.rb +1 -1
  5. data/lib/active_record/associations.rb +9 -9
  6. data/lib/active_record/attribute_methods/serialization.rb +34 -50
  7. data/lib/active_record/attribute_methods.rb +1 -1
  8. data/lib/active_record/base.rb +3 -3
  9. data/lib/active_record/connection_adapters/abstract/connection_handler.rb +1 -1
  10. data/lib/active_record/connection_adapters/abstract/schema_definitions.rb +4 -0
  11. data/lib/active_record/connection_adapters/abstract/schema_statements.rb +3 -3
  12. data/lib/active_record/connection_adapters/abstract_adapter.rb +5 -5
  13. data/lib/active_record/connection_adapters/abstract_mysql_adapter.rb +4 -0
  14. data/lib/active_record/connection_adapters/mysql/quoting.rb +3 -1
  15. data/lib/active_record/connection_adapters/mysql/schema_statements.rb +19 -1
  16. data/lib/active_record/connection_adapters/postgresql/quoting.rb +1 -1
  17. data/lib/active_record/connection_adapters/postgresql/schema_statements.rb +2 -0
  18. data/lib/active_record/connection_adapters/postgresql_adapter.rb +3 -3
  19. data/lib/active_record/connection_adapters/sqlite3/schema_statements.rb +1 -1
  20. data/lib/active_record/connection_handling.rb +2 -2
  21. data/lib/active_record/core.rb +3 -3
  22. data/lib/active_record/encryption/configurable.rb +8 -2
  23. data/lib/active_record/encryption/contexts.rb +3 -3
  24. data/lib/active_record/encryption/derived_secret_key_provider.rb +1 -1
  25. data/lib/active_record/encryption/deterministic_key_provider.rb +1 -1
  26. data/lib/active_record/encryption/encryptable_record.rb +2 -4
  27. data/lib/active_record/encryption/encrypted_attribute_type.rb +2 -2
  28. data/lib/active_record/encryption/encryptor.rb +7 -7
  29. data/lib/active_record/encryption/envelope_encryption_key_provider.rb +3 -3
  30. data/lib/active_record/encryption/extended_deterministic_queries.rb +4 -4
  31. data/lib/active_record/encryption/scheme.rb +1 -1
  32. data/lib/active_record/enum.rb +1 -1
  33. data/lib/active_record/fixtures.rb +4 -4
  34. data/lib/active_record/gem_version.rb +3 -3
  35. data/lib/active_record/locking/pessimistic.rb +3 -3
  36. data/lib/active_record/log_subscriber.rb +10 -5
  37. data/lib/active_record/middleware/database_selector.rb +13 -6
  38. data/lib/active_record/middleware/shard_selector.rb +4 -4
  39. data/lib/active_record/migration/command_recorder.rb +3 -3
  40. data/lib/active_record/migration/compatibility.rb +7 -26
  41. data/lib/active_record/migration.rb +5 -4
  42. data/lib/active_record/model_schema.rb +1 -1
  43. data/lib/active_record/persistence.rb +9 -8
  44. data/lib/active_record/querying.rb +1 -1
  45. data/lib/active_record/railtie.rb +14 -0
  46. data/lib/active_record/railties/databases.rake +1 -1
  47. data/lib/active_record/reflection.rb +6 -0
  48. data/lib/active_record/relation/batches.rb +3 -3
  49. data/lib/active_record/relation/query_methods.rb +8 -1
  50. data/lib/active_record/relation.rb +6 -6
  51. data/lib/active_record/sanitization.rb +6 -5
  52. data/lib/active_record/scoping/default.rb +1 -5
  53. data/lib/active_record/serialization.rb +5 -0
  54. data/lib/active_record/signed_id.rb +1 -1
  55. data/lib/active_record/tasks/database_tasks.rb +26 -21
  56. data/lib/active_record/tasks/postgresql_database_tasks.rb +1 -2
  57. data/lib/active_record/test_fixtures.rb +3 -0
  58. data/lib/active_record/translation.rb +1 -1
  59. data/lib/active_record/validations/associated.rb +3 -3
  60. data/lib/active_record/validations/presence.rb +2 -2
  61. data/lib/active_record/validations/uniqueness.rb +3 -3
  62. data/lib/active_record/version.rb +1 -1
  63. metadata +10 -10
@@ -92,16 +92,17 @@ module ActiveRecord
92
92
  end
93
93
 
94
94
  # Sanitizes a +string+ so that it is safe to use within an SQL
95
- # LIKE statement. This method uses +escape_character+ to escape all occurrences of "\", "_" and "%".
95
+ # LIKE statement. This method uses +escape_character+ to escape all
96
+ # occurrences of itself, "_" and "%".
96
97
  #
97
- # sanitize_sql_like("100%")
98
- # # => "100\\%"
98
+ # sanitize_sql_like("100% true!")
99
+ # # => "100\\% true!"
99
100
  #
100
101
  # sanitize_sql_like("snake_cased_string")
101
102
  # # => "snake\\_cased\\_string"
102
103
  #
103
- # sanitize_sql_like("100%", "!")
104
- # # => "100!%"
104
+ # sanitize_sql_like("100% true!", "!")
105
+ # # => "100!% true!!"
105
106
  #
106
107
  # sanitize_sql_like("snake_cased_string", "!")
107
108
  # # => "snake!_cased!_string"
@@ -48,10 +48,6 @@ module ActiveRecord
48
48
  super || default_scopes.any? || respond_to?(:default_scope)
49
49
  end
50
50
 
51
- def before_remove_const # :nodoc:
52
- self.current_scope = nil
53
- end
54
-
55
51
  # Checks if the model has any default scopes. If all_queries
56
52
  # is set to true, the method will check if there are any
57
53
  # default_scopes for the model where +all_queries+ is true.
@@ -83,7 +79,7 @@ module ActiveRecord
83
79
  # <tt>all_queries: true</tt>:
84
80
  #
85
81
  # class Article < ActiveRecord::Base
86
- # default_scope { where(blog_id: 1) }, all_queries: true
82
+ # default_scope -> { where(blog_id: 1) }, all_queries: true
87
83
  # end
88
84
  #
89
85
  # Applying a default scope to all queries will ensure that records
@@ -20,5 +20,10 @@ module ActiveRecord # :nodoc:
20
20
 
21
21
  super(options)
22
22
  end
23
+
24
+ private
25
+ def attribute_names_for_serialization
26
+ attribute_names
27
+ end
23
28
  end
24
29
  end
@@ -47,7 +47,7 @@ module ActiveRecord
47
47
  end
48
48
  end
49
49
 
50
- # Works like +find_signed+, but will raise an +ActiveSupport::MessageVerifier::InvalidSignature+
50
+ # Works like find_signed, but will raise an +ActiveSupport::MessageVerifier::InvalidSignature+
51
51
  # exception if the +signed_id+ has either expired, has a purpose mismatch, is for another record,
52
52
  # or has been tampered with. It will also raise an +ActiveRecord::RecordNotFound+ exception if
53
53
  # the valid signed id can't find a record.
@@ -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)
@@ -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
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.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: 2022-04-26 00:00:00.000000000 Z
11
+ date: 2022-05-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.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.0.2.4
26
+ version: 7.0.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.0.2.4
33
+ version: 7.0.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.0.2.4
40
+ version: 7.0.3
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.3/activerecord/CHANGELOG.md
438
+ documentation_uri: https://api.rubyonrails.org/v7.0.3/
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.3/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.7
460
460
  signing_key:
461
461
  specification_version: 4
462
462
  summary: Object-relational mapper framework (part of Rails).