Skip to content

Commit

Permalink
Fix ActiveRecord::PendingMigrationError action not dumping schema.
Browse files Browse the repository at this point in the history
  • Loading branch information
tgxworld committed Aug 26, 2020
1 parent 3ddf6b6 commit 17ec88e
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 21 deletions.
6 changes: 6 additions & 0 deletions activerecord/lib/active_record/migration.rb
Expand Up @@ -135,6 +135,12 @@ class PendingMigrationError < MigrationError #:nodoc:

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)
Expand Down
19 changes: 0 additions & 19 deletions activerecord/test/cases/tasks/database_tasks_test.rb
Expand Up @@ -905,25 +905,6 @@ class DatabaseTasksMigrationTestCase < ActiveRecord::TestCase
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"]

Expand Down
17 changes: 15 additions & 2 deletions railties/test/application/configuration_test.rb
Expand Up @@ -153,12 +153,25 @@ def change

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
Expand Down

0 comments on commit 17ec88e

Please sign in to comment.