Skip to content

Commit aeb0828

Browse files
authored
Merge pull request rails#53240 from JoeDupuis/fix-db-migrate-reset
Fix `db:migrate:reset` task
2 parents 8c7e553 + b62fb1e commit aeb0828

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

activerecord/lib/active_record/railties/databases.rake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ db_namespace = namespace :db do
176176
end
177177

178178
# desc 'Resets your database using your migrations for the current environment'
179-
task reset: ["db:drop", "db:create", "db:migrate"]
179+
task reset: ["db:drop", "db:create", "db:schema:dump", "db:migrate"]
180180

181181
desc 'Run the "up" for a given migration VERSION.'
182182
task up: :load_config do

railties/test/application/rake/dbs_test.rb

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -363,6 +363,24 @@ def db_migrate_and_status(expected_database)
363363
assert_equal "[\"ar_internal_metadata\", \"comments\", \"schema_migrations\"]", list_tables[]
364364
end
365365

366+
test "db:migrate:reset regenerates the schema from migrations" do
367+
app_file "db/migrate/01_a_migration.rb", <<-MIGRATION
368+
class AMigration < ActiveRecord::Migration::Current
369+
create_table(:comments) {}
370+
end
371+
MIGRATION
372+
rails("db:migrate")
373+
app_file "db/migrate/01_a_migration.rb", <<-MIGRATION
374+
class AMigration < ActiveRecord::Migration::Current
375+
create_table(:comments) { |t| t.string :title }
376+
end
377+
MIGRATION
378+
379+
rails("db:migrate:reset")
380+
381+
assert File.read("#{app_path}/db/schema.rb").include?("title")
382+
end
383+
366384
def db_schema_dump
367385
Dir.chdir(app_path) do
368386
args = ["generate", "model", "book", "title:string"]

0 commit comments

Comments
 (0)