aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--activerecord/lib/active_record/internal_metadata.rb10
-rw-r--r--activerecord/lib/active_record/migration.rb6
-rw-r--r--activerecord/lib/active_record/schema.rb2
-rw-r--r--activerecord/lib/active_record/tasks/database_tasks.rb2
-rw-r--r--activerecord/test/cases/migration_test.rb4
-rw-r--r--activerecord/test/cases/tasks/database_tasks_test.rb2
6 files changed, 12 insertions, 14 deletions
diff --git a/activerecord/lib/active_record/internal_metadata.rb b/activerecord/lib/active_record/internal_metadata.rb
index fc1bb0bdce..7bd66028b6 100644
--- a/activerecord/lib/active_record/internal_metadata.rb
+++ b/activerecord/lib/active_record/internal_metadata.rb
@@ -4,7 +4,7 @@ require 'active_record/scoping/named'
module ActiveRecord
# This class is used to create a table that keeps track of values and keys such
# as which environment migrations were run in.
- class InternalMetadata < ActiveRecord::Base
+ class InternalMetadata < ActiveRecord::Base # :nodoc:
class << self
def primary_key
"key"
@@ -18,13 +18,11 @@ module ActiveRecord
"#{table_name_prefix}unique_#{ActiveRecord::Base.internal_metadata_table_name}#{table_name_suffix}"
end
- def store(hash)
- hash.each do |key, value|
- first_or_initialize(key: key).update_attributes!(value: value)
- end
+ def []=(key, value)
+ first_or_initialize(key: key).update_attributes!(value: value)
end
- def value_for(key)
+ def [](key)
where(key: key).pluck(:value).first
end
diff --git a/activerecord/lib/active_record/migration.rb b/activerecord/lib/active_record/migration.rb
index a7e747a482..cd1bda3324 100644
--- a/activerecord/lib/active_record/migration.rb
+++ b/activerecord/lib/active_record/migration.rb
@@ -1233,15 +1233,15 @@ module ActiveRecord
else
migrated << version
ActiveRecord::SchemaMigration.create!(version: version.to_s)
- ActiveRecord::InternalMetadata.store(environment: current_environment)
+ ActiveRecord::InternalMetadata[:environment] = ActiveRecord::Migrator.current_environment
end
end
def self.last_stored_environment
- ActiveRecord::InternalMetadata.value_for(:environment)
+ ActiveRecord::InternalMetadata[:environment]
end
- def current_environment
+ def self.current_environment
ActiveRecord::ConnectionHandling::DEFAULT_ENV.call
end
diff --git a/activerecord/lib/active_record/schema.rb b/activerecord/lib/active_record/schema.rb
index 0a0ea33196..784a02d2c3 100644
--- a/activerecord/lib/active_record/schema.rb
+++ b/activerecord/lib/active_record/schema.rb
@@ -53,7 +53,7 @@ module ActiveRecord
end
ActiveRecord::InternalMetadata.create_table
- ActiveRecord::InternalMetadata.store("environment" => ActiveRecord::ConnectionHandling::DEFAULT_ENV.call)
+ ActiveRecord::InternalMetadata[:environment] = ActiveRecord::Migrator.current_environment
end
private
diff --git a/activerecord/lib/active_record/tasks/database_tasks.rb b/activerecord/lib/active_record/tasks/database_tasks.rb
index 92f6f44de9..d51f38c93f 100644
--- a/activerecord/lib/active_record/tasks/database_tasks.rb
+++ b/activerecord/lib/active_record/tasks/database_tasks.rb
@@ -221,7 +221,7 @@ module ActiveRecord
raise ArgumentError, "unknown format #{format.inspect}"
end
ActiveRecord::InternalMetadata.create_table
- ActiveRecord::InternalMetata.store("environment" => ActiveRecord::ConnectionHandling::DEFAULT_ENV.call)
+ ActiveRecord::InternalMetadata[:environment] = ActiveRecord::Migrator.current_environment
end
def load_schema_for(*args)
diff --git a/activerecord/test/cases/migration_test.rb b/activerecord/test/cases/migration_test.rb
index 2f7859a7be..bd60b64ee2 100644
--- a/activerecord/test/cases/migration_test.rb
+++ b/activerecord/test/cases/migration_test.rb
@@ -380,7 +380,7 @@ class MigrationTest < ActiveRecord::TestCase
old_path = ActiveRecord::Migrator.migrations_paths
ActiveRecord::Migrator.migrations_paths = migrations_path
- assert_equal current_env, ActiveRecord::InternalMetadata.value_for("environment")
+ assert_equal current_env, ActiveRecord::InternalMetadata[:environment]
original_rails_env = ENV["RAILS_ENV"]
original_rack_env = ENV["RACK_ENV"]
@@ -391,7 +391,7 @@ class MigrationTest < ActiveRecord::TestCase
sleep 1 # mysql by default does not store fractional seconds in the database
ActiveRecord::Migrator.up(migrations_path)
- assert_equal new_env, ActiveRecord::InternalMetadata.value_for("environment")
+ assert_equal new_env, ActiveRecord::InternalMetadata[:environment]
ensure
ActiveRecord::Migrator.migrations_paths = old_path
ENV["RAILS_ENV"] = original_rails_env
diff --git a/activerecord/test/cases/tasks/database_tasks_test.rb b/activerecord/test/cases/tasks/database_tasks_test.rb
index e91a222534..326373791c 100644
--- a/activerecord/test/cases/tasks/database_tasks_test.rb
+++ b/activerecord/test/cases/tasks/database_tasks_test.rb
@@ -23,7 +23,7 @@ module ActiveRecord
ActiveRecord::Migrator.stubs(:current_version).returns(1)
protected_environments = ActiveRecord::Base.protected_environments.dup
- current_env = ActiveRecord::ConnectionHandling::DEFAULT_ENV.call
+ current_env = ActiveRecord::Migrator.current_environment
assert !protected_environments.include?(current_env)
# Assert no error
ActiveRecord::Tasks::DatabaseTasks.check_protected_environments!