diff --git a/activerecord/lib/active_record/railties/databases.rake b/activerecord/lib/active_record/railties/databases.rake index 5661bde6f2db0..9af73c6e69650 100644 --- a/activerecord/lib/active_record/railties/databases.rake +++ b/activerecord/lib/active_record/railties/databases.rake @@ -176,7 +176,7 @@ db_namespace = namespace :db do end # desc 'Resets your database using your migrations for the current environment' - task reset: ["db:drop", "db:create", "db:migrate"] + task reset: ["db:drop", "db:create", "db:schema:dump", "db:migrate"] desc 'Run the "up" for a given migration VERSION.' task up: :load_config do diff --git a/railties/test/application/rake/dbs_test.rb b/railties/test/application/rake/dbs_test.rb index 8b9d3cb83ff12..9a8e6c3764d15 100644 --- a/railties/test/application/rake/dbs_test.rb +++ b/railties/test/application/rake/dbs_test.rb @@ -363,6 +363,24 @@ def db_migrate_and_status(expected_database) assert_equal "[\"ar_internal_metadata\", \"comments\", \"schema_migrations\"]", list_tables[] end + test "db:migrate:reset regenerates the schema from migrations" do + app_file "db/migrate/01_a_migration.rb", <<-MIGRATION + class AMigration < ActiveRecord::Migration::Current + create_table(:comments) {} + end + MIGRATION + rails("db:migrate") + app_file "db/migrate/01_a_migration.rb", <<-MIGRATION + class AMigration < ActiveRecord::Migration::Current + create_table(:comments) { |t| t.string :title } + end + MIGRATION + + rails("db:migrate:reset") + + assert File.read("#{app_path}/db/schema.rb").include?("title") + end + def db_schema_dump Dir.chdir(app_path) do args = ["generate", "model", "book", "title:string"]