diff options
author | Sean Griffin <sean@seantheprogrammer.com> | 2016-01-08 13:42:48 -0700 |
---|---|---|
committer | Sean Griffin <sean@seantheprogrammer.com> | 2016-01-08 13:42:48 -0700 |
commit | c1a1595740b243bed02f5e59090cc58dac77bbf3 (patch) | |
tree | c22f9ed3df30b9a5aa3c2f2b9e112cecee382c75 /activerecord/lib/active_record/tasks | |
parent | d0393fccffc118a5de37654aa222774b66123393 (diff) | |
parent | d70c68d76abcbc24ef0e56b7a7b580d0013255dd (diff) | |
download | rails-c1a1595740b243bed02f5e59090cc58dac77bbf3.tar.gz rails-c1a1595740b243bed02f5e59090cc58dac77bbf3.tar.bz2 rails-c1a1595740b243bed02f5e59090cc58dac77bbf3.zip |
Merge pull request #22967 from schneems/schneems/generic-metadata
Prevent destructive action on production database
Diffstat (limited to 'activerecord/lib/active_record/tasks')
-rw-r--r-- | activerecord/lib/active_record/tasks/database_tasks.rb | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/activerecord/lib/active_record/tasks/database_tasks.rb b/activerecord/lib/active_record/tasks/database_tasks.rb index b6fba0cf79..6a9af5d1b4 100644 --- a/activerecord/lib/active_record/tasks/database_tasks.rb +++ b/activerecord/lib/active_record/tasks/database_tasks.rb @@ -42,6 +42,22 @@ module ActiveRecord LOCAL_HOSTS = ['127.0.0.1', 'localhost'] + def check_protected_environments! + unless ENV['DISABLE_DATABASE_internal_metadata'] + current = ActiveRecord::Migrator.current_environment + stored = ActiveRecord::Migrator.last_stored_environment + + if ActiveRecord::Migrator.protected_environment? + raise ActiveRecord::ProtectedEnvironmentError.new(stored) + end + + if stored && stored != current + raise ActiveRecord::EnvironmentMismatchError.new(current: current, stored: stored) + end + end + rescue ActiveRecord::NoDatabaseError + end + def register_task(pattern, task) @tasks ||= {} @tasks[pattern] = task @@ -204,6 +220,8 @@ module ActiveRecord else raise ArgumentError, "unknown format #{format.inspect}" end + ActiveRecord::InternalMetadata.create_table + ActiveRecord::InternalMetadata[:environment] = ActiveRecord::Migrator.current_environment end def load_schema_for(*args) |