diff options
Diffstat (limited to 'activerecord/lib/active_record/migration.rb')
-rw-r--r-- | activerecord/lib/active_record/migration.rb | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/activerecord/lib/active_record/migration.rb b/activerecord/lib/active_record/migration.rb index c61491d58c..a7e747a482 100644 --- a/activerecord/lib/active_record/migration.rb +++ b/activerecord/lib/active_record/migration.rb @@ -163,6 +163,15 @@ module ActiveRecord end end + class EnvironmentMismatchError < ActiveRecordError + def initialize(current: current, stored: stored) + msg = "You are attempting to modify a database that was last run in #{ stored } environment.\n" + msg << "You are running in #{ current } environment." + msg << "if you are sure you want to continue, run the same command with the environment variable\n" + msg << "DISABLE_DATABASE_ENVIRONMENT_CHECK=1" + end + end + # = Active Record Migrations # # Migrations can manage the evolution of a schema used by several physical @@ -1224,8 +1233,7 @@ module ActiveRecord else migrated << version ActiveRecord::SchemaMigration.create!(version: version.to_s) - environment = ActiveRecord::ConnectionHandling::DEFAULT_ENV.call - ActiveRecord::InternalMetadata.store(environment: environment) + ActiveRecord::InternalMetadata.store(environment: current_environment) end end @@ -1233,6 +1241,10 @@ module ActiveRecord ActiveRecord::InternalMetadata.value_for(:environment) end + def current_environment + ActiveRecord::ConnectionHandling::DEFAULT_ENV.call + end + def self.protected_environment? return false if current_version == 0 raise NoEnvironmentInSchemaError unless ActiveRecord::InternalMetadata.table_exists? |