Skip to content

Commit

Permalink
Merge pull request rails#53240 from JoeDupuis/fix-db-migrate-reset
Browse files Browse the repository at this point in the history
Fix `db:migrate:reset` task
  • Loading branch information
rafaelfranca authored Oct 15, 2024
2 parents 8c7e553 + b62fb1e commit aeb0828
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
2 changes: 1 addition & 1 deletion activerecord/lib/active_record/railties/databases.rake
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
18 changes: 18 additions & 0 deletions railties/test/application/rake/dbs_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down

0 comments on commit aeb0828

Please sign in to comment.