提交 54886868 编写于 作者: F fatkodima

Combine and deprecate `rails db:structure:{dump,load}` tasks into `rails db:schema:{dump,load}`

上级 7c32f09c
* Deprecate `rails db:structure:{load, dump}` tasks and extend
`rails db:schema:{load, dump}` tasks to work with either `:ruby` or `:sql` format,
depending on `config.active_record.schema_format` configuration value.
*fatkodima*
* Allow attribute's default to be configured but keeping its own type.
```ruby
......
......@@ -104,7 +104,7 @@ def self.configurations
##
# :singleton-method:
# Specifies which database schemas to dump when calling db:structure:dump.
# Specifies which database schemas to dump when calling db:schema:dump.
# If the value is :schema_search_path (the default), any schemas listed in
# schema_search_path are dumped. Use :all to dump all schemas regardless
# of schema_search_path, or a string of comma separated schemas for a
......
......@@ -2,6 +2,7 @@
require "active_record"
require "active_support/configuration_file"
require "active_support/deprecation"
databases = ActiveRecord::Tasks::DatabaseTasks.setup_initial_database_yaml
......@@ -95,12 +96,7 @@ db_namespace = namespace :db do
# IMPORTANT: This task won't dump the schema if ActiveRecord::Base.dump_schema_after_migration is set to false
task :_dump do
if ActiveRecord::Base.dump_schema_after_migration
case ActiveRecord::Base.schema_format
when :ruby then db_namespace["schema:dump"].invoke
when :sql then db_namespace["structure:dump"].invoke
else
raise "unknown schema format #{ActiveRecord::Base.schema_format}"
end
db_namespace["schema:dump"].invoke
end
# Allow this task to be called as many times as required. An example is the
# migrate:redo task, which calls other two internally that depend on this one.
......@@ -112,12 +108,7 @@ db_namespace = namespace :db do
# IMPORTANT: This task won't dump the schema if ActiveRecord::Base.dump_schema_after_migration is set to false
task name do
if ActiveRecord::Base.dump_schema_after_migration
case ActiveRecord::Base.schema_format
when :ruby then db_namespace["schema:dump:#{name}"].invoke
when :sql then db_namespace["structure:dump:#{name}"].invoke
else
raise "unknown schema format #{ActiveRecord::Base.schema_format}"
end
db_namespace["schema:dump:#{name}"].invoke
end
# Allow this task to be called as many times as required. An example is the
# migrate:redo task, which calls other two internally that depend on this one.
......@@ -356,7 +347,7 @@ db_namespace = namespace :db do
end
desc "Creates the database, loads the schema, and initializes with the seed data (use db:reset to also drop the database first)"
task setup: ["db:schema:load_if_ruby", "db:structure:load_if_sql", :seed]
task setup: ["db:create", :environment, "db:schema:load", :seed]
desc "Runs setup if database does not exist, or runs migrations if it does"
task prepare: :load_config do
......@@ -446,32 +437,28 @@ db_namespace = namespace :db do
end
namespace :schema do
desc "Creates a db/schema.rb file that is portable against any DB supported by Active Record"
desc "Creates a database schema file (either db/schema.rb or db/structure.sql, depending on `config.active_record.schema_format`)"
task dump: :load_config do
ActiveRecord::Base.configurations.configs_for(env_name: ActiveRecord::Tasks::DatabaseTasks.env).each do |db_config|
ActiveRecord::Base.establish_connection(db_config)
ActiveRecord::Tasks::DatabaseTasks.dump_schema(db_config, :ruby)
ActiveRecord::Tasks::DatabaseTasks.dump_schema(db_config)
end
db_namespace["schema:dump"].reenable
end
desc "Loads a schema.rb file into the database"
desc "Loads a database schema file (either db/schema.rb or db/structure.sql, depending on `config.active_record.schema_format`) into the database"
task load: [:load_config, :check_protected_environments] do
ActiveRecord::Tasks::DatabaseTasks.load_schema_current(:ruby, ENV["SCHEMA"])
end
task load_if_ruby: ["db:create", :environment] do
db_namespace["schema:load"].invoke if ActiveRecord::Base.schema_format == :ruby
ActiveRecord::Tasks::DatabaseTasks.load_schema_current(ActiveRecord::Base.schema_format, ENV["SCHEMA"])
end
namespace :dump do
ActiveRecord::Tasks::DatabaseTasks.for_each(databases) do |name|
desc "Creates a db/schema.rb file that is portable against any DB supported by Active Record for #{name} database"
desc "Creates a database schema file (either db/schema.rb or db/structure.sql, depending on `config.active_record.schema_format`) for #{name} database"
task name => :load_config do
db_config = ActiveRecord::Base.configurations.configs_for(env_name: ActiveRecord::Tasks::DatabaseTasks.env, name: name)
ActiveRecord::Base.establish_connection(db_config)
ActiveRecord::Tasks::DatabaseTasks.dump_schema(db_config, :ruby)
ActiveRecord::Tasks::DatabaseTasks.dump_schema(db_config)
db_namespace["schema:dump:#{name}"].reenable
end
end
......@@ -479,10 +466,10 @@ db_namespace = namespace :db do
namespace :load do
ActiveRecord::Tasks::DatabaseTasks.for_each(databases) do |name|
desc "Loads a schema.rb file into the #{name} database"
desc "Loads a database schema file (either db/schema.rb or db/structure.sql, depending on `config.active_record.schema_format`) into the #{name} database"
task name => :load_config do
db_config = ActiveRecord::Base.configurations.configs_for(env_name: ActiveRecord::Tasks::DatabaseTasks.env, name: name)
ActiveRecord::Tasks::DatabaseTasks.load_schema(db_config, :ruby, ENV["SCHEMA"])
ActiveRecord::Tasks::DatabaseTasks.load_schema(db_config, ActiveRecord::Base.schema_format, ENV["SCHEMA"])
end
end
end
......@@ -521,30 +508,33 @@ db_namespace = namespace :db do
namespace :structure do
desc "Dumps the database structure to db/structure.sql. Specify another file with SCHEMA=db/my_structure.sql"
task dump: :load_config do
ActiveRecord::Base.configurations.configs_for(env_name: ActiveRecord::Tasks::DatabaseTasks.env).each do |db_config|
ActiveRecord::Base.establish_connection(db_config)
ActiveRecord::Tasks::DatabaseTasks.dump_schema(db_config, :sql)
end
ActiveSupport::Deprecation.warn(<<-MSG.squish)
Using `bin/rails db:structure:dump` is deprecated and will be removed in Rails 6.2.
Configure the format using `config.active_record.schema_format = :sql` to use `structure.sql` and run `bin/rails db:schema:dump` instead.
MSG
db_namespace["schema:dump"].invoke
db_namespace["structure:dump"].reenable
end
desc "Recreates the databases from the structure.sql file"
task load: [:load_config, :check_protected_environments] do
ActiveRecord::Tasks::DatabaseTasks.load_schema_current(:sql, ENV["SCHEMA"])
end
task load_if_sql: ["db:create", :environment] do
db_namespace["structure:load"].invoke if ActiveRecord::Base.schema_format == :sql
ActiveSupport::Deprecation.warn(<<-MSG.squish)
Using `bin/rails db:structure:load` is deprecated and will be removed in Rails 6.2.
Configure the format using `config.active_record.schema_format = :sql` to use `structure.sql` and run `bin/rails db:schema:load` instead.
MSG
db_namespace["schema:load"].invoke
end
namespace :dump do
ActiveRecord::Tasks::DatabaseTasks.for_each(databases) do |name|
desc "Dumps the #{name} database structure to db/structure.sql. Specify another file with SCHEMA=db/my_structure.sql"
task name => :load_config do
db_config = ActiveRecord::Base.configurations.configs_for(env_name: ActiveRecord::Tasks::DatabaseTasks.env, name: name)
ActiveRecord::Base.establish_connection(db_config)
ActiveRecord::Tasks::DatabaseTasks.dump_schema(db_config, :sql)
ActiveSupport::Deprecation.warn(<<-MSG.squish)
Using `bin/rails db:structure:dump:#{name}` is deprecated and will be removed in Rails 6.2.
Configure the format using `config.active_record.schema_format = :sql` to use `structure.sql` and run `bin/rails db:schema:dump:#{name}` instead.
MSG
db_namespace["schema:dump:#{name}"].invoke
db_namespace["structure:dump:#{name}"].reenable
end
end
......@@ -554,8 +544,11 @@ db_namespace = namespace :db do
ActiveRecord::Tasks::DatabaseTasks.for_each(databases) do |name|
desc "Recreates the #{name} database from the structure.sql file"
task name => :load_config do
db_config = ActiveRecord::Base.configurations.configs_for(env_name: ActiveRecord::Tasks::DatabaseTasks.env, name: name)
ActiveRecord::Tasks::DatabaseTasks.load_schema(db_config, :sql, ENV["SCHEMA"])
ActiveSupport::Deprecation.warn(<<-MSG.squish)
Using `bin/rails db:structure:load:#{name}` is deprecated and will be removed in Rails 6.2.
Configure the format using `config.active_record.schema_format = :sql` to use `structure.sql` and run `bin/rails db:schema:load:#{name}` instead.
MSG
db_namespace["schema:load:#{name}"].invoke
end
end
end
......@@ -564,21 +557,16 @@ db_namespace = namespace :db do
namespace :test do
# desc "Recreate the test database from the current schema"
task load: %w(db:test:purge) do
case ActiveRecord::Base.schema_format
when :ruby
db_namespace["test:load_schema"].invoke
when :sql
db_namespace["test:load_structure"].invoke
end
db_namespace["test:load_schema"].invoke
end
# desc "Recreate the test database from an existent schema.rb file"
# desc "Recreate the test database from an existent schema file (schema.rb or structure.sql, depending on `config.active_record.schema_format`)"
task load_schema: %w(db:test:purge) do
should_reconnect = ActiveRecord::Base.connection_pool.active_connection?
ActiveRecord::Schema.verbose = false
ActiveRecord::Base.configurations.configs_for(env_name: "test").each do |db_config|
filename = ActiveRecord::Tasks::DatabaseTasks.dump_filename(db_config.name, :ruby)
ActiveRecord::Tasks::DatabaseTasks.load_schema(db_config, :ruby, filename)
filename = ActiveRecord::Tasks::DatabaseTasks.dump_filename(db_config.name)
ActiveRecord::Tasks::DatabaseTasks.load_schema(db_config, ActiveRecord::Base.schema_format, filename)
end
ensure
if should_reconnect
......@@ -588,10 +576,11 @@ db_namespace = namespace :db do
# desc "Recreate the test database from an existent structure.sql file"
task load_structure: %w(db:test:purge) do
ActiveRecord::Base.configurations.configs_for(env_name: "test").each do |db_config|
filename = ActiveRecord::Tasks::DatabaseTasks.dump_filename(db_config.name, :sql)
ActiveRecord::Tasks::DatabaseTasks.load_schema(db_config, :sql, filename)
end
ActiveSupport::Deprecation.warn(<<-MSG.squish)
Using `bin/rails db:test:load_structure` is deprecated and will be removed in Rails 6.2.
Configure the format using `config.active_record.schema_format = :sql` to use `structure.sql` and run `bin/rails db:test:load_schema` instead.
MSG
db_namespace["test:load_schema"].invoke
end
# desc "Empty the test database"
......@@ -612,12 +601,7 @@ db_namespace = namespace :db do
# desc "Recreate the #{name} test database"
namespace :load do
task name => "db:test:purge:#{name}" do
case ActiveRecord::Base.schema_format
when :ruby
db_namespace["test:load_schema:#{name}"].invoke
when :sql
db_namespace["test:load_structure:#{name}"].invoke
end
db_namespace["test:load_schema:#{name}"].invoke
end
end
......@@ -626,9 +610,9 @@ db_namespace = namespace :db do
task name => "db:test:purge:#{name}" do
should_reconnect = ActiveRecord::Base.connection_pool.active_connection?
ActiveRecord::Schema.verbose = false
filename = ActiveRecord::Tasks::DatabaseTasks.dump_filename(name, :ruby)
filename = ActiveRecord::Tasks::DatabaseTasks.dump_filename(name)
db_config = ActiveRecord::Base.configurations.configs_for(env_name: "test", name: name)
ActiveRecord::Tasks::DatabaseTasks.load_schema(db_config, :ruby, filename)
ActiveRecord::Tasks::DatabaseTasks.load_schema(db_config, ActiveRecord::Base.schema_format, filename)
ensure
if should_reconnect
ActiveRecord::Base.establish_connection(ActiveRecord::Tasks::DatabaseTasks.env.to_sym)
......@@ -639,9 +623,11 @@ db_namespace = namespace :db do
# desc "Recreate the #{name} test database from an existent structure.sql file"
namespace :load_structure do
task name => "db:test:purge:#{name}" do
filename = ActiveRecord::Tasks::DatabaseTasks.dump_filename(name, :sql)
db_config = ActiveRecord::Base.configurations.configs_for(env_name: "test", name: name)
ActiveRecord::Tasks::DatabaseTasks.load_schema(db_config, :sql, filename)
ActiveSupport::Deprecation.warn(<<-MSG.squish)
Using `bin/rails db:test:load_structure:#{name}` is deprecated and will be removed in Rails 6.2.
Configure the format using `config.active_record.schema_format = :sql` to use `structure.sql` and run `bin/rails db:test:load_structure:#{name}` instead.
MSG
db_namespace["test:load_schema:#{name}"].invoke
end
end
......
......@@ -38,12 +38,12 @@ class DatabaseNotSupported < StandardError; end # :nodoc:
module DatabaseTasks
##
# :singleton-method:
# Extra flags passed to database CLI tool (mysqldump/pg_dump) when calling db:structure:dump
# Extra flags passed to database CLI tool (mysqldump/pg_dump) when calling db:schema:dump
mattr_accessor :structure_dump_flags, instance_accessor: false
##
# :singleton-method:
# Extra flags passed to database CLI tool when calling db:structure:load
# Extra flags passed to database CLI tool when calling db:schema:load
mattr_accessor :structure_load_flags, instance_accessor: false
extend self
......
......@@ -978,7 +978,7 @@ using a tool specific to the database into `db/structure.sql`. For example, for
PostgreSQL, the `pg_dump` utility is used. For MySQL and MariaDB, this file will
contain the output of `SHOW CREATE TABLE` for the various tables.
To load the schema from `db/structure.sql`, run `bin/rails db:structure:load`.
To load the schema from `db/structure.sql`, run `bin/rails db:schema:load`.
Loading this file is done by executing the SQL statements it contains. By
definition, this will create a perfect copy of the database's structure.
......
......@@ -152,18 +152,12 @@ rails db:migrate:status:primary # Display status of migrations for prim
rails db:rollback # Rolls the schema back to the previous version (specify steps w/ STEP=n)
rails db:rollback:animals # Rollback animals database for current environment (specify steps w/ STEP=n)
rails db:rollback:primary # Rollback primary database for current environment (specify steps w/ STEP=n)
rails db:schema:dump # Creates a db/schema.rb file that is portable against any DB supported ...
rails db:schema:dump:animals # Creates a db/schema.rb file that is portable against any DB supported ...
rails db:schema:dump # Creates a database schema file (either db/schema.rb or db/structure.sql ...
rails db:schema:dump:animals # Creates a database schema file (either db/schema.rb or db/structure.sql ...
rails db:schema:dump:primary # Creates a db/schema.rb file that is portable against any DB supported ...
rails db:schema:load # Loads a schema.rb file into the database
rails db:schema:load:animals # Loads a schema.rb file into the animals database
rails db:schema:load:primary # Loads a schema.rb file into the primary database
rails db:structure:dump # Dumps the database structure to db/structure.sql. Specify another file ...
rails db:structure:dump:animals # Dumps the animals database structure to sdb/structure.sql. Specify another ...
rails db:structure:dump:primary # Dumps the primary database structure to db/structure.sql. Specify another ...
rails db:structure:load # Recreates the databases from the structure.sql file
rails db:structure:load:animals # Recreates the animals database from the structure.sql file
rails db:structure:load:primary # Recreates the primary database from the structure.sql file
rails db:schema:load # Loads a database schema file (either db/schema.rb or db/structure.sql ...
rails db:schema:load:animals # Loads a database schema file (either db/schema.rb or db/structure.sql ...
rails db:schema:load:primary # Loads a database schema file (either db/schema.rb or db/structure.sql ...
```
Running a command like `bin/rails db:create` will create both the primary and animals databases.
......
......@@ -56,11 +56,9 @@ In addition to those commands, there are:
db:rollback Rolls the schema back to ...
db:schema:cache:clear Clears a db/schema_cache.yml file
db:schema:cache:dump Creates a db/schema_cache.yml file
db:schema:dump Creates a db/schema.rb file ...
db:schema:load Loads a schema.rb file ...
db:schema:dump Creates a database schema file (either db/schema.rb or db/structure.sql ...
db:schema:load Loads a database schema file (either db/schema.rb or db/structure.sql ...
db:seed Loads the seed data ...
db:structure:dump Dumps the database structure ...
db:structure:load Recreates the databases ...
db:version Retrieves the current schema ...
...
restart Restart app by touching ...
......
......@@ -429,7 +429,7 @@ in controllers and views. This defaults to `false`.
`config/environments/production.rb` which is generated by Rails. The
default value is `true` if this configuration is not set.
* `config.active_record.dump_schemas` controls which database schemas will be dumped when calling `db:structure:dump`.
* `config.active_record.dump_schemas` controls which database schemas will be dumped when calling `db:schema:dump`.
The options are `:schema_search_path` (the default) which dumps any schemas listed in `schema_search_path`,
`:all` which always dumps all schemas regardless of the `schema_search_path`,
or a string of comma separated schemas.
......
......@@ -53,7 +53,7 @@ namespace :db do
desc "Rolls the schema back to the previous version (specify steps w/ STEP=n)."
app_task "rollback"
desc "Create a db/schema.rb file that can be portably used against any database supported by Active Record"
desc "Creates a database schema file (either db/schema.rb or db/structure.sql, depending on `config.active_record.schema_format`)"
app_task "schema:dump"
desc "Load a schema.rb file into the database"
......@@ -65,9 +65,6 @@ namespace :db do
desc "Create the database, load the schema, and initialize with the seed data (use db:reset to also drop the database first)"
app_task "setup"
desc "Dump the database structure to an SQL file"
app_task "structure:dump"
desc "Retrieves the current schema version number"
app_task "version"
......
......@@ -488,19 +488,30 @@ def db_structure_dump_and_load(expected_database)
end
end
["dump", "load"].each do |command|
test "db:structure:#{command} is deprecated" do
add_to_config("config.active_support.deprecation = :stderr")
stderr_output = capture(:stderr) { rails("db:structure:#{command}", stderr: true, allow_failure: true) }
assert_match(/DEPRECATION WARNING: Using `bin\/rails db:structure:#{command}` is deprecated and will be removed in Rails 6.2/, stderr_output)
end
end
test "db:structure:dump and db:structure:load without database_url" do
add_to_config "config.active_record.schema_format = :sql"
require "#{app_path}/config/environment"
db_config = ActiveRecord::Base.connection_db_config
db_structure_dump_and_load db_config.database
end
test "db:structure:dump and db:structure:load with database_url" do
add_to_config "config.active_record.schema_format = :sql"
require "#{app_path}/config/environment"
set_database_url
db_structure_dump_and_load database_url_db_name
end
test "db:structure:dump and db:structure:load set ar_internal_metadata" do
add_to_config "config.active_record.schema_format = :sql"
require "#{app_path}/config/environment"
db_config = ActiveRecord::Base.connection_db_config
db_structure_dump_and_load db_config.database
......@@ -510,6 +521,7 @@ def db_structure_dump_and_load(expected_database)
end
test "db:structure:dump does not dump schema information when no migrations are used" do
add_to_config "config.active_record.schema_format = :sql"
# create table without migrations
rails "runner", "ActiveRecord::Base.connection.create_table(:posts) {|t| t.string :title }"
......@@ -534,6 +546,7 @@ def db_structure_dump_and_load(expected_database)
rails "db:schema:load"
assert_equal '["posts", "comments", "schema_migrations", "ar_internal_metadata"]', list_tables[]
add_to_config "config.active_record.schema_format = :sql"
app_file "db/structure.sql", <<-SQL
CREATE TABLE "users" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "name" varchar(255));
SQL
......@@ -588,10 +601,17 @@ def db_test_load_structure
end
test "db:test:load_structure without database_url" do
add_to_config "config.active_record.schema_format = :sql"
require "#{app_path}/config/environment"
db_test_load_structure
end
test "db:test:load_structure is deprecated" do
add_to_config("config.active_support.deprecation = :stderr")
stderr_output = capture(:stderr) { rails("db:test:load_structure", stderr: true, allow_failure: true) }
assert_match(/DEPRECATION WARNING: Using `bin\/rails db:test:load_structure` is deprecated and will be removed in Rails 6.2/, stderr_output)
end
test "db:setup loads schema and seeds database" do
@old_rails_env = ENV["RAILS_ENV"]
@old_rack_env = ENV["RACK_ENV"]
......
......@@ -85,24 +85,27 @@ def db_migrate_and_schema_cache_dump_and_schema_cache_clear
end
end
def db_migrate_and_schema_dump_and_load(format)
def db_migrate_and_schema_dump_and_load(schema_format)
add_to_config "config.active_record.schema_format = :#{schema_format}"
require "#{app_path}/config/environment"
Dir.chdir(app_path) do
generate_models_for_animals
rails "db:migrate", "db:#{format}:dump"
rails "db:migrate", "db:schema:dump"
if format == "schema"
schema_dump = File.read("db/#{format}.rb")
schema_dump_animals = File.read("db/animals_#{format}.rb")
if schema_format == "ruby"
schema_dump = File.read("db/schema.rb")
schema_dump_animals = File.read("db/animals_schema.rb")
assert_match(/create_table \"books\"/, schema_dump)
assert_match(/create_table \"dogs\"/, schema_dump_animals)
else
schema_dump = File.read("db/#{format}.sql")
schema_dump_animals = File.read("db/animals_#{format}.sql")
schema_dump = File.read("db/structure.sql")
schema_dump_animals = File.read("db/animals_structure.sql")
assert_match(/CREATE TABLE (?:IF NOT EXISTS )?\"books\"/, schema_dump)
assert_match(/CREATE TABLE (?:IF NOT EXISTS )?\"dogs\"/, schema_dump_animals)
end
rails "db:#{format}:load"
rails "db:schema:load"
ar_tables = lambda { rails("runner", "p ActiveRecord::Base.connection.tables").strip }
animals_tables = lambda { rails("runner", "p AnimalsBase.connection.tables").strip }
......@@ -199,20 +202,10 @@ def db_test_prepare_name(name, schema_format)
Dir.chdir(app_path) do
generate_models_for_animals
if schema_format == "ruby"
dump_command = "db:schema:dump:#{name}"
else
dump_command = "db:structure:dump:#{name}"
end
rails("db:migrate:#{name}", dump_command)
rails("db:migrate:#{name}", "db:schema:dump:#{name}")
output = rails("db:test:prepare:#{name}", "--trace")
if schema_format == "ruby"
assert_match(/Execute db:test:load_schema:#{name}/, output)
else
assert_match(/Execute db:test:load_structure:#{name}/, output)
end
assert_match(/Execute db:test:load_schema:#{name}/, output)
ar_tables = lambda { rails("runner", "-e", "test", "p ActiveRecord::Base.connection.tables").strip }
animals_tables = lambda { rails("runner", "-e", "test", "p AnimalsBase.connection.tables").strip }
......@@ -435,16 +428,13 @@ def generate_models_for_animals
end
test "db:migrate and db:schema:dump and db:schema:load works on all databases" do
require "#{app_path}/config/environment"
db_migrate_and_schema_dump_and_load "schema"
db_migrate_and_schema_dump_and_load "ruby"
end
test "db:migrate and db:structure:dump and db:structure:load works on all databases" do
require "#{app_path}/config/environment"
db_migrate_and_schema_dump_and_load "structure"
test "db:migrate and db:schema:dump and db:schema:load works on all databases with sql option" do
db_migrate_and_schema_dump_and_load "sql"
end
test "db:migrate:name dumps the schema for the primary database" do
db_migrate_name_dumps_the_schema("primary", "ruby")
end
......@@ -471,12 +461,33 @@ def generate_models_for_animals
db_migrate_and_schema_dump_and_load_one_database("schema", "animals")
end
["dump", "load"].each do |command|
test "db:structure:#{command}:NAME is deprecated" do
app_file "config/database.yml", <<-YAML
default: &default
adapter: sqlite3
development:
primary:
<<: *default
animals:
<<: *default
database: db/animals_development.sqlite3
YAML
add_to_config("config.active_support.deprecation = :stderr")
stderr_output = capture(:stderr) { rails("db:structure:#{command}:animals", stderr: true, allow_failure: true) }
assert_match(/DEPRECATION WARNING: Using `bin\/rails db:structure:#{command}:animals` is deprecated and will be removed in Rails 6.2/, stderr_output)
end
end
test "db:migrate:name and db:structure:dump:name and db:structure:load:name works for the primary database" do
add_to_config "config.active_record.schema_format = :sql"
require "#{app_path}/config/environment"
db_migrate_and_schema_dump_and_load_one_database("structure", "primary")
end
test "db:migrate:name and db:structure:dump:name and db:structure:load:name works for the animals database" do
add_to_config "config.active_record.schema_format = :sql"
require "#{app_path}/config/environment"
db_migrate_and_schema_dump_and_load_one_database("structure", "animals")
end
......@@ -681,7 +692,7 @@ class TwoMigration < ActiveRecord::Migration::Current
ENV.delete "RAILS_ENV"
ENV.delete "RACK_ENV"
db_migrate_and_schema_dump_and_load "schema"
db_migrate_and_schema_dump_and_load "ruby"
app_file "db/seeds.rb", <<-RUBY
print Book.connection.pool.db_config.database
......
......@@ -244,7 +244,7 @@ def test_db_test_prepare_when_using_sql_format
rails "generate", "scaffold", "user", "username:string"
rails "db:migrate"
output = rails("db:test:prepare", "--trace")
assert_match(/Execute db:test:load_structure/, output)
assert_match(/Execute db:test:load_schema/, output)
end
def test_rake_dump_structure_should_respect_db_structure_env_variable
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册