diff --git a/activerecord/lib/active_record/migration.rb b/activerecord/lib/active_record/migration.rb index 56c7495226..4240cb20c0 100644 --- a/activerecord/lib/active_record/migration.rb +++ b/activerecord/lib/active_record/migration.rb @@ -135,6 +135,12 @@ module ActiveRecord action "Run pending migrations" do ActiveRecord::Tasks::DatabaseTasks.migrate + + if ActiveRecord::Base.dump_schema_after_migration + ActiveRecord::Tasks::DatabaseTasks.dump_schema( + ActiveRecord::Base.connection_db_config + ) + end end def initialize(message = nil) diff --git a/activerecord/test/cases/tasks/database_tasks_test.rb b/activerecord/test/cases/tasks/database_tasks_test.rb index 2c1504179b..fd090c8bca 100644 --- a/activerecord/test/cases/tasks/database_tasks_test.rb +++ b/activerecord/test/cases/tasks/database_tasks_test.rb @@ -905,25 +905,6 @@ module ActiveRecord end class DatabaseTasksMigrateTest < DatabaseTasksMigrationTestCase - def test_can_migrate_from_pending_migration_error_action_dispatch - verbose, version = ENV["VERBOSE"], ENV["VERSION"] - ENV["VERSION"] = "2" - ENV["VERBOSE"] = "false" - - # run down migration because it was already run on copied db - assert_empty capture_migration_output - - ENV.delete("VERSION") - ENV.delete("VERBOSE") - - # re-run up migration - assert_includes(capture(:stdout) do - ActiveSupport::ActionableError.dispatch ActiveRecord::PendingMigrationError, "Run pending migrations" - end, "migrating") - ensure - ENV["VERBOSE"], ENV["VERSION"] = verbose, version - end - def test_migrate_set_and_unset_empty_values_for_verbose_and_version_env_vars verbose, version = ENV["VERBOSE"], ENV["VERSION"] diff --git a/railties/test/application/configuration_test.rb b/railties/test/application/configuration_test.rb index 3dcf4b105c..199eeffcc7 100644 --- a/railties/test/application/configuration_test.rb +++ b/railties/test/application/configuration_test.rb @@ -153,12 +153,25 @@ module ApplicationTests app "development" - ActiveRecord::Migrator.migrations_paths = ["#{app_path}/db/migrate"] - begin + ActiveRecord::Migrator.migrations_paths = ["#{app_path}/db/migrate"] + get "/foo" assert_equal 500, last_response.status assert_match "ActiveRecord::PendingMigrationError", last_response.body + + assert_changes -> { File.exist?(File.join(app_path, "db", "schema.rb")) }, from: false, to: true do + output = capture(:stdout) do + post "/rails/actions", { error: "ActiveRecord::PendingMigrationError", action: "Run pending migrations" } + end + + assert_match(/\d{14}\s+CreateUser/, output) + end + + assert_equal 302, last_response.status + + get "/foo" + assert_equal 404, last_response.status ensure ActiveRecord::Migrator.migrations_paths = nil end