Skip to content

Commit f91cb4f

Browse files
committed
Deprecated ENV["SCHEMA_CACHE"] in favor of schema_cache_path in the databse configuration
The config in the yaml allows for more complex configuration.
1 parent 83f4441 commit f91cb4f

File tree

4 files changed

+22
-16
lines changed

4 files changed

+22
-16
lines changed

activerecord/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
* Deprecated `ENV["SCHEMA_CACHE"]` in favor of `schema_cache_path` in the database configuration.
2+
3+
*Rafael Mendonça França*
4+
15
* Add `ActiveRecord::Base.with_connection` as a shortcut for leasing a connection for a short duration.
26

37
The leased connection is yielded, and for the duration of the block, any call to `ActiveRecord::Base.connection`

activerecord/lib/active_record/tasks/database_tasks.rb

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -441,7 +441,7 @@ def cache_dump_filename(db_config_or_name, schema_cache_path: nil)
441441
if db_config_or_name.is_a?(DatabaseConfigurations::DatabaseConfig)
442442
schema_cache_path ||
443443
db_config_or_name.schema_cache_path ||
444-
ENV["SCHEMA_CACHE"] ||
444+
schema_cache_env ||
445445
db_config_or_name.default_schema_cache_path(ActiveRecord::Tasks::DatabaseTasks.db_dir)
446446
else
447447
ActiveRecord.deprecator.warn(<<~MSG.squish)
@@ -455,7 +455,7 @@ def cache_dump_filename(db_config_or_name, schema_cache_path: nil)
455455
"#{db_config_or_name}_schema_cache.yml"
456456
end
457457

458-
schema_cache_path || ENV["SCHEMA_CACHE"] || File.join(ActiveRecord::Tasks::DatabaseTasks.db_dir, filename)
458+
schema_cache_path || schema_cache_env || File.join(ActiveRecord::Tasks::DatabaseTasks.db_dir, filename)
459459
end
460460
end
461461

@@ -523,6 +523,17 @@ def migration_connection # :nodoc:
523523
end
524524

525525
private
526+
def schema_cache_env
527+
if ENV["SCHEMA_CACHE"]
528+
ActiveRecord.deprecator.warn(<<~MSG.squish)
529+
Setting `ENV["SCHEMA_CACHE"]` is deprecated and will be removed in Rails 7.3.
530+
Configure the `:schema_cache_path` in the database configuration instead.
531+
MSG
532+
533+
nil
534+
end
535+
end
536+
526537
def with_temporary_pool(db_config, clobber: false)
527538
original_db_config = migration_class.connection_db_config
528539
pool = migration_class.connection_handler.establish_connection(db_config, clobber: clobber)

activerecord/test/cases/tasks/database_tasks_test.rb

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -388,8 +388,10 @@ def test_cache_dump_filename_with_env_override
388388
config = DatabaseConfigurations::HashConfig.new("development", "primary", {})
389389

390390
ActiveRecord::Tasks::DatabaseTasks.stub(:db_dir, "db") do
391-
path = ActiveRecord::Tasks::DatabaseTasks.cache_dump_filename(config)
392-
assert_equal "tmp/something.yml", path
391+
path = assert_deprecated(/Setting `ENV\["SCHEMA_CACHE"\]` is deprecated and will be removed in Rails 7\.3\. Configure the `:schema_cache_path` in the database configuration instead\. \(/, ActiveRecord.deprecator) do
392+
ActiveRecord::Tasks::DatabaseTasks.cache_dump_filename(config)
393+
end
394+
assert_equal "db/schema_cache.yml", path
393395
end
394396
ensure
395397
ENV["SCHEMA_CACHE"] = old_path
@@ -403,7 +405,7 @@ def test_deprecated_cache_dump_filename_with_env_override
403405
path = assert_deprecated(/Passing a database name to `cache_dump_filename` is deprecated and will be removed in Rails 7\.3\. Pass a `ActiveRecord::DatabaseConfigurations::DatabaseConfig` object instead\. \(/, ActiveRecord.deprecator) do
404406
ActiveRecord::Tasks::DatabaseTasks.cache_dump_filename("primary")
405407
end
406-
assert_equal "tmp/something.yml", path
408+
assert_equal "db/schema_cache.yml", path
407409
end
408410
ensure
409411
ENV["SCHEMA_CACHE"] = old_path

railties/test/application/rake/dbs_test.rb

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -439,17 +439,6 @@ def db_schema_cache_dump
439439
db_schema_cache_dump
440440
end
441441

442-
test "db:schema:cache:dump custom env" do
443-
@old_schema_cache_env = ENV["SCHEMA_CACHE"]
444-
filename = "db/special_schema_cache.yml"
445-
ENV["SCHEMA_CACHE"] = filename
446-
447-
db_schema_dump
448-
db_schema_cache_dump
449-
ensure
450-
ENV["SCHEMA_CACHE"] = @old_schema_cache_env
451-
end
452-
453442
test "db:schema:cache:dump first config wins" do
454443
Dir.chdir(app_path) do
455444
File.open("#{app_path}/config/database.yml", "w") do |f|

0 commit comments

Comments
 (0)