Skip to content

Commit cf269d5

Browse files
committed
Remove deprecated rake tasks:
* `db:schema:load_if_ruby` * `db:structure:dump` * `db:structure:load` * `db:structure:load_if_sql` * `db:structure:dump:#{name}` * `db:structure:load:#{name}` * `db:test:load_structure` * `db:test:load_structure:#{name}`
1 parent 7b9d4d2 commit cf269d5

File tree

6 files changed

+44
-216
lines changed

6 files changed

+44
-216
lines changed

activerecord/CHANGELOG.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,16 @@
1+
* Remove deprecated rake tasks:
2+
3+
* `db:schema:load_if_ruby`
4+
* `db:structure:dump`
5+
* `db:structure:load`
6+
* `db:structure:load_if_sql`
7+
* `db:structure:dump:#{name}`
8+
* `db:structure:load:#{name}`
9+
* `db:test:load_structure`
10+
* `db:test:load_structure:#{name}`
11+
12+
*Rafael Mendonça França*
13+
114
* Remove deprecated `DatabaseConfig#config` method.
215

316
*Rafael Mendonça França*

activerecord/lib/active_record/railties/databases.rake

Lines changed: 0 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -469,14 +469,6 @@ db_namespace = namespace :db do
469469
ActiveRecord::Tasks::DatabaseTasks.load_schema_current(ActiveRecord.schema_format, ENV["SCHEMA"])
470470
end
471471

472-
task load_if_ruby: ["db:create", :environment] do
473-
ActiveSupport::Deprecation.warn(<<-MSG.squish)
474-
Using `bin/rails db:schema:load_if_ruby` is deprecated and will be removed in Rails 7.0.
475-
Configure the format using `config.active_record.schema_format = :ruby` to use `schema.rb` and run `bin/rails db:schema:load` instead.
476-
MSG
477-
db_namespace["schema:load"].invoke if ActiveRecord.schema_format == :ruby
478-
end
479-
480472
namespace :dump do
481473
ActiveRecord::Tasks::DatabaseTasks.for_each(databases) do |name|
482474
desc "Creates a database schema file (either db/schema.rb or db/structure.sql, depending on `config.active_record.schema_format`) for #{name} database"
@@ -533,63 +525,6 @@ db_namespace = namespace :db do
533525
end
534526
end
535527

536-
namespace :structure do
537-
desc "Dumps the database structure to db/structure.sql. Specify another file with SCHEMA=db/my_structure.sql"
538-
task dump: :load_config do
539-
ActiveSupport::Deprecation.warn(<<-MSG.squish)
540-
Using `bin/rails db:structure:dump` is deprecated and will be removed in Rails 7.0.
541-
Configure the format using `config.active_record.schema_format = :sql` to use `structure.sql` and run `bin/rails db:schema:dump` instead.
542-
MSG
543-
544-
db_namespace["schema:dump"].invoke
545-
db_namespace["structure:dump"].reenable
546-
end
547-
548-
desc "Recreates the databases from the structure.sql file"
549-
task load: [:load_config, :check_protected_environments] do
550-
ActiveSupport::Deprecation.warn(<<-MSG.squish)
551-
Using `bin/rails db:structure:load` is deprecated and will be removed in Rails 7.0.
552-
Configure the format using `config.active_record.schema_format = :sql` to use `structure.sql` and run `bin/rails db:schema:load` instead.
553-
MSG
554-
db_namespace["schema:load"].invoke
555-
end
556-
557-
task load_if_sql: ["db:create", :environment] do
558-
ActiveSupport::Deprecation.warn(<<-MSG.squish)
559-
Using `bin/rails db:structure:load_if_sql` is deprecated and will be removed in Rails 7.0.
560-
Configure the format using `config.active_record.schema_format = :sql` to use `structure.sql` and run `bin/rails db:schema:load` instead.
561-
MSG
562-
db_namespace["schema:load"].invoke if ActiveRecord.schema_format == :sql
563-
end
564-
565-
namespace :dump do
566-
ActiveRecord::Tasks::DatabaseTasks.for_each(databases) do |name|
567-
desc "Dumps the #{name} database structure to db/structure.sql. Specify another file with SCHEMA=db/my_structure.sql"
568-
task name => :load_config do
569-
ActiveSupport::Deprecation.warn(<<-MSG.squish)
570-
Using `bin/rails db:structure:dump:#{name}` is deprecated and will be removed in Rails 7.0.
571-
Configure the format using `config.active_record.schema_format = :sql` to use `structure.sql` and run `bin/rails db:schema:dump:#{name}` instead.
572-
MSG
573-
db_namespace["schema:dump:#{name}"].invoke
574-
db_namespace["structure:dump:#{name}"].reenable
575-
end
576-
end
577-
end
578-
579-
namespace :load do
580-
ActiveRecord::Tasks::DatabaseTasks.for_each(databases) do |name|
581-
desc "Recreates the #{name} database from the structure.sql file"
582-
task name => :load_config do
583-
ActiveSupport::Deprecation.warn(<<-MSG.squish)
584-
Using `bin/rails db:structure:load:#{name}` is deprecated and will be removed in Rails 7.0.
585-
Configure the format using `config.active_record.schema_format = :sql` to use `structure.sql` and run `bin/rails db:schema:load:#{name}` instead.
586-
MSG
587-
db_namespace["schema:load:#{name}"].invoke
588-
end
589-
end
590-
end
591-
end
592-
593528
namespace :encryption do
594529
desc "Generate a set of keys for configuring Active Record encryption in a given environment"
595530
task :init do
@@ -623,15 +558,6 @@ db_namespace = namespace :db do
623558
end
624559
end
625560

626-
# desc "Recreate the test database from an existent structure.sql file"
627-
task load_structure: %w(db:test:purge) do
628-
ActiveSupport::Deprecation.warn(<<-MSG.squish)
629-
Using `bin/rails db:test:load_structure` is deprecated and will be removed in Rails 7.0.
630-
Configure the format using `config.active_record.schema_format = :sql` to use `structure.sql` and run `bin/rails db:test:load_schema` instead.
631-
MSG
632-
db_namespace["test:load_schema"].invoke
633-
end
634-
635561
# desc "Empty the test database"
636562
task purge: %w(load_config check_protected_environments) do
637563
ActiveRecord::Base.configurations.configs_for(env_name: "test").each do |db_config|
@@ -668,17 +594,6 @@ db_namespace = namespace :db do
668594
end
669595
end
670596

671-
# desc "Recreate the #{name} test database from an existent structure.sql file"
672-
namespace :load_structure do
673-
task name => "db:test:purge:#{name}" do
674-
ActiveSupport::Deprecation.warn(<<-MSG.squish)
675-
Using `bin/rails db:test:load_structure:#{name}` is deprecated and will be removed in Rails 7.0.
676-
Configure the format using `config.active_record.schema_format = :sql` to use `structure.sql` and run `bin/rails db:test:load_structure:#{name}` instead.
677-
MSG
678-
db_namespace["test:load_schema:#{name}"].invoke
679-
end
680-
end
681-
682597
# desc "Empty the #{name} test database"
683598
namespace :purge do
684599
task name => %w(load_config check_protected_environments) do

guides/source/7_0_release_notes.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,17 @@ Please refer to the [Changelog][active-record] for detailed changes.
126126

127127
* Remove deprecated `DatabaseConfig#config` method.
128128

129+
* Remove deprecated rake tasks:
130+
131+
* `db:schema:load_if_ruby`
132+
* `db:structure:dump`
133+
* `db:structure:load`
134+
* `db:structure:load_if_sql`
135+
* `db:structure:dump:#{name}`
136+
* `db:structure:load:#{name}`
137+
* `db:test:load_structure`
138+
* `db:test:load_structure:#{name}`
139+
129140
### Deprecations
130141

131142
### Notable changes

railties/test/application/rake/dbs_test.rb

Lines changed: 1 addition & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -471,63 +471,6 @@ def db_fixtures_load(expected_database)
471471
assert_equal 2, Admin::Book.count
472472
end
473473

474-
def db_structure_dump_and_load(expected_database)
475-
Dir.chdir(app_path) do
476-
rails "generate", "model", "book", "title:string"
477-
rails "db:migrate", "db:structure:dump"
478-
structure_dump = File.read("db/structure.sql")
479-
assert_match(/CREATE TABLE (?:IF NOT EXISTS )?"books"/, structure_dump)
480-
rails "environment", "db:drop", "db:structure:load"
481-
assert_match expected_database, ActiveRecord::Base.connection_db_config.database
482-
require "#{app_path}/app/models/book"
483-
# if structure is not loaded correctly, exception would be raised
484-
assert_equal 0, Book.count
485-
end
486-
end
487-
488-
["dump", "load"].each do |command|
489-
test "db:structure:#{command} is deprecated" do
490-
add_to_config("config.active_support.deprecation = :stderr")
491-
stderr_output = capture(:stderr) { rails("db:structure:#{command}", stderr: true, allow_failure: true) }
492-
assert_match(/DEPRECATION WARNING: Using `bin\/rails db:structure:#{command}` is deprecated and will be removed in Rails 7.0/, stderr_output)
493-
end
494-
end
495-
496-
test "db:structure:dump and db:structure:load without database_url" do
497-
add_to_config "config.active_record.schema_format = :sql"
498-
require "#{app_path}/config/environment"
499-
db_config = ActiveRecord::Base.connection_db_config
500-
db_structure_dump_and_load db_config.database
501-
end
502-
503-
test "db:structure:dump and db:structure:load with database_url" do
504-
add_to_config "config.active_record.schema_format = :sql"
505-
require "#{app_path}/config/environment"
506-
set_database_url
507-
db_structure_dump_and_load database_url_db_name
508-
end
509-
510-
test "db:structure:dump and db:structure:load set ar_internal_metadata" do
511-
add_to_config "config.active_record.schema_format = :sql"
512-
require "#{app_path}/config/environment"
513-
db_config = ActiveRecord::Base.connection_db_config
514-
db_structure_dump_and_load db_config.database
515-
516-
assert_equal "test", rails("runner", "-e", "test", "puts ActiveRecord::InternalMetadata[:environment]").strip
517-
assert_equal "development", rails("runner", "puts ActiveRecord::InternalMetadata[:environment]").strip
518-
end
519-
520-
test "db:structure:dump does not dump schema information when no migrations are used" do
521-
add_to_config "config.active_record.schema_format = :sql"
522-
# create table without migrations
523-
rails "runner", "ActiveRecord::Base.connection.create_table(:posts) {|t| t.string :title }"
524-
525-
stderr_output = capture(:stderr) { rails("db:structure:dump", stderr: true, allow_failure: true) }
526-
assert_empty stderr_output
527-
structure_dump = File.read("#{app_path}/db/structure.sql")
528-
assert_match(/CREATE TABLE (?:IF NOT EXISTS )?"posts"/, structure_dump)
529-
end
530-
531474
test "db:schema:load and db:structure:load do not purge the existing database" do
532475
rails "runner", "ActiveRecord::Base.connection.create_table(:posts) {|t| t.string :title }"
533476

@@ -548,7 +491,7 @@ def db_structure_dump_and_load(expected_database)
548491
CREATE TABLE "users" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "name" varchar(255));
549492
SQL
550493

551-
rails "db:structure:load"
494+
rails "db:schema:load"
552495
assert_equal '["posts", "comments", "schema_migrations", "ar_internal_metadata", "users"]', list_tables[]
553496
end
554497

@@ -583,32 +526,6 @@ def db_structure_dump_and_load(expected_database)
583526
assert_match(/Run `bin\/rails db:migrate` to create it/, stderr_output)
584527
end
585528

586-
def db_test_load_structure
587-
Dir.chdir(app_path) do
588-
rails "generate", "model", "book", "title:string"
589-
rails "db:migrate", "db:structure:dump", "db:test:load_structure"
590-
ActiveRecord::Base.configurations = Rails.application.config.database_configuration
591-
ActiveRecord::Base.establish_connection :test
592-
require "#{app_path}/app/models/book"
593-
# if structure is not loaded correctly, exception would be raised
594-
assert_equal 0, Book.count
595-
db_config = ActiveRecord::Base.configurations.configs_for(env_name: "test", name: "primary")
596-
assert_match db_config.database, ActiveRecord::Base.connection_db_config.database
597-
end
598-
end
599-
600-
test "db:test:load_structure without database_url" do
601-
add_to_config "config.active_record.schema_format = :sql"
602-
require "#{app_path}/config/environment"
603-
db_test_load_structure
604-
end
605-
606-
test "db:test:load_structure is deprecated" do
607-
add_to_config("config.active_support.deprecation = :stderr")
608-
stderr_output = capture(:stderr) { rails("db:test:load_structure", stderr: true, allow_failure: true) }
609-
assert_match(/DEPRECATION WARNING: Using `bin\/rails db:test:load_structure` is deprecated and will be removed in Rails 7.0/, stderr_output)
610-
end
611-
612529
test "db:setup loads schema and seeds database" do
613530
@old_rails_env = ENV["RAILS_ENV"]
614531
@old_rack_env = ENV["RACK_ENV"]

railties/test/application/rake/multi_dbs_test.rb

Lines changed: 19 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -115,34 +115,37 @@ def db_migrate_and_schema_dump_and_load(schema_format = "ruby")
115115
end
116116
end
117117

118-
def db_migrate_and_schema_dump_and_load_one_database(format, database)
118+
def db_migrate_and_schema_dump_and_load_one_database(database, schema_format)
119+
add_to_config "config.active_record.schema_format = :#{schema_format}"
120+
require "#{app_path}/config/environment"
121+
119122
Dir.chdir(app_path) do
120123
generate_models_for_animals
121-
rails "db:migrate:#{database}", "db:#{format}:dump:#{database}"
124+
rails "db:migrate:#{database}", "db:schema:dump:#{database}"
122125

123-
if format == "schema"
126+
if schema_format == "ruby"
124127
if database == "primary"
125-
schema_dump = File.read("db/#{format}.rb")
126-
assert_not(File.exist?("db/animals_#{format}.rb"))
128+
schema_dump = File.read("db/schema.rb")
129+
assert_not(File.exist?("db/animals_schema.rb"))
127130
assert_match(/create_table "books"/, schema_dump)
128131
else
129-
assert_not(File.exist?("db/#{format}.rb"))
130-
schema_dump_animals = File.read("db/animals_#{format}.rb")
132+
assert_not(File.exist?("db/schema.rb"))
133+
schema_dump_animals = File.read("db/animals_schema.rb")
131134
assert_match(/create_table "dogs"/, schema_dump_animals)
132135
end
133136
else
134137
if database == "primary"
135-
schema_dump = File.read("db/#{format}.sql")
136-
assert_not(File.exist?("db/animals_#{format}.sql"))
138+
schema_dump = File.read("db/structure.sql")
139+
assert_not(File.exist?("db/animals_structure.sql"))
137140
assert_match(/CREATE TABLE (?:IF NOT EXISTS )?"books"/, schema_dump)
138141
else
139-
assert_not(File.exist?("db/#{format}.sql"))
140-
schema_dump_animals = File.read("db/animals_#{format}.sql")
142+
assert_not(File.exist?("db/structure.sql"))
143+
schema_dump_animals = File.read("db/animals_structure.sql")
141144
assert_match(/CREATE TABLE (?:IF NOT EXISTS )?"dogs"/, schema_dump_animals)
142145
end
143146
end
144147

145-
rails "db:#{format}:load:#{database}"
148+
rails "db:schema:load:#{database}"
146149

147150
ar_tables = lambda { rails("runner", "p ActiveRecord::Base.connection.tables").strip }
148151
animals_tables = lambda { rails("runner", "p AnimalsBase.connection.tables").strip }
@@ -584,44 +587,19 @@ def change
584587
end
585588

586589
test "db:migrate:name and db:schema:dump:name and db:schema:load:name works for the primary database" do
587-
require "#{app_path}/config/environment"
588-
db_migrate_and_schema_dump_and_load_one_database("schema", "primary")
590+
db_migrate_and_schema_dump_and_load_one_database("primary", "ruby")
589591
end
590592

591593
test "db:migrate:name and db:schema:dump:name and db:schema:load:name works for the animals database" do
592-
require "#{app_path}/config/environment"
593-
db_migrate_and_schema_dump_and_load_one_database("schema", "animals")
594-
end
595-
596-
["dump", "load"].each do |command|
597-
test "db:structure:#{command}:NAME is deprecated" do
598-
app_file "config/database.yml", <<-YAML
599-
default: &default
600-
adapter: sqlite3
601-
development:
602-
primary:
603-
<<: *default
604-
animals:
605-
<<: *default
606-
database: db/animals_development.sqlite3
607-
YAML
608-
609-
add_to_config("config.active_support.deprecation = :stderr")
610-
stderr_output = capture(:stderr) { rails("db:structure:#{command}:animals", stderr: true, allow_failure: true) }
611-
assert_match(/DEPRECATION WARNING: Using `bin\/rails db:structure:#{command}:animals` is deprecated and will be removed in Rails 7.0/, stderr_output)
612-
end
594+
db_migrate_and_schema_dump_and_load_one_database("animals", "ruby")
613595
end
614596

615597
test "db:migrate:name and db:structure:dump:name and db:structure:load:name works for the primary database" do
616-
add_to_config "config.active_record.schema_format = :sql"
617-
require "#{app_path}/config/environment"
618-
db_migrate_and_schema_dump_and_load_one_database("structure", "primary")
598+
db_migrate_and_schema_dump_and_load_one_database("primary", "sql")
619599
end
620600

621601
test "db:migrate:name and db:structure:dump:name and db:structure:load:name works for the animals database" do
622-
add_to_config "config.active_record.schema_format = :sql"
623-
require "#{app_path}/config/environment"
624-
db_migrate_and_schema_dump_and_load_one_database("structure", "animals")
602+
db_migrate_and_schema_dump_and_load_one_database("animals", "sql")
625603
end
626604

627605
test "db:test:prepare:name works for the primary database with a ruby schema" do

railties/test/application/rake_test.rb

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -272,12 +272,6 @@ def test_db_test_prepare_when_using_sql_format
272272
assert_match(/Execute db:test:load_schema/, output)
273273
end
274274

275-
def test_rake_dump_structure_should_respect_db_structure_env_variable
276-
# ensure we have a schema_migrations table to dump
277-
rails "db:migrate", "db:structure:dump", "SCHEMA=db/my_structure.sql"
278-
assert File.exist?(File.join(app_path, "db", "my_structure.sql"))
279-
end
280-
281275
def test_rake_dump_structure_should_be_called_twice_when_migrate_redo
282276
add_to_config "config.active_record.schema_format = :sql"
283277

0 commit comments

Comments
 (0)