activerecord 7.1.5.1 → 8.0.2
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 +369 -2484
- data/README.rdoc +15 -15
- data/examples/performance.rb +2 -2
- data/lib/active_record/association_relation.rb +2 -1
- data/lib/active_record/associations/alias_tracker.rb +31 -23
- data/lib/active_record/associations/association.rb +43 -12
- data/lib/active_record/associations/belongs_to_association.rb +21 -8
- data/lib/active_record/associations/belongs_to_polymorphic_association.rb +3 -2
- data/lib/active_record/associations/builder/association.rb +7 -6
- data/lib/active_record/associations/builder/belongs_to.rb +1 -0
- data/lib/active_record/associations/builder/has_and_belongs_to_many.rb +2 -2
- data/lib/active_record/associations/builder/has_many.rb +3 -4
- data/lib/active_record/associations/builder/has_one.rb +3 -4
- data/lib/active_record/associations/collection_association.rb +17 -9
- data/lib/active_record/associations/collection_proxy.rb +14 -1
- data/lib/active_record/associations/disable_joins_association_scope.rb +1 -1
- data/lib/active_record/associations/errors.rb +265 -0
- data/lib/active_record/associations/has_many_association.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 +1 -1
- data/lib/active_record/associations/nested_error.rb +47 -0
- data/lib/active_record/associations/preloader/association.rb +4 -3
- data/lib/active_record/associations/preloader/branch.rb +7 -1
- data/lib/active_record/associations/preloader/through_association.rb +1 -3
- data/lib/active_record/associations/singular_association.rb +14 -3
- data/lib/active_record/associations/through_association.rb +1 -1
- data/lib/active_record/associations.rb +92 -295
- data/lib/active_record/asynchronous_queries_tracker.rb +28 -24
- data/lib/active_record/attribute_assignment.rb +0 -2
- data/lib/active_record/attribute_methods/composite_primary_key.rb +84 -0
- data/lib/active_record/attribute_methods/primary_key.rb +25 -61
- data/lib/active_record/attribute_methods/read.rb +1 -13
- data/lib/active_record/attribute_methods/serialization.rb +4 -24
- data/lib/active_record/attribute_methods/time_zone_conversion.rb +9 -18
- data/lib/active_record/attribute_methods.rb +71 -75
- data/lib/active_record/attributes.rb +63 -49
- data/lib/active_record/autosave_association.rb +92 -57
- data/lib/active_record/base.rb +2 -3
- data/lib/active_record/callbacks.rb +1 -1
- data/lib/active_record/connection_adapters/abstract/connection_handler.rb +48 -122
- data/lib/active_record/connection_adapters/abstract/connection_pool/queue.rb +0 -1
- data/lib/active_record/connection_adapters/abstract/connection_pool/reaper.rb +1 -1
- data/lib/active_record/connection_adapters/abstract/connection_pool.rb +286 -77
- data/lib/active_record/connection_adapters/abstract/database_statements.rb +119 -55
- data/lib/active_record/connection_adapters/abstract/query_cache.rb +197 -76
- data/lib/active_record/connection_adapters/abstract/quoting.rb +66 -92
- data/lib/active_record/connection_adapters/abstract/schema_creation.rb +4 -5
- data/lib/active_record/connection_adapters/abstract/schema_definitions.rb +12 -3
- data/lib/active_record/connection_adapters/abstract/schema_statements.rb +48 -12
- data/lib/active_record/connection_adapters/abstract/transaction.rb +140 -67
- data/lib/active_record/connection_adapters/abstract_adapter.rb +85 -90
- data/lib/active_record/connection_adapters/abstract_mysql_adapter.rb +71 -52
- data/lib/active_record/connection_adapters/mysql/database_statements.rb +9 -1
- data/lib/active_record/connection_adapters/mysql/quoting.rb +50 -57
- data/lib/active_record/connection_adapters/mysql/schema_definitions.rb +2 -8
- data/lib/active_record/connection_adapters/mysql/schema_statements.rb +56 -45
- data/lib/active_record/connection_adapters/mysql2/database_statements.rb +92 -101
- data/lib/active_record/connection_adapters/mysql2_adapter.rb +13 -31
- data/lib/active_record/connection_adapters/pool_config.rb +14 -13
- data/lib/active_record/connection_adapters/postgresql/database_statements.rb +86 -41
- data/lib/active_record/connection_adapters/postgresql/oid/array.rb +1 -1
- data/lib/active_record/connection_adapters/postgresql/oid/interval.rb +1 -1
- data/lib/active_record/connection_adapters/postgresql/oid/point.rb +10 -0
- data/lib/active_record/connection_adapters/postgresql/oid/uuid.rb +14 -4
- data/lib/active_record/connection_adapters/postgresql/quoting.rb +58 -58
- data/lib/active_record/connection_adapters/postgresql/referential_integrity.rb +2 -4
- data/lib/active_record/connection_adapters/postgresql/schema_creation.rb +1 -11
- data/lib/active_record/connection_adapters/postgresql/schema_definitions.rb +36 -20
- data/lib/active_record/connection_adapters/postgresql/schema_dumper.rb +3 -2
- data/lib/active_record/connection_adapters/postgresql/schema_statements.rb +75 -28
- data/lib/active_record/connection_adapters/postgresql_adapter.rb +73 -113
- data/lib/active_record/connection_adapters/schema_cache.rb +124 -131
- data/lib/active_record/connection_adapters/sqlite3/column.rb +14 -1
- data/lib/active_record/connection_adapters/sqlite3/database_statements.rb +81 -97
- data/lib/active_record/connection_adapters/sqlite3/quoting.rb +57 -46
- data/lib/active_record/connection_adapters/sqlite3/schema_creation.rb +16 -0
- data/lib/active_record/connection_adapters/sqlite3/schema_definitions.rb +13 -0
- data/lib/active_record/connection_adapters/sqlite3/schema_dumper.rb +29 -0
- data/lib/active_record/connection_adapters/sqlite3/schema_statements.rb +35 -3
- data/lib/active_record/connection_adapters/sqlite3_adapter.rb +183 -87
- data/lib/active_record/connection_adapters/statement_pool.rb +4 -2
- data/lib/active_record/connection_adapters/trilogy/database_statements.rb +39 -69
- data/lib/active_record/connection_adapters/trilogy_adapter.rb +19 -65
- data/lib/active_record/connection_adapters.rb +65 -0
- data/lib/active_record/connection_handling.rb +74 -37
- data/lib/active_record/core.rb +132 -51
- data/lib/active_record/counter_cache.rb +19 -10
- data/lib/active_record/database_configurations/connection_url_resolver.rb +9 -2
- data/lib/active_record/database_configurations/database_config.rb +23 -4
- data/lib/active_record/database_configurations/hash_config.rb +46 -34
- data/lib/active_record/database_configurations/url_config.rb +20 -1
- data/lib/active_record/database_configurations.rb +1 -1
- data/lib/active_record/delegated_type.rb +41 -17
- data/lib/active_record/dynamic_matchers.rb +2 -2
- data/lib/active_record/encryption/config.rb +3 -1
- data/lib/active_record/encryption/encryptable_record.rb +7 -7
- data/lib/active_record/encryption/encrypted_attribute_type.rb +33 -4
- data/lib/active_record/encryption/encryptor.rb +28 -6
- 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/message_pack_message_serializer.rb +76 -0
- data/lib/active_record/encryption/message_serializer.rb +4 -0
- data/lib/active_record/encryption/null_encryptor.rb +4 -0
- data/lib/active_record/encryption/read_only_null_encryptor.rb +4 -0
- data/lib/active_record/encryption/scheme.rb +8 -1
- data/lib/active_record/enum.rb +20 -16
- data/lib/active_record/errors.rb +54 -20
- data/lib/active_record/explain.rb +13 -24
- data/lib/active_record/fixtures.rb +37 -33
- data/lib/active_record/future_result.rb +21 -13
- data/lib/active_record/gem_version.rb +4 -4
- data/lib/active_record/inheritance.rb +4 -2
- data/lib/active_record/insert_all.rb +19 -16
- data/lib/active_record/integration.rb +4 -1
- data/lib/active_record/internal_metadata.rb +48 -34
- data/lib/active_record/locking/optimistic.rb +8 -7
- data/lib/active_record/log_subscriber.rb +5 -32
- data/lib/active_record/message_pack.rb +1 -1
- data/lib/active_record/migration/command_recorder.rb +33 -14
- data/lib/active_record/migration/compatibility.rb +8 -3
- data/lib/active_record/migration/default_strategy.rb +4 -5
- data/lib/active_record/migration/pending_migration_connection.rb +2 -2
- data/lib/active_record/migration.rb +104 -98
- data/lib/active_record/model_schema.rb +32 -70
- data/lib/active_record/nested_attributes.rb +15 -9
- data/lib/active_record/normalization.rb +3 -7
- data/lib/active_record/persistence.rb +127 -451
- data/lib/active_record/query_cache.rb +19 -8
- data/lib/active_record/query_logs.rb +104 -37
- data/lib/active_record/query_logs_formatter.rb +17 -28
- data/lib/active_record/querying.rb +24 -12
- data/lib/active_record/railtie.rb +26 -68
- data/lib/active_record/railties/controller_runtime.rb +13 -4
- data/lib/active_record/railties/databases.rake +43 -61
- data/lib/active_record/reflection.rb +112 -53
- data/lib/active_record/relation/batches/batch_enumerator.rb +19 -5
- data/lib/active_record/relation/batches.rb +138 -72
- data/lib/active_record/relation/calculations.rb +122 -82
- data/lib/active_record/relation/delegation.rb +30 -22
- data/lib/active_record/relation/finder_methods.rb +32 -18
- data/lib/active_record/relation/merger.rb +12 -14
- data/lib/active_record/relation/predicate_builder/array_handler.rb +2 -2
- data/lib/active_record/relation/predicate_builder/association_query_value.rb +10 -2
- 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 +16 -3
- data/lib/active_record/relation/query_attribute.rb +1 -1
- data/lib/active_record/relation/query_methods.rb +317 -101
- data/lib/active_record/relation/spawn_methods.rb +3 -19
- data/lib/active_record/relation/where_clause.rb +7 -19
- data/lib/active_record/relation.rb +561 -119
- data/lib/active_record/result.rb +95 -46
- data/lib/active_record/runtime_registry.rb +39 -0
- data/lib/active_record/sanitization.rb +31 -25
- data/lib/active_record/schema.rb +8 -6
- data/lib/active_record/schema_dumper.rb +53 -20
- data/lib/active_record/schema_migration.rb +31 -14
- data/lib/active_record/scoping/named.rb +6 -2
- data/lib/active_record/signed_id.rb +24 -4
- data/lib/active_record/statement_cache.rb +19 -19
- data/lib/active_record/store.rb +7 -3
- data/lib/active_record/table_metadata.rb +2 -13
- data/lib/active_record/tasks/database_tasks.rb +87 -58
- data/lib/active_record/tasks/mysql_database_tasks.rb +1 -3
- data/lib/active_record/tasks/postgresql_database_tasks.rb +1 -1
- data/lib/active_record/tasks/sqlite_database_tasks.rb +4 -3
- data/lib/active_record/test_fixtures.rb +98 -89
- data/lib/active_record/testing/query_assertions.rb +121 -0
- data/lib/active_record/timestamp.rb +2 -2
- data/lib/active_record/token_for.rb +22 -12
- data/lib/active_record/touch_later.rb +1 -1
- data/lib/active_record/transaction.rb +132 -0
- data/lib/active_record/transactions.rb +72 -17
- data/lib/active_record/translation.rb +0 -2
- data/lib/active_record/type/serialized.rb +1 -3
- data/lib/active_record/type_caster/connection.rb +4 -4
- data/lib/active_record/validations/associated.rb +9 -3
- data/lib/active_record/validations/uniqueness.rb +23 -18
- data/lib/active_record/validations.rb +4 -1
- data/lib/active_record.rb +138 -57
- data/lib/arel/alias_predication.rb +1 -1
- data/lib/arel/collectors/bind.rb +4 -2
- data/lib/arel/collectors/composite.rb +7 -0
- data/lib/arel/collectors/sql_string.rb +2 -2
- data/lib/arel/collectors/substitute_binds.rb +3 -3
- data/lib/arel/nodes/binary.rb +1 -7
- data/lib/arel/nodes/bound_sql_literal.rb +9 -5
- data/lib/arel/nodes/{and.rb → nary.rb} +5 -2
- data/lib/arel/nodes/node.rb +5 -4
- data/lib/arel/nodes/sql_literal.rb +8 -1
- data/lib/arel/nodes.rb +2 -2
- data/lib/arel/predications.rb +1 -1
- data/lib/arel/select_manager.rb +1 -1
- data/lib/arel/table.rb +3 -7
- data/lib/arel/tree_manager.rb +3 -2
- data/lib/arel/update_manager.rb +2 -1
- data/lib/arel/visitors/dot.rb +1 -0
- data/lib/arel/visitors/mysql.rb +9 -4
- data/lib/arel/visitors/postgresql.rb +1 -12
- data/lib/arel/visitors/sqlite.rb +25 -0
- data/lib/arel/visitors/to_sql.rb +29 -16
- data/lib/arel.rb +7 -3
- data/lib/rails/generators/active_record/migration/templates/create_table_migration.rb.tt +4 -1
- metadata +18 -16
- data/lib/active_record/relation/record_fetch_warning.rb +0 -49
@@ -13,17 +13,13 @@ module ActiveRecord
|
|
13
13
|
class NullInternalMetadata # :nodoc:
|
14
14
|
end
|
15
15
|
|
16
|
-
attr_reader :
|
16
|
+
attr_reader :arel_table
|
17
17
|
|
18
|
-
def initialize(
|
19
|
-
@
|
18
|
+
def initialize(pool)
|
19
|
+
@pool = pool
|
20
20
|
@arel_table = Arel::Table.new(table_name)
|
21
21
|
end
|
22
22
|
|
23
|
-
def enabled?
|
24
|
-
connection.use_metadata_table?
|
25
|
-
end
|
26
|
-
|
27
23
|
def primary_key
|
28
24
|
"key"
|
29
25
|
end
|
@@ -36,50 +32,66 @@ module ActiveRecord
|
|
36
32
|
"#{ActiveRecord::Base.table_name_prefix}#{ActiveRecord::Base.internal_metadata_table_name}#{ActiveRecord::Base.table_name_suffix}"
|
37
33
|
end
|
38
34
|
|
35
|
+
def enabled?
|
36
|
+
@pool.db_config.use_metadata_table?
|
37
|
+
end
|
38
|
+
|
39
39
|
def []=(key, value)
|
40
40
|
return unless enabled?
|
41
41
|
|
42
|
-
|
42
|
+
@pool.with_connection do |connection|
|
43
|
+
update_or_create_entry(connection, key, value)
|
44
|
+
end
|
43
45
|
end
|
44
46
|
|
45
47
|
def [](key)
|
46
48
|
return unless enabled?
|
47
49
|
|
48
|
-
|
49
|
-
entry
|
50
|
+
@pool.with_connection do |connection|
|
51
|
+
if entry = select_entry(connection, key)
|
52
|
+
entry[value_key]
|
53
|
+
end
|
50
54
|
end
|
51
55
|
end
|
52
56
|
|
53
57
|
def delete_all_entries
|
54
58
|
dm = Arel::DeleteManager.new(arel_table)
|
55
59
|
|
56
|
-
|
60
|
+
@pool.with_connection do |connection|
|
61
|
+
connection.delete(dm, "#{self.class} Destroy")
|
62
|
+
end
|
57
63
|
end
|
58
64
|
|
59
65
|
def count
|
60
66
|
sm = Arel::SelectManager.new(arel_table)
|
61
67
|
sm.project(*Arel::Nodes::Count.new([Arel.star]))
|
62
68
|
|
63
|
-
|
69
|
+
@pool.with_connection do |connection|
|
70
|
+
connection.select_values(sm, "#{self.class} Count").first
|
71
|
+
end
|
64
72
|
end
|
65
73
|
|
66
74
|
def create_table_and_set_flags(environment, schema_sha1 = nil)
|
67
75
|
return unless enabled?
|
68
76
|
|
69
|
-
|
70
|
-
|
71
|
-
|
77
|
+
@pool.with_connection do |connection|
|
78
|
+
create_table
|
79
|
+
update_or_create_entry(connection, :environment, environment)
|
80
|
+
update_or_create_entry(connection, :schema_sha1, schema_sha1) if schema_sha1
|
81
|
+
end
|
72
82
|
end
|
73
83
|
|
74
84
|
# Creates an internal metadata table with columns +key+ and +value+
|
75
85
|
def create_table
|
76
86
|
return unless enabled?
|
77
87
|
|
78
|
-
|
79
|
-
connection.
|
80
|
-
|
81
|
-
|
82
|
-
|
88
|
+
@pool.with_connection do |connection|
|
89
|
+
unless connection.table_exists?(table_name)
|
90
|
+
connection.create_table(table_name, id: false) do |t|
|
91
|
+
t.string :key, **connection.internal_string_options_for_primary_key
|
92
|
+
t.string :value
|
93
|
+
t.timestamps
|
94
|
+
end
|
83
95
|
end
|
84
96
|
end
|
85
97
|
end
|
@@ -87,49 +99,51 @@ module ActiveRecord
|
|
87
99
|
def drop_table
|
88
100
|
return unless enabled?
|
89
101
|
|
90
|
-
|
102
|
+
@pool.with_connection do |connection|
|
103
|
+
connection.drop_table table_name, if_exists: true
|
104
|
+
end
|
91
105
|
end
|
92
106
|
|
93
107
|
def table_exists?
|
94
|
-
|
108
|
+
@pool.schema_cache.data_source_exists?(table_name)
|
95
109
|
end
|
96
110
|
|
97
111
|
private
|
98
|
-
def update_or_create_entry(key, value)
|
99
|
-
entry = select_entry(key)
|
112
|
+
def update_or_create_entry(connection, key, value)
|
113
|
+
entry = select_entry(connection, key)
|
100
114
|
|
101
115
|
if entry
|
102
116
|
if entry[value_key] != value
|
103
|
-
update_entry(key, value)
|
117
|
+
update_entry(connection, key, value)
|
104
118
|
else
|
105
119
|
entry[value_key]
|
106
120
|
end
|
107
121
|
else
|
108
|
-
create_entry(key, value)
|
122
|
+
create_entry(connection, key, value)
|
109
123
|
end
|
110
124
|
end
|
111
125
|
|
112
|
-
def current_time
|
126
|
+
def current_time(connection)
|
113
127
|
connection.default_timezone == :utc ? Time.now.utc : Time.now
|
114
128
|
end
|
115
129
|
|
116
|
-
def create_entry(key, value)
|
130
|
+
def create_entry(connection, key, value)
|
117
131
|
im = Arel::InsertManager.new(arel_table)
|
118
132
|
im.insert [
|
119
133
|
[arel_table[primary_key], key],
|
120
134
|
[arel_table[value_key], value],
|
121
|
-
[arel_table[:created_at], current_time],
|
122
|
-
[arel_table[:updated_at], current_time]
|
135
|
+
[arel_table[:created_at], current_time(connection)],
|
136
|
+
[arel_table[:updated_at], current_time(connection)]
|
123
137
|
]
|
124
138
|
|
125
139
|
connection.insert(im, "#{self.class} Create", primary_key, key)
|
126
140
|
end
|
127
141
|
|
128
|
-
def update_entry(key, new_value)
|
142
|
+
def update_entry(connection, key, new_value)
|
129
143
|
um = Arel::UpdateManager.new(arel_table)
|
130
144
|
um.set [
|
131
145
|
[arel_table[value_key], new_value],
|
132
|
-
[arel_table[:updated_at], current_time]
|
146
|
+
[arel_table[:updated_at], current_time(connection)]
|
133
147
|
]
|
134
148
|
|
135
149
|
um.where(arel_table[primary_key].eq(key))
|
@@ -137,9 +151,9 @@ module ActiveRecord
|
|
137
151
|
connection.update(um, "#{self.class} Update")
|
138
152
|
end
|
139
153
|
|
140
|
-
def select_entry(key)
|
154
|
+
def select_entry(connection, key)
|
141
155
|
sm = Arel::SelectManager.new(arel_table)
|
142
|
-
sm.project(Arel::Nodes::SqlLiteral.new("*"))
|
156
|
+
sm.project(Arel::Nodes::SqlLiteral.new("*", retryable: true))
|
143
157
|
sm.where(arel_table[primary_key].eq(Arel::Nodes::BindParam.new(key)))
|
144
158
|
sm.order(arel_table[primary_key].asc)
|
145
159
|
sm.limit = 1
|
@@ -9,7 +9,7 @@ module ActiveRecord
|
|
9
9
|
# it was opened, an ActiveRecord::StaleObjectError exception is thrown if that has occurred
|
10
10
|
# and the update is ignored.
|
11
11
|
#
|
12
|
-
# Check out
|
12
|
+
# Check out ActiveRecord::Locking::Pessimistic for an alternative.
|
13
13
|
#
|
14
14
|
# == Usage
|
15
15
|
#
|
@@ -182,14 +182,15 @@ module ActiveRecord
|
|
182
182
|
super
|
183
183
|
end
|
184
184
|
|
185
|
-
|
186
|
-
|
187
|
-
|
185
|
+
private
|
186
|
+
def hook_attribute_type(name, cast_type)
|
187
|
+
if lock_optimistically && name == locking_column
|
188
|
+
cast_type = LockingType.new(cast_type)
|
189
|
+
end
|
190
|
+
|
191
|
+
super
|
188
192
|
end
|
189
|
-
super
|
190
|
-
end
|
191
193
|
|
192
|
-
private
|
193
194
|
def inherited(base)
|
194
195
|
super
|
195
196
|
base.class_eval do
|
@@ -6,27 +6,6 @@ module ActiveRecord
|
|
6
6
|
|
7
7
|
class_attribute :backtrace_cleaner, default: ActiveSupport::BacktraceCleaner.new
|
8
8
|
|
9
|
-
def self.runtime=(value)
|
10
|
-
ActiveRecord.deprecator.warn(<<-MSG.squish)
|
11
|
-
ActiveRecord::LogSubscriber.runtime= is deprecated and will be removed in Rails 7.2.
|
12
|
-
MSG
|
13
|
-
ActiveRecord::RuntimeRegistry.sql_runtime = value
|
14
|
-
end
|
15
|
-
|
16
|
-
def self.runtime
|
17
|
-
ActiveRecord.deprecator.warn(<<-MSG.squish)
|
18
|
-
ActiveRecord::LogSubscriber.runtime is deprecated and will be removed in Rails 7.2.
|
19
|
-
MSG
|
20
|
-
ActiveRecord::RuntimeRegistry.sql_runtime
|
21
|
-
end
|
22
|
-
|
23
|
-
def self.reset_runtime
|
24
|
-
ActiveRecord.deprecator.warn(<<-MSG.squish)
|
25
|
-
ActiveRecord::LogSubscriber.reset_runtime is deprecated and will be removed in Rails 7.2.
|
26
|
-
MSG
|
27
|
-
ActiveRecord::RuntimeRegistry.reset
|
28
|
-
end
|
29
|
-
|
30
9
|
def strict_loading_violation(event)
|
31
10
|
debug do
|
32
11
|
owner = event.payload[:owner]
|
@@ -147,18 +126,12 @@ module ActiveRecord
|
|
147
126
|
end
|
148
127
|
end
|
149
128
|
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
return frame if frame
|
155
|
-
end
|
156
|
-
nil
|
157
|
-
end
|
158
|
-
else
|
159
|
-
def query_source_location
|
160
|
-
backtrace_cleaner.clean(caller(1).lazy).first
|
129
|
+
def query_source_location
|
130
|
+
Thread.each_caller_location do |location|
|
131
|
+
frame = backtrace_cleaner.clean_frame(location)
|
132
|
+
return frame if frame
|
161
133
|
end
|
134
|
+
nil
|
162
135
|
end
|
163
136
|
|
164
137
|
def filter(name, value)
|
@@ -79,7 +79,7 @@ module ActiveRecord
|
|
79
79
|
end
|
80
80
|
|
81
81
|
def add_cached_associations(record, entry)
|
82
|
-
record.class.
|
82
|
+
record.class.normalized_reflections.each_value do |reflection|
|
83
83
|
if record.association_cached?(reflection.name) && record.association(reflection.name).loaded?
|
84
84
|
entry << reflection.name << encode(record.association(reflection.name).target)
|
85
85
|
end
|
@@ -22,10 +22,12 @@ module ActiveRecord
|
|
22
22
|
# * change_table_comment (must supply a +:from+ and +:to+ option)
|
23
23
|
# * create_enum
|
24
24
|
# * create_join_table
|
25
|
+
# * create_virtual_table
|
25
26
|
# * create_table
|
26
27
|
# * disable_extension
|
27
28
|
# * drop_enum (must supply a list of values)
|
28
29
|
# * drop_join_table
|
30
|
+
# * drop_virtual_table (must supply options)
|
29
31
|
# * drop_table (must supply a block)
|
30
32
|
# * enable_extension
|
31
33
|
# * remove_column (must supply a type)
|
@@ -38,7 +40,7 @@ module ActiveRecord
|
|
38
40
|
# * remove_reference
|
39
41
|
# * remove_timestamps
|
40
42
|
# * rename_column
|
41
|
-
# * rename_enum
|
43
|
+
# * rename_enum
|
42
44
|
# * rename_enum_value (must supply a +:from+ and +:to+ option)
|
43
45
|
# * rename_index
|
44
46
|
# * rename_table
|
@@ -55,6 +57,8 @@ module ActiveRecord
|
|
55
57
|
:add_exclusion_constraint, :remove_exclusion_constraint,
|
56
58
|
:add_unique_constraint, :remove_unique_constraint,
|
57
59
|
:create_enum, :drop_enum, :rename_enum, :add_enum_value, :rename_enum_value,
|
60
|
+
:create_schema, :drop_schema,
|
61
|
+
:create_virtual_table, :drop_virtual_table
|
58
62
|
]
|
59
63
|
include JoinTable
|
60
64
|
|
@@ -163,7 +167,9 @@ module ActiveRecord
|
|
163
167
|
add_exclusion_constraint: :remove_exclusion_constraint,
|
164
168
|
add_unique_constraint: :remove_unique_constraint,
|
165
169
|
enable_extension: :disable_extension,
|
166
|
-
create_enum: :drop_enum
|
170
|
+
create_enum: :drop_enum,
|
171
|
+
create_schema: :drop_schema,
|
172
|
+
create_virtual_table: :drop_virtual_table
|
167
173
|
}.each do |cmd, inv|
|
168
174
|
[[inv, cmd], [cmd, inv]].uniq.each do |method, inverse|
|
169
175
|
class_eval <<-EOV, __FILE__, __LINE__ + 1
|
@@ -196,13 +202,20 @@ module ActiveRecord
|
|
196
202
|
end
|
197
203
|
|
198
204
|
def invert_drop_table(args, &block)
|
199
|
-
|
200
|
-
|
205
|
+
options = args.extract_options!
|
206
|
+
options.delete(:if_exists)
|
207
|
+
|
208
|
+
if args.size > 1
|
209
|
+
raise ActiveRecord::IrreversibleMigration, "To avoid mistakes, drop_table is only reversible if given a single table name."
|
201
210
|
end
|
202
|
-
|
211
|
+
|
212
|
+
if args.size == 1 && options == {} && block == nil
|
203
213
|
raise ActiveRecord::IrreversibleMigration, "To avoid mistakes, drop_table is only reversible if given options or a block (can be empty)."
|
204
214
|
end
|
205
|
-
|
215
|
+
|
216
|
+
args << options unless options.empty?
|
217
|
+
|
218
|
+
super(args, &block)
|
206
219
|
end
|
207
220
|
|
208
221
|
def invert_rename_table(args)
|
@@ -353,13 +366,13 @@ module ActiveRecord
|
|
353
366
|
end
|
354
367
|
|
355
368
|
def invert_rename_enum(args)
|
356
|
-
name,
|
369
|
+
name, new_name, = args
|
357
370
|
|
358
|
-
|
359
|
-
|
371
|
+
if new_name.is_a?(Hash) && new_name.key?(:to)
|
372
|
+
new_name = new_name[:to]
|
360
373
|
end
|
361
374
|
|
362
|
-
[:rename_enum, [
|
375
|
+
[:rename_enum, [new_name, name]]
|
363
376
|
end
|
364
377
|
|
365
378
|
def invert_rename_enum_value(args)
|
@@ -369,7 +382,14 @@ module ActiveRecord
|
|
369
382
|
raise ActiveRecord::IrreversibleMigration, "rename_enum_value is only reversible if given a :from and :to option."
|
370
383
|
end
|
371
384
|
|
372
|
-
[:
|
385
|
+
options[:to], options[:from] = options[:from], options[:to]
|
386
|
+
[:rename_enum_value, [type_name, options]]
|
387
|
+
end
|
388
|
+
|
389
|
+
def invert_drop_virtual_table(args)
|
390
|
+
_enum, values = args.dup.tap(&:extract_options!)
|
391
|
+
raise ActiveRecord::IrreversibleMigration, "drop_virtual_table is only reversible if given options." unless values
|
392
|
+
super
|
373
393
|
end
|
374
394
|
|
375
395
|
def respond_to_missing?(method, _)
|
@@ -377,14 +397,13 @@ module ActiveRecord
|
|
377
397
|
end
|
378
398
|
|
379
399
|
# Forwards any missing method call to the \target.
|
380
|
-
def method_missing(method,
|
400
|
+
def method_missing(method, ...)
|
381
401
|
if delegate.respond_to?(method)
|
382
|
-
delegate.public_send(method,
|
402
|
+
delegate.public_send(method, ...)
|
383
403
|
else
|
384
404
|
super
|
385
405
|
end
|
386
406
|
end
|
387
|
-
ruby2_keywords(:method_missing)
|
388
407
|
end
|
389
408
|
end
|
390
409
|
end
|
@@ -21,8 +21,7 @@ module ActiveRecord
|
|
21
21
|
# New migration functionality that will never be backward compatible should be added directly to `ActiveRecord::Migration`.
|
22
22
|
#
|
23
23
|
# There are classes for each prior Rails version. Each class descends from the *next* Rails version, so:
|
24
|
-
# 7.0 < 7.1
|
25
|
-
# 5.2 < 6.0 < 6.1 < 7.0 < 7.1
|
24
|
+
# 5.2 < 6.0 < 6.1 < 7.0 < 7.1 < 7.2 < 8.0
|
26
25
|
#
|
27
26
|
# If you are introducing new migration functionality that should only apply from Rails 7 onward, then you should
|
28
27
|
# find the class that immediately precedes it (6.1), and override the relevant migration methods to undo your changes.
|
@@ -30,7 +29,13 @@ module ActiveRecord
|
|
30
29
|
# For example, Rails 6 added a default value for the `precision` option on datetime columns. So in this file, the `V5_2`
|
31
30
|
# class sets the value of `precision` to `nil` if it's not explicitly provided. This way, the default value will not apply
|
32
31
|
# for migrations written for 5.2, but will for migrations written for 6.0.
|
33
|
-
|
32
|
+
V8_0 = Current
|
33
|
+
|
34
|
+
class V7_2 < V8_0
|
35
|
+
end
|
36
|
+
|
37
|
+
class V7_1 < V7_2
|
38
|
+
end
|
34
39
|
|
35
40
|
class V7_0 < V7_1
|
36
41
|
module LegacyIndexName
|
@@ -6,13 +6,12 @@ module ActiveRecord
|
|
6
6
|
# to the connection adapter.
|
7
7
|
class DefaultStrategy < ExecutionStrategy # :nodoc:
|
8
8
|
private
|
9
|
-
def method_missing(method,
|
10
|
-
connection.send(method,
|
9
|
+
def method_missing(method, ...)
|
10
|
+
connection.send(method, ...)
|
11
11
|
end
|
12
|
-
ruby2_keywords(:method_missing)
|
13
12
|
|
14
|
-
def respond_to_missing?(method,
|
15
|
-
connection.respond_to?(method) || super
|
13
|
+
def respond_to_missing?(method, include_private = false)
|
14
|
+
connection.respond_to?(method, include_private) || super
|
16
15
|
end
|
17
16
|
|
18
17
|
def connection
|
@@ -2,10 +2,10 @@
|
|
2
2
|
|
3
3
|
module ActiveRecord
|
4
4
|
class PendingMigrationConnection # :nodoc:
|
5
|
-
def self.
|
5
|
+
def self.with_temporary_pool(db_config, &block)
|
6
6
|
pool = ActiveRecord::Base.connection_handler.establish_connection(db_config, owner_name: self)
|
7
7
|
|
8
|
-
yield pool
|
8
|
+
yield pool
|
9
9
|
ensure
|
10
10
|
ActiveRecord::Base.connection_handler.remove_connection_pool(self.name)
|
11
11
|
end
|