mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Remove deprecated methods in `Tasks::DatabaseTasks
This commit is contained in:
parent
9828cc76d1
commit
71f61b13e1
4 changed files with 32 additions and 117 deletions
|
@ -1,3 +1,23 @@
|
|||
* Remove deprecated `Tasks::DatabaseTasks.spec`.
|
||||
|
||||
*Rafael Mendonça França*
|
||||
|
||||
* Remove deprecated `Tasks::DatabaseTasks.current_config`.
|
||||
|
||||
*Rafael Mendonça França*
|
||||
|
||||
* Deprecate `Tasks::DatabaseTasks.schema_file_type`.
|
||||
|
||||
*Rafael Mendonça França*
|
||||
|
||||
* Remove deprecated `Tasks::DatabaseTasks.dump_filename`.
|
||||
|
||||
*Rafael Mendonça França*
|
||||
|
||||
* Remove deprecated `Tasks::DatabaseTasks.schema_file`.
|
||||
|
||||
*Rafael Mendonça França*
|
||||
|
||||
* Remove deprecated `environment` and `name` arguments from `Tasks::DatabaseTasks.schema_up_to_date?`.
|
||||
|
||||
*Rafael Mendonça França*
|
||||
|
|
|
@ -55,8 +55,7 @@ module ActiveRecord
|
|||
|
||||
extend self
|
||||
|
||||
attr_writer :current_config, :db_dir, :migrations_paths, :fixtures_path, :root, :env, :seed_loader
|
||||
deprecate :current_config=
|
||||
attr_writer :db_dir, :migrations_paths, :fixtures_path, :root, :env, :seed_loader
|
||||
attr_accessor :database_configuration
|
||||
|
||||
LOCAL_HOSTS = ["127.0.0.1", "localhost"]
|
||||
|
@ -110,11 +109,6 @@ module ActiveRecord
|
|||
@env ||= Rails.env
|
||||
end
|
||||
|
||||
def spec
|
||||
@spec ||= "primary"
|
||||
end
|
||||
deprecate spec: "please use name instead"
|
||||
|
||||
def name
|
||||
@name ||= "primary"
|
||||
end
|
||||
|
@ -123,18 +117,6 @@ module ActiveRecord
|
|||
@seed_loader ||= Rails.application
|
||||
end
|
||||
|
||||
def current_config(options = {})
|
||||
if options.has_key?(:config)
|
||||
@current_config = options[:config]
|
||||
else
|
||||
env_name = options[:env] || env
|
||||
name = options[:spec] || "primary"
|
||||
|
||||
@current_config ||= configs_for(env_name: env_name, name: name)&.configuration_hash
|
||||
end
|
||||
end
|
||||
deprecate :current_config
|
||||
|
||||
def create(configuration, *arguments)
|
||||
db_config = resolve_configuration(configuration)
|
||||
database_adapter_for(db_config, *arguments).create
|
||||
|
@ -453,11 +435,6 @@ module ActiveRecord
|
|||
end
|
||||
end
|
||||
|
||||
def schema_file(format = ActiveRecord.schema_format)
|
||||
File.join(db_dir, schema_file_type(format))
|
||||
end
|
||||
deprecate :schema_file
|
||||
|
||||
def schema_file_type(format = ActiveRecord.schema_format)
|
||||
case format
|
||||
when :ruby
|
||||
|
@ -466,18 +443,7 @@ module ActiveRecord
|
|||
"structure.sql"
|
||||
end
|
||||
end
|
||||
|
||||
def dump_filename(db_config_name, format = ActiveRecord.schema_format)
|
||||
ActiveSupport::Deprecation.warn("#dump_filename is deprecated. Please call `schema_dump_path` or call `schema_dump` on the `db_config` directly.")
|
||||
|
||||
filename = if ActiveRecord::Base.configurations.primary?(db_config_name)
|
||||
schema_file_type(format)
|
||||
else
|
||||
"#{db_config_name}_#{schema_file_type(format)}"
|
||||
end
|
||||
|
||||
ENV["SCHEMA"] || File.join(ActiveRecord::Tasks::DatabaseTasks.db_dir, filename)
|
||||
end
|
||||
deprecate :schema_file_type
|
||||
|
||||
def schema_dump_path(db_config, format = ActiveRecord.schema_format)
|
||||
return ENV["SCHEMA"] if ENV["SCHEMA"]
|
||||
|
|
|
@ -112,59 +112,6 @@ module ActiveRecord
|
|||
end
|
||||
end
|
||||
|
||||
class DatabaseTasksCurrentConfigTask < ActiveRecord::TestCase
|
||||
def test_current_config_set
|
||||
hash = {}
|
||||
|
||||
with_stubbed_configurations do
|
||||
ActiveRecord::Tasks::DatabaseTasks.current_config(config: hash, env: "production")
|
||||
|
||||
assert_equal hash, ActiveRecord::Tasks::DatabaseTasks.current_config(env: "production")
|
||||
end
|
||||
end
|
||||
|
||||
def test_current_config_read_none_found
|
||||
with_stubbed_configurations do
|
||||
config = ActiveRecord::Tasks::DatabaseTasks.current_config(env: "production", spec: "empty")
|
||||
|
||||
assert_nil config
|
||||
end
|
||||
end
|
||||
|
||||
def test_current_config_read_found
|
||||
with_stubbed_configurations do
|
||||
config = ActiveRecord::Tasks::DatabaseTasks.current_config(env: "production", spec: "exists")
|
||||
|
||||
assert_equal({ database: "my-db" }, config)
|
||||
end
|
||||
end
|
||||
|
||||
def test_current_config_read_after_set
|
||||
hash = {}
|
||||
|
||||
with_stubbed_configurations do
|
||||
ActiveRecord::Tasks::DatabaseTasks.current_config(config: hash, env: "production")
|
||||
|
||||
config = ActiveRecord::Tasks::DatabaseTasks.current_config(env: "production", spec: "exists")
|
||||
|
||||
assert_equal hash, config
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
def with_stubbed_configurations(&block)
|
||||
old_configurations = ActiveRecord::Base.configurations
|
||||
ActiveRecord::Base.configurations = { "production" => { "exists" => { "database" => "my-db" } } }
|
||||
|
||||
assert_deprecated(&block)
|
||||
ensure
|
||||
ActiveRecord::Base.configurations = old_configurations
|
||||
assert_deprecated do
|
||||
ActiveRecord::Tasks::DatabaseTasks.current_config = nil
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
class DatabaseTasksRegisterTask < ActiveRecord::TestCase
|
||||
def test_register_task
|
||||
klazz = Class.new do
|
||||
|
@ -1597,24 +1544,6 @@ module ActiveRecord
|
|||
@configurations = { "development" => { "database" => "my-db" } }
|
||||
end
|
||||
|
||||
def test_check_schema_file_defaults
|
||||
ActiveRecord::Tasks::DatabaseTasks.stub(:db_dir, "/tmp") do
|
||||
assert_deprecated do
|
||||
assert_equal "/tmp/schema.rb", ActiveRecord::Tasks::DatabaseTasks.schema_file
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
{ ruby: "schema.rb", sql: "structure.sql" }.each_pair do |fmt, filename|
|
||||
define_method("test_check_schema_file_for_#{fmt}_format") do
|
||||
ActiveRecord::Tasks::DatabaseTasks.stub(:db_dir, "/tmp") do
|
||||
assert_deprecated do
|
||||
assert_equal "/tmp/#{filename}", ActiveRecord::Tasks::DatabaseTasks.schema_file(fmt)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def test_check_dump_filename_defaults
|
||||
ActiveRecord::Tasks::DatabaseTasks.stub(:db_dir, "/tmp") do
|
||||
with_stubbed_configurations do
|
||||
|
@ -1623,16 +1552,6 @@ module ActiveRecord
|
|||
end
|
||||
end
|
||||
|
||||
def test_dump_filename_is_deprecated
|
||||
ActiveRecord::Tasks::DatabaseTasks.stub(:db_dir, "/tmp") do
|
||||
with_stubbed_configurations do
|
||||
assert_deprecated do
|
||||
assert_equal "/tmp/schema.rb", ActiveRecord::Tasks::DatabaseTasks.dump_filename(config_for("development", "primary").name)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def test_check_dump_filename_with_schema_env
|
||||
schema = ENV["SCHEMA"]
|
||||
ENV["SCHEMA"] = "schema_path"
|
||||
|
|
|
@ -141,8 +141,18 @@ Please refer to the [Changelog][active-record] for detailed changes.
|
|||
|
||||
* Remove deprecated `environment` and `name` arguments from `Tasks::DatabaseTasks.schema_up_to_date?`.
|
||||
|
||||
* Remove deprecated `Tasks::DatabaseTasks.dump_filename`.
|
||||
|
||||
* Remove deprecated `Tasks::DatabaseTasks.schema_file`.
|
||||
|
||||
* Remove deprecated `Tasks::DatabaseTasks.spec`.
|
||||
|
||||
* Remove deprecated `Tasks::DatabaseTasks.current_config`.
|
||||
|
||||
### Deprecations
|
||||
|
||||
* Deprecated `Tasks::DatabaseTasks.:schema_file_type`.
|
||||
|
||||
### Notable changes
|
||||
|
||||
* Rollback transactions when the block returns earlier than expected.
|
||||
|
|
Loading…
Reference in a new issue