Skip to content

Commit

Permalink
Fix db:migrate:reset task
Browse files Browse the repository at this point in the history
Fixes rails#53216

`db:migrate:reset` is broken, because we started to load the schema
before migrating. This prevents migrations from running. This patch
empties the schema before migrating, ensuring that migrations run as
expected.
  • Loading branch information
JoeDupuis committed Oct 11, 2024
1 parent 8ceb7b9 commit b62fb1e
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 b62fb1e

Please sign in to comment.