activerecord 8.0.2 → 8.0.5.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 +288 -1
- data/README.rdoc +1 -1
- data/lib/active_record/associations/belongs_to_association.rb +11 -1
- data/lib/active_record/associations/collection_association.rb +3 -3
- data/lib/active_record/associations/join_dependency.rb +2 -2
- data/lib/active_record/associations/preloader/batch.rb +7 -1
- data/lib/active_record/attribute_methods/query.rb +34 -0
- data/lib/active_record/attribute_methods/serialization.rb +1 -1
- data/lib/active_record/attribute_methods.rb +1 -1
- data/lib/active_record/attributes.rb +35 -24
- data/lib/active_record/autosave_association.rb +2 -2
- data/lib/active_record/base.rb +2 -2
- data/lib/active_record/connection_adapters/abstract/connection_handler.rb +1 -1
- data/lib/active_record/connection_adapters/abstract/connection_pool.rb +10 -6
- data/lib/active_record/connection_adapters/abstract/database_statements.rb +1 -1
- data/lib/active_record/connection_adapters/abstract/query_cache.rb +17 -6
- data/lib/active_record/connection_adapters/abstract/schema_statements.rb +7 -4
- data/lib/active_record/connection_adapters/abstract_adapter.rb +39 -32
- data/lib/active_record/connection_adapters/postgresql/column.rb +4 -2
- data/lib/active_record/connection_adapters/postgresql/database_statements.rb +9 -2
- data/lib/active_record/connection_adapters/postgresql_adapter.rb +9 -2
- data/lib/active_record/connection_adapters/sqlite3/column.rb +8 -2
- data/lib/active_record/connection_adapters/sqlite3/database_statements.rb +2 -2
- data/lib/active_record/connection_adapters/sqlite3/schema_dumper.rb +15 -3
- data/lib/active_record/connection_adapters/sqlite3_adapter.rb +5 -5
- data/lib/active_record/connection_handling.rb +13 -9
- data/lib/active_record/core.rb +8 -6
- data/lib/active_record/database_configurations/hash_config.rb +8 -2
- data/lib/active_record/delegated_type.rb +1 -1
- data/lib/active_record/encryption/encryptable_record.rb +1 -1
- data/lib/active_record/encryption/encrypted_attribute_type.rb +1 -1
- data/lib/active_record/encryption/encryptor.rb +27 -25
- data/lib/active_record/enum.rb +13 -12
- data/lib/active_record/errors.rb +3 -3
- data/lib/active_record/fixture_set/table_row.rb +19 -2
- data/lib/active_record/future_result.rb +2 -0
- data/lib/active_record/gem_version.rb +2 -2
- data/lib/active_record/insert_all.rb +2 -2
- data/lib/active_record/migration/command_recorder.rb +1 -1
- data/lib/active_record/migration.rb +5 -5
- data/lib/active_record/query_logs.rb +4 -0
- data/lib/active_record/querying.rb +4 -4
- data/lib/active_record/railtie.rb +2 -2
- data/lib/active_record/railties/databases.rake +8 -16
- data/lib/active_record/relation/calculations.rb +15 -16
- data/lib/active_record/relation/finder_methods.rb +15 -14
- data/lib/active_record/relation/predicate_builder/array_handler.rb +3 -1
- data/lib/active_record/relation/query_methods.rb +6 -5
- data/lib/active_record/relation/spawn_methods.rb +6 -6
- data/lib/active_record/relation/where_clause.rb +9 -3
- data/lib/active_record/relation.rb +15 -5
- data/lib/active_record/secure_token.rb +3 -3
- data/lib/active_record/signed_id.rb +3 -3
- data/lib/active_record/tasks/database_tasks.rb +22 -14
- data/lib/active_record/tasks/postgresql_database_tasks.rb +9 -1
- data/lib/active_record/test_databases.rb +1 -1
- data/lib/active_record/transactions.rb +3 -1
- data/lib/active_record/type/serialized.rb +5 -0
- data/lib/active_record.rb +3 -2
- data/lib/arel/crud.rb +2 -0
- data/lib/arel/delete_manager.rb +5 -0
- data/lib/arel/nodes/delete_statement.rb +4 -2
- data/lib/arel/nodes/update_statement.rb +4 -2
- data/lib/arel/predications.rb +1 -3
- data/lib/arel/select_manager.rb +6 -2
- data/lib/arel/update_manager.rb +5 -0
- data/lib/arel/visitors/dot.rb +2 -0
- data/lib/arel/visitors/to_sql.rb +2 -0
- metadata +10 -10
|
@@ -738,7 +738,7 @@ module ActiveRecord
|
|
|
738
738
|
end
|
|
739
739
|
|
|
740
740
|
def extract_table_ref_from_insert_sql(sql)
|
|
741
|
-
if sql =~ /into\s("[A-Za-z0-9_."\[\]\s]+"|[A-Za-z0-9_."\[\]]+)\s*/im
|
|
741
|
+
if sql =~ /into\s("[-A-Za-z0-9_."\[\]\s]+"|[A-Za-z0-9_."\[\]]+)\s*/im
|
|
742
742
|
$1.delete('"').strip
|
|
743
743
|
end
|
|
744
744
|
end
|
|
@@ -191,15 +191,26 @@ module ActiveRecord
|
|
|
191
191
|
end
|
|
192
192
|
end
|
|
193
193
|
|
|
194
|
-
attr_accessor :query_cache
|
|
195
|
-
|
|
196
194
|
def initialize(*)
|
|
197
195
|
super
|
|
198
196
|
@query_cache = nil
|
|
199
197
|
end
|
|
200
198
|
|
|
199
|
+
attr_writer :query_cache
|
|
200
|
+
|
|
201
|
+
def query_cache
|
|
202
|
+
if @pinned && @owner != ActiveSupport::IsolatedExecutionState.context
|
|
203
|
+
# With transactional tests, if the connection is pinned, any thread
|
|
204
|
+
# other than the one that pinned the connection need to go through the
|
|
205
|
+
# query cache pool, so each thread get a different cache.
|
|
206
|
+
pool.query_cache
|
|
207
|
+
else
|
|
208
|
+
@query_cache
|
|
209
|
+
end
|
|
210
|
+
end
|
|
211
|
+
|
|
201
212
|
def query_cache_enabled
|
|
202
|
-
|
|
213
|
+
query_cache&.enabled?
|
|
203
214
|
end
|
|
204
215
|
|
|
205
216
|
# Enable the query cache within the block.
|
|
@@ -238,7 +249,7 @@ module ActiveRecord
|
|
|
238
249
|
|
|
239
250
|
# If arel is locked this is a SELECT ... FOR UPDATE or somesuch.
|
|
240
251
|
# Such queries should not be cached.
|
|
241
|
-
if
|
|
252
|
+
if query_cache_enabled && !(arel.respond_to?(:locked) && arel.locked)
|
|
242
253
|
sql, binds, preparable, allow_retry = to_sql_and_binds(arel, binds, preparable)
|
|
243
254
|
|
|
244
255
|
if async
|
|
@@ -262,7 +273,7 @@ module ActiveRecord
|
|
|
262
273
|
|
|
263
274
|
result = nil
|
|
264
275
|
@lock.synchronize do
|
|
265
|
-
result =
|
|
276
|
+
result = query_cache[key]
|
|
266
277
|
end
|
|
267
278
|
|
|
268
279
|
if result
|
|
@@ -281,7 +292,7 @@ module ActiveRecord
|
|
|
281
292
|
hit = true
|
|
282
293
|
|
|
283
294
|
@lock.synchronize do
|
|
284
|
-
result =
|
|
295
|
+
result = query_cache.compute_if_absent(key) do
|
|
285
296
|
hit = false
|
|
286
297
|
yield
|
|
287
298
|
end
|
|
@@ -186,6 +186,9 @@ module ActiveRecord
|
|
|
186
186
|
# Join tables for {ActiveRecord::Base.has_and_belongs_to_many}[rdoc-ref:Associations::ClassMethods#has_and_belongs_to_many] should set it to false.
|
|
187
187
|
#
|
|
188
188
|
# A Symbol can be used to specify the type of the generated primary key column.
|
|
189
|
+
#
|
|
190
|
+
# A Hash can be used to specify the generated primary key column creation options.
|
|
191
|
+
# See {add_column}[rdoc-ref:ConnectionAdapters::SchemaStatements#add_column] for available options.
|
|
189
192
|
# [<tt>:primary_key</tt>]
|
|
190
193
|
# The name of the primary key, if one is to be added automatically.
|
|
191
194
|
# Defaults to +id+. If <tt>:id</tt> is false, then this option is ignored.
|
|
@@ -548,7 +551,7 @@ module ActiveRecord
|
|
|
548
551
|
#
|
|
549
552
|
# See {ActiveRecord::ConnectionAdapters::TableDefinition.column}[rdoc-ref:ActiveRecord::ConnectionAdapters::TableDefinition#column].
|
|
550
553
|
#
|
|
551
|
-
# The +type+ parameter is normally one of the
|
|
554
|
+
# The +type+ parameter is normally one of the migration's native types,
|
|
552
555
|
# which is one of the following:
|
|
553
556
|
# <tt>:primary_key</tt>, <tt>:string</tt>, <tt>:text</tt>,
|
|
554
557
|
# <tt>:integer</tt>, <tt>:bigint</tt>, <tt>:float</tt>, <tt>:decimal</tt>, <tt>:numeric</tt>,
|
|
@@ -1557,11 +1560,11 @@ module ActiveRecord
|
|
|
1557
1560
|
non_combinable_operations = []
|
|
1558
1561
|
|
|
1559
1562
|
operations.each do |command, args|
|
|
1560
|
-
|
|
1563
|
+
args.shift # remove table_name
|
|
1561
1564
|
method = :"#{command}_for_alter"
|
|
1562
1565
|
|
|
1563
1566
|
if respond_to?(method, true)
|
|
1564
|
-
sqls, procs = Array(send(method,
|
|
1567
|
+
sqls, procs = Array(send(method, table_name, *args)).partition { |v| v.is_a?(String) }
|
|
1565
1568
|
sql_fragments.concat(sqls)
|
|
1566
1569
|
non_combinable_operations.concat(procs)
|
|
1567
1570
|
else
|
|
@@ -1569,7 +1572,7 @@ module ActiveRecord
|
|
|
1569
1572
|
non_combinable_operations.each(&:call)
|
|
1570
1573
|
sql_fragments = []
|
|
1571
1574
|
non_combinable_operations = []
|
|
1572
|
-
send(command,
|
|
1575
|
+
send(command, table_name, *args)
|
|
1573
1576
|
end
|
|
1574
1577
|
end
|
|
1575
1578
|
|
|
@@ -42,6 +42,7 @@ module ActiveRecord
|
|
|
42
42
|
|
|
43
43
|
attr_reader :pool
|
|
44
44
|
attr_reader :visitor, :owner, :logger, :lock
|
|
45
|
+
attr_accessor :pinned # :nodoc:
|
|
45
46
|
alias :in_use? :owner
|
|
46
47
|
|
|
47
48
|
def pool=(value)
|
|
@@ -150,6 +151,7 @@ module ActiveRecord
|
|
|
150
151
|
end
|
|
151
152
|
|
|
152
153
|
@owner = nil
|
|
154
|
+
@pinned = false
|
|
153
155
|
@pool = ActiveRecord::ConnectionAdapters::NullPool.new
|
|
154
156
|
@idle_since = Process.clock_gettime(Process::CLOCK_MONOTONIC)
|
|
155
157
|
@visitor = arel_visitor
|
|
@@ -664,34 +666,33 @@ module ActiveRecord
|
|
|
664
666
|
deadline = retry_deadline && Process.clock_gettime(Process::CLOCK_MONOTONIC) + retry_deadline
|
|
665
667
|
|
|
666
668
|
@lock.synchronize do
|
|
667
|
-
|
|
669
|
+
attempt_configure_connection do
|
|
670
|
+
reconnect
|
|
668
671
|
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
672
|
+
enable_lazy_transactions!
|
|
673
|
+
@raw_connection_dirty = false
|
|
674
|
+
@last_activity = Process.clock_gettime(Process::CLOCK_MONOTONIC)
|
|
675
|
+
@verified = true
|
|
673
676
|
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
677
|
+
reset_transaction(restore: restore_transactions) do
|
|
678
|
+
clear_cache!(new_connection: true)
|
|
679
|
+
configure_connection
|
|
680
|
+
end
|
|
681
|
+
rescue => original_exception
|
|
682
|
+
translated_exception = translate_exception_class(original_exception, nil, nil)
|
|
683
|
+
retry_deadline_exceeded = deadline && deadline < Process.clock_gettime(Process::CLOCK_MONOTONIC)
|
|
681
684
|
|
|
682
|
-
|
|
683
|
-
|
|
685
|
+
if !retry_deadline_exceeded && retries_available > 0
|
|
686
|
+
retries_available -= 1
|
|
684
687
|
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
+
if retryable_connection_error?(translated_exception)
|
|
689
|
+
backoff(connection_retries - retries_available)
|
|
690
|
+
retry
|
|
691
|
+
end
|
|
688
692
|
end
|
|
689
|
-
end
|
|
690
|
-
|
|
691
|
-
@last_activity = nil
|
|
692
|
-
@verified = false
|
|
693
693
|
|
|
694
|
-
|
|
694
|
+
raise translated_exception
|
|
695
|
+
end
|
|
695
696
|
end
|
|
696
697
|
end
|
|
697
698
|
|
|
@@ -699,6 +700,8 @@ module ActiveRecord
|
|
|
699
700
|
# method does nothing.
|
|
700
701
|
def disconnect!
|
|
701
702
|
@lock.synchronize do
|
|
703
|
+
@last_activity = nil
|
|
704
|
+
@verified = false
|
|
702
705
|
clear_cache!(new_connection: true)
|
|
703
706
|
reset_transaction
|
|
704
707
|
@raw_connection_dirty = false
|
|
@@ -724,9 +727,11 @@ module ActiveRecord
|
|
|
724
727
|
# should call super immediately after resetting the connection (and while
|
|
725
728
|
# still holding @lock).
|
|
726
729
|
def reset!
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
+
attempt_configure_connection do
|
|
731
|
+
clear_cache!(new_connection: true)
|
|
732
|
+
reset_transaction
|
|
733
|
+
configure_connection
|
|
734
|
+
end
|
|
730
735
|
end
|
|
731
736
|
|
|
732
737
|
# Removes the connection from the pool and disconnect it.
|
|
@@ -760,11 +765,13 @@ module ActiveRecord
|
|
|
760
765
|
unless active?
|
|
761
766
|
@lock.synchronize do
|
|
762
767
|
if @unconfigured_connection
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
+
attempt_configure_connection do
|
|
769
|
+
@raw_connection = @unconfigured_connection
|
|
770
|
+
@unconfigured_connection = nil
|
|
771
|
+
configure_connection
|
|
772
|
+
@last_activity = Process.clock_gettime(Process::CLOCK_MONOTONIC)
|
|
773
|
+
@verified = true
|
|
774
|
+
end
|
|
768
775
|
return
|
|
769
776
|
end
|
|
770
777
|
|
|
@@ -1214,8 +1221,8 @@ module ActiveRecord
|
|
|
1214
1221
|
end
|
|
1215
1222
|
|
|
1216
1223
|
def attempt_configure_connection
|
|
1217
|
-
|
|
1218
|
-
rescue
|
|
1224
|
+
yield
|
|
1225
|
+
rescue Exception # Need to handle things such as Timeout::ExitException
|
|
1219
1226
|
disconnect!
|
|
1220
1227
|
raise
|
|
1221
1228
|
end
|
|
@@ -65,7 +65,8 @@ module ActiveRecord
|
|
|
65
65
|
other.is_a?(Column) &&
|
|
66
66
|
super &&
|
|
67
67
|
identity? == other.identity? &&
|
|
68
|
-
serial? == other.serial?
|
|
68
|
+
serial? == other.serial? &&
|
|
69
|
+
virtual? == other.virtual?
|
|
69
70
|
end
|
|
70
71
|
alias :eql? :==
|
|
71
72
|
|
|
@@ -73,7 +74,8 @@ module ActiveRecord
|
|
|
73
74
|
Column.hash ^
|
|
74
75
|
super.hash ^
|
|
75
76
|
identity?.hash ^
|
|
76
|
-
serial?.hash
|
|
77
|
+
serial?.hash ^
|
|
78
|
+
virtual?.hash
|
|
77
79
|
end
|
|
78
80
|
end
|
|
79
81
|
end
|
|
@@ -127,7 +127,14 @@ module ActiveRecord
|
|
|
127
127
|
def cancel_any_running_query
|
|
128
128
|
return if @raw_connection.nil? || IDLE_TRANSACTION_STATUSES.include?(@raw_connection.transaction_status)
|
|
129
129
|
|
|
130
|
-
@raw_connection.cancel
|
|
130
|
+
# Skip @raw_connection.cancel (PG::Connection#cancel) when using libpq >= 18 with pg < 1.6.0,
|
|
131
|
+
# because the pg gem cannot obtain the backend_key in that case.
|
|
132
|
+
# This method is only called from exec_rollback_db_transaction and exec_restart_db_transaction.
|
|
133
|
+
# Even without cancel, rollback will still run. However, since any running
|
|
134
|
+
# query must finish first, the rollback may take longer.
|
|
135
|
+
if !(PG.library_version >= 18_00_00 && Gem::Version.new(PG::VERSION) < Gem::Version.new("1.6.0"))
|
|
136
|
+
@raw_connection.cancel
|
|
137
|
+
end
|
|
131
138
|
@raw_connection.block
|
|
132
139
|
rescue PG::Error
|
|
133
140
|
end
|
|
@@ -164,7 +171,7 @@ module ActiveRecord
|
|
|
164
171
|
|
|
165
172
|
verified!
|
|
166
173
|
handle_warnings(result)
|
|
167
|
-
notification_payload[:row_count] = result.
|
|
174
|
+
notification_payload[:row_count] = result.ntuples
|
|
168
175
|
result
|
|
169
176
|
end
|
|
170
177
|
|
|
@@ -25,7 +25,7 @@ module ActiveRecord
|
|
|
25
25
|
#
|
|
26
26
|
# The PostgreSQL adapter works with the native C (https://github.com/ged/ruby-pg) driver.
|
|
27
27
|
#
|
|
28
|
-
# Options
|
|
28
|
+
# ==== Options
|
|
29
29
|
#
|
|
30
30
|
# * <tt>:host</tt> - Defaults to a Unix-domain socket in /tmp. On machines without Unix-domain sockets,
|
|
31
31
|
# the default is to connect to localhost.
|
|
@@ -381,6 +381,11 @@ module ActiveRecord
|
|
|
381
381
|
end
|
|
382
382
|
end
|
|
383
383
|
|
|
384
|
+
def clear_cache!(new_connection: false)
|
|
385
|
+
super
|
|
386
|
+
@schema_search_path = nil if new_connection
|
|
387
|
+
end
|
|
388
|
+
|
|
384
389
|
# Disconnects from the database if already connected. Otherwise, this
|
|
385
390
|
# method does nothing.
|
|
386
391
|
def disconnect!
|
|
@@ -616,7 +621,7 @@ module ActiveRecord
|
|
|
616
621
|
}
|
|
617
622
|
end
|
|
618
623
|
|
|
619
|
-
# Returns the configured supported identifier length supported by PostgreSQL
|
|
624
|
+
# Returns the configured maximum supported identifier length supported by PostgreSQL
|
|
620
625
|
def max_identifier_length
|
|
621
626
|
@max_identifier_length ||= query_value("SHOW max_identifier_length", "SCHEMA").to_i
|
|
622
627
|
end
|
|
@@ -993,6 +998,8 @@ module ActiveRecord
|
|
|
993
998
|
add_pg_encoders
|
|
994
999
|
add_pg_decoders
|
|
995
1000
|
|
|
1001
|
+
schema_search_path # populate cache
|
|
1002
|
+
|
|
996
1003
|
reload_type_map
|
|
997
1004
|
end
|
|
998
1005
|
|
|
@@ -46,7 +46,9 @@ module ActiveRecord
|
|
|
46
46
|
def ==(other)
|
|
47
47
|
other.is_a?(Column) &&
|
|
48
48
|
super &&
|
|
49
|
-
auto_increment? == other.auto_increment?
|
|
49
|
+
auto_increment? == other.auto_increment? &&
|
|
50
|
+
rowid == other.rowid &&
|
|
51
|
+
generated_type == other.generated_type
|
|
50
52
|
end
|
|
51
53
|
alias :eql? :==
|
|
52
54
|
|
|
@@ -54,8 +56,12 @@ module ActiveRecord
|
|
|
54
56
|
Column.hash ^
|
|
55
57
|
super.hash ^
|
|
56
58
|
auto_increment?.hash ^
|
|
57
|
-
rowid.hash
|
|
59
|
+
rowid.hash ^
|
|
60
|
+
virtual?.hash
|
|
58
61
|
end
|
|
62
|
+
|
|
63
|
+
protected
|
|
64
|
+
attr_reader :generated_type
|
|
59
65
|
end
|
|
60
66
|
end
|
|
61
67
|
end
|
|
@@ -114,8 +114,8 @@ module ActiveRecord
|
|
|
114
114
|
end
|
|
115
115
|
|
|
116
116
|
def cast_result(result)
|
|
117
|
-
# Given that SQLite3 doesn't
|
|
118
|
-
#
|
|
117
|
+
# Given that SQLite3 doesn't have a Result type, raw_execute already returns an ActiveRecord::Result
|
|
118
|
+
# so we have nothing to cast here.
|
|
119
119
|
result
|
|
120
120
|
end
|
|
121
121
|
|
|
@@ -6,7 +6,7 @@ module ActiveRecord
|
|
|
6
6
|
class SchemaDumper < ConnectionAdapters::SchemaDumper # :nodoc:
|
|
7
7
|
private
|
|
8
8
|
def virtual_tables(stream)
|
|
9
|
-
virtual_tables = @connection.virtual_tables
|
|
9
|
+
virtual_tables = @connection.virtual_tables.reject { |name, _| ignored?(name) }
|
|
10
10
|
if virtual_tables.any?
|
|
11
11
|
stream.puts
|
|
12
12
|
stream.puts " # Virtual tables defined in this database."
|
|
@@ -19,11 +19,23 @@ module ActiveRecord
|
|
|
19
19
|
end
|
|
20
20
|
|
|
21
21
|
def default_primary_key?(column)
|
|
22
|
-
schema_type(column) == :integer
|
|
22
|
+
schema_type(column) == :integer && primary_key_has_autoincrement?
|
|
23
23
|
end
|
|
24
24
|
|
|
25
25
|
def explicit_primary_key_default?(column)
|
|
26
|
-
column.bigint?
|
|
26
|
+
column.bigint? || (column.type == :integer && !primary_key_has_autoincrement?)
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def primary_key_has_autoincrement?
|
|
30
|
+
return false unless table_name
|
|
31
|
+
|
|
32
|
+
table_sql = @connection.query_value(<<~SQL, "SCHEMA")
|
|
33
|
+
SELECT sql FROM sqlite_master WHERE name = #{@connection.quote(table_name)} AND type = 'table'
|
|
34
|
+
UNION ALL
|
|
35
|
+
SELECT sql FROM sqlite_temp_master WHERE name = #{@connection.quote(table_name)} AND type = 'table'
|
|
36
|
+
SQL
|
|
37
|
+
|
|
38
|
+
table_sql.to_s.match?(/\bAUTOINCREMENT\b/i)
|
|
27
39
|
end
|
|
28
40
|
|
|
29
41
|
def prepare_column_options(column)
|
|
@@ -24,7 +24,7 @@ module ActiveRecord
|
|
|
24
24
|
# The SQLite3 adapter works with the sqlite3-ruby drivers
|
|
25
25
|
# (available as gem from https://rubygems.org/gems/sqlite3).
|
|
26
26
|
#
|
|
27
|
-
# Options
|
|
27
|
+
# ==== Options
|
|
28
28
|
#
|
|
29
29
|
# * <tt>:database</tt> - Path to the database file.
|
|
30
30
|
class SQLite3Adapter < AbstractAdapter
|
|
@@ -291,7 +291,7 @@ module ActiveRecord
|
|
|
291
291
|
exec_query "DROP INDEX #{quote_column_name(index_name)}"
|
|
292
292
|
end
|
|
293
293
|
|
|
294
|
-
VIRTUAL_TABLE_REGEX = /USING\s+(\w+)\s*\((
|
|
294
|
+
VIRTUAL_TABLE_REGEX = /USING\s+(\w+)\s*\((.*)\)/i
|
|
295
295
|
|
|
296
296
|
# Returns a list of defined virtual tables
|
|
297
297
|
def virtual_tables
|
|
@@ -309,7 +309,7 @@ module ActiveRecord
|
|
|
309
309
|
# Creates a virtual table
|
|
310
310
|
#
|
|
311
311
|
# Example:
|
|
312
|
-
# create_virtual_table :emails, :fts5, ['sender', 'title','
|
|
312
|
+
# create_virtual_table :emails, :fts5, ['sender', 'title', 'body']
|
|
313
313
|
def create_virtual_table(table_name, module_name, values)
|
|
314
314
|
exec_query "CREATE VIRTUAL TABLE IF NOT EXISTS #{table_name} USING #{module_name} (#{values.join(", ")})"
|
|
315
315
|
end
|
|
@@ -583,8 +583,8 @@ module ActiveRecord
|
|
|
583
583
|
yield definition if block_given?
|
|
584
584
|
end
|
|
585
585
|
|
|
586
|
-
|
|
587
|
-
|
|
586
|
+
disable_referential_integrity do
|
|
587
|
+
transaction do
|
|
588
588
|
move_table(table_name, altered_table_name, options.merge(temporary: true))
|
|
589
589
|
move_table(altered_table_name, table_name, &caller)
|
|
590
590
|
end
|
|
@@ -172,9 +172,11 @@ module ActiveRecord
|
|
|
172
172
|
prevent_writes = true if role == ActiveRecord.reading_role
|
|
173
173
|
|
|
174
174
|
append_to_connected_to_stack(role: role, shard: shard, prevent_writes: prevent_writes, klasses: classes)
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
175
|
+
begin
|
|
176
|
+
yield
|
|
177
|
+
ensure
|
|
178
|
+
connected_to_stack.pop
|
|
179
|
+
end
|
|
178
180
|
end
|
|
179
181
|
|
|
180
182
|
# Passes the block to +connected_to+ for every +shard+ the
|
|
@@ -301,7 +303,7 @@ module ActiveRecord
|
|
|
301
303
|
|
|
302
304
|
# Checkouts a connection from the pool, yield it and then check it back in.
|
|
303
305
|
# If a connection was already leased via #lease_connection or a parent call to
|
|
304
|
-
# #with_connection, that same connection is
|
|
306
|
+
# #with_connection, that same connection is yielded.
|
|
305
307
|
# If #lease_connection is called inside the block, the connection won't be checked
|
|
306
308
|
# back in.
|
|
307
309
|
# If #connection is called inside the block, the connection won't be checked back in
|
|
@@ -395,11 +397,13 @@ module ActiveRecord
|
|
|
395
397
|
prevent_writes = true if role == ActiveRecord.reading_role
|
|
396
398
|
|
|
397
399
|
append_to_connected_to_stack(role: role, shard: shard, prevent_writes: prevent_writes, klasses: [self])
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
400
|
+
begin
|
|
401
|
+
return_value = yield
|
|
402
|
+
return_value.load if return_value.is_a? ActiveRecord::Relation
|
|
403
|
+
return_value
|
|
404
|
+
ensure
|
|
405
|
+
self.connected_to_stack.pop
|
|
406
|
+
end
|
|
403
407
|
end
|
|
404
408
|
|
|
405
409
|
def append_to_connected_to_stack(entry)
|
data/lib/active_record/core.rb
CHANGED
|
@@ -277,7 +277,7 @@ module ActiveRecord
|
|
|
277
277
|
return super if StatementCache.unsupported_value?(id)
|
|
278
278
|
|
|
279
279
|
cached_find_by([primary_key], [id]) ||
|
|
280
|
-
raise(RecordNotFound.new("Couldn't find #{name} with '#{primary_key}'=#{id}", name, primary_key, id))
|
|
280
|
+
raise(RecordNotFound.new("Couldn't find #{name} with '#{primary_key}'=#{id.inspect}", name, primary_key, id))
|
|
281
281
|
end
|
|
282
282
|
|
|
283
283
|
def find_by(*args) # :nodoc:
|
|
@@ -600,7 +600,7 @@ module ActiveRecord
|
|
|
600
600
|
#
|
|
601
601
|
# topic = Topic.new(title: "Budget", author_name: "Jason")
|
|
602
602
|
# topic.slice(:title, :author_name)
|
|
603
|
-
# => { "title" => "Budget", "author_name" => "Jason" }
|
|
603
|
+
# # => { "title" => "Budget", "author_name" => "Jason" }
|
|
604
604
|
#
|
|
605
605
|
#--
|
|
606
606
|
# Implemented by ActiveModel::Access#slice.
|
|
@@ -614,7 +614,7 @@ module ActiveRecord
|
|
|
614
614
|
#
|
|
615
615
|
# topic = Topic.new(title: "Budget", author_name: "Jason")
|
|
616
616
|
# topic.values_at(:title, :author_name)
|
|
617
|
-
# => ["Budget", "Jason"]
|
|
617
|
+
# # => ["Budget", "Jason"]
|
|
618
618
|
#
|
|
619
619
|
#--
|
|
620
620
|
# Implemented by ActiveModel::Access#values_at.
|
|
@@ -691,12 +691,14 @@ module ActiveRecord
|
|
|
691
691
|
# Sets the record to strict_loading mode. This will raise an error
|
|
692
692
|
# if the record tries to lazily load an association.
|
|
693
693
|
#
|
|
694
|
+
# NOTE: Strict loading is disabled during validation in order to let the record validate its association.
|
|
695
|
+
#
|
|
694
696
|
# user = User.first
|
|
695
697
|
# user.strict_loading! # => true
|
|
696
698
|
# user.address.city
|
|
697
|
-
# => ActiveRecord::StrictLoadingViolationError
|
|
699
|
+
# # => ActiveRecord::StrictLoadingViolationError
|
|
698
700
|
# user.comments.to_a
|
|
699
|
-
# => ActiveRecord::StrictLoadingViolationError
|
|
701
|
+
# # => ActiveRecord::StrictLoadingViolationError
|
|
700
702
|
#
|
|
701
703
|
# ==== Parameters
|
|
702
704
|
#
|
|
@@ -716,7 +718,7 @@ module ActiveRecord
|
|
|
716
718
|
# user.address.city # => "Tatooine"
|
|
717
719
|
# user.comments.to_a # => [#<Comment:0x00...]
|
|
718
720
|
# user.comments.first.ratings.to_a
|
|
719
|
-
# => ActiveRecord::StrictLoadingViolationError
|
|
721
|
+
# # => ActiveRecord::StrictLoadingViolationError
|
|
720
722
|
def strict_loading!(value = true, mode: :all)
|
|
721
723
|
unless [:all, :n_plus_one_only].include?(mode)
|
|
722
724
|
raise ArgumentError, "The :mode option must be one of [:all, :n_plus_one_only] but #{mode.inspect} was provided."
|
|
@@ -146,7 +146,7 @@ module ActiveRecord
|
|
|
146
146
|
#
|
|
147
147
|
# If the config option is set that will be used. Otherwise Rails will generate
|
|
148
148
|
# the filename from the database config name.
|
|
149
|
-
def schema_dump(format =
|
|
149
|
+
def schema_dump(format = schema_format)
|
|
150
150
|
if configuration_hash.key?(:schema_dump)
|
|
151
151
|
if config = configuration_hash[:schema_dump]
|
|
152
152
|
config
|
|
@@ -158,6 +158,12 @@ module ActiveRecord
|
|
|
158
158
|
end
|
|
159
159
|
end
|
|
160
160
|
|
|
161
|
+
def schema_format # :nodoc:
|
|
162
|
+
format = configuration_hash[:schema_format]&.to_sym || ActiveRecord.schema_format
|
|
163
|
+
raise "Invalid schema format" unless [ :ruby, :sql ].include? format
|
|
164
|
+
format
|
|
165
|
+
end
|
|
166
|
+
|
|
161
167
|
def database_tasks? # :nodoc:
|
|
162
168
|
!replica? && !!configuration_hash.fetch(:database_tasks, true)
|
|
163
169
|
end
|
|
@@ -168,7 +174,7 @@ module ActiveRecord
|
|
|
168
174
|
|
|
169
175
|
private
|
|
170
176
|
def schema_file_type(format)
|
|
171
|
-
case format
|
|
177
|
+
case format.to_sym
|
|
172
178
|
when :ruby
|
|
173
179
|
"schema.rb"
|
|
174
180
|
when :sql
|
|
@@ -202,7 +202,7 @@ module ActiveRecord
|
|
|
202
202
|
# @entry.access_notice_message
|
|
203
203
|
# @entry.access_notice_message?
|
|
204
204
|
#
|
|
205
|
-
#
|
|
205
|
+
# ==== Options
|
|
206
206
|
#
|
|
207
207
|
# The +options+ are passed directly to the +belongs_to+ call, so this is where you declare +dependent+ etc.
|
|
208
208
|
# The following options can be included to specialize the behavior of the delegated type convenience methods.
|
|
@@ -16,7 +16,7 @@ module ActiveRecord
|
|
|
16
16
|
class_methods do
|
|
17
17
|
# Encrypts the +name+ attribute.
|
|
18
18
|
#
|
|
19
|
-
#
|
|
19
|
+
# ==== Options
|
|
20
20
|
#
|
|
21
21
|
# * <tt>:key_provider</tt> - A key provider to provide encryption and decryption keys. Defaults to
|
|
22
22
|
# +ActiveRecord::Encryption.key_provider+.
|
|
@@ -15,7 +15,7 @@ module ActiveRecord
|
|
|
15
15
|
delegate :key_provider, :downcase?, :deterministic?, :previous_schemes, :with_context, :fixed?, to: :scheme
|
|
16
16
|
delegate :accessor, :type, to: :cast_type
|
|
17
17
|
|
|
18
|
-
#
|
|
18
|
+
# ==== Options
|
|
19
19
|
#
|
|
20
20
|
# * <tt>:scheme</tt> - A +Scheme+ with the encryption properties for this attribute.
|
|
21
21
|
# * <tt>:cast_type</tt> - A type that will be used to serialize (before encrypting) and deserialize
|