未验证 提交 211564c6 编写于 作者: R Rafael França 提交者: GitHub

Merge pull request #40001 from tgxworld/actionable_migration_not_dumping_schema

Fix ActiveRecord::PendingMigrationError action not dumping schema.
......@@ -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)
......
......@@ -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"]
......
......@@ -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
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册