mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Make ActiveRecord::PendingMigrationError actionable
This commit is contained in:
parent
45f1c7a3e1
commit
255a2422a3
2 changed files with 10 additions and 2 deletions
|
@ -129,6 +129,12 @@ module ActiveRecord
|
||||||
end
|
end
|
||||||
|
|
||||||
class PendingMigrationError < MigrationError #:nodoc:
|
class PendingMigrationError < MigrationError #:nodoc:
|
||||||
|
include ActiveSupport::ActionableError
|
||||||
|
|
||||||
|
action "Run pending migrations" do
|
||||||
|
ActiveRecord::Tasks::DatabaseTasks.migrate
|
||||||
|
end
|
||||||
|
|
||||||
def initialize(message = nil)
|
def initialize(message = nil)
|
||||||
if !message && defined?(Rails.env)
|
if !message && defined?(Rails.env)
|
||||||
super("Migrations are pending. To resolve this issue, run:\n\n rails db:migrate RAILS_ENV=#{::Rails.env}")
|
super("Migrations are pending. To resolve this issue, run:\n\n rails db:migrate RAILS_ENV=#{::Rails.env}")
|
||||||
|
|
|
@ -760,7 +760,7 @@ module ActiveRecord
|
||||||
end
|
end
|
||||||
|
|
||||||
class DatabaseTasksMigrateTest < DatabaseTasksMigrationTestCase
|
class DatabaseTasksMigrateTest < DatabaseTasksMigrationTestCase
|
||||||
def test_migrate_set_and_unset_verbose_and_version_env_vars
|
def test_can_migrate_from_pending_migration_error_action_dispatch
|
||||||
verbose, version = ENV["VERBOSE"], ENV["VERSION"]
|
verbose, version = ENV["VERBOSE"], ENV["VERSION"]
|
||||||
ENV["VERSION"] = "2"
|
ENV["VERSION"] = "2"
|
||||||
ENV["VERBOSE"] = "false"
|
ENV["VERBOSE"] = "false"
|
||||||
|
@ -772,7 +772,9 @@ module ActiveRecord
|
||||||
ENV.delete("VERBOSE")
|
ENV.delete("VERBOSE")
|
||||||
|
|
||||||
# re-run up migration
|
# re-run up migration
|
||||||
assert_includes capture_migration_output, "migrating"
|
assert_includes(capture(:stdout) do
|
||||||
|
ActiveSupport::ActionableError.dispatch ActiveRecord::PendingMigrationError, "Run pending migrations"
|
||||||
|
end, "migrating")
|
||||||
ensure
|
ensure
|
||||||
ENV["VERBOSE"], ENV["VERSION"] = verbose, version
|
ENV["VERBOSE"], ENV["VERSION"] = verbose, version
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue