You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Move the database version cache from schema cache to pool config
Ref: rails#49378
As discussed with Matthew Draper, we have a bit of a chicken and egg
problem with the schema cache and the database version.
The database version is stored in the cache to avoid a query,
but the schema cache need to query the schema version in the database
to be revalidated.
So `check_version` depends on `schema_cache`, which depends on
`Migrator.current_version`, which depends on `configure_connection`
which depends on `check_version`.
But ultimately, we think storing the server version in the cache
is incorrect, because upgrading a DB server is orthogonal from
regenerating the schema cache.
So not persisting the version in cache is better. Instead we store
it in the pool config, so that we only check it once per process
and per database.
Copy file name to clipboardExpand all lines: activerecord/lib/active_record/railtie.rb
+5-2Lines changed: 5 additions & 2 deletions
Original file line number
Diff line number
Diff line change
@@ -162,10 +162,13 @@ class Railtie < Rails::Railtie # :nodoc:
162
162
warn"Failed to validate the schema cache because of #{error.class}: #{error.message}"
163
163
nil
164
164
end
165
-
nextifcurrent_version.nil?
166
165
167
-
ifcache.schema_version != current_version
166
+
ifcurrent_version.nil?
167
+
connection_pool.schema_reflection.clear!
168
+
next
169
+
elsifcache.schema_version != current_version
168
170
warn"Ignoring #{filename} because it has expired. The current schema version is #{current_version}, but the one in the schema cache file is #{cache.schema_version}."
0 commit comments