提交 81f6a1f8 编写于 作者: N Nick Burns 提交者: Nick Burns

Apply suggestions from review

Co-Authored-By: NEileen M. Uchitelle <eileencodes@users.noreply.github.com>
上级 aee310c1
......@@ -7,8 +7,8 @@ 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.
#
# It is possible to enable or disable this functionality by setting the
# adapter configuration option `use_metadata_table` to false
# This is enabled by default. To disable this functionality set
# `use_metadata_table` to false in your database configuration.
class InternalMetadata < ActiveRecord::Base # :nodoc:
class << self
def enabled?
......
......@@ -190,10 +190,11 @@ def initialize(current: nil, stored: nil)
end
end
class EnvironmentStorageError < ActiveRecordError #:nodoc:
class EnvironmentStorageError < ActiveRecordError # :nodoc:
def initialize
msg = +"You are attempting to store the environment in a database where metadata is disabled.\n"
msg << "Check your database configuration to see if this is inteded."
msg << "Check your database configuration to see if this is intended."
super(msg)
end
end
......
......@@ -641,13 +641,26 @@ def test_internal_metadata_stores_environment_when_other_data_exists
end
def test_internal_metadata_not_used_when_not_enabled
ActiveRecord::InternalMetadata.stub(:enabled?, false) do
migrations_path = MIGRATIONS_ROOT + "/valid"
ActiveRecord::InternalMetadata.drop_table
original_config = ActiveRecord::Base.connection.instance_variable_get("@config")
migrator = ActiveRecord::MigrationContext.new(migrations_path, @schema_migration)
migrator.up
assert_not ActiveRecord::InternalMetadata[:environment]
end
modified_config = original_config.dup.merge(use_metadata_table: false)
ActiveRecord::Base.connection
.instance_variable_set("@config", modified_config)
assert_not ActiveRecord::InternalMetadata.enabled?
assert_not ActiveRecord::InternalMetadata.table_exists?
migrations_path = MIGRATIONS_ROOT + "/valid"
migrator = ActiveRecord::MigrationContext.new(migrations_path, @schema_migration)
migrator.up
assert_not ActiveRecord::InternalMetadata[:environment]
assert_not ActiveRecord::InternalMetadata.table_exists?
ensure
ActiveRecord::Base.connection.instance_variable_set("@config", original_config)
ActiveRecord::InternalMetadata.create_table
end
def test_proper_table_name_on_migration
......
......@@ -1260,7 +1260,12 @@ Change the username and password in the `development` section as appropriate.
#### Configuring Metadata Storage
By default Rails will store information about your environment and schema in an internal table. If you do not want this table to be created, and are willing to give up the protections it provides (useful when working with a shared database and a database user that can not create tables).
By default Rails will store information about your Rails environment and schema
in an internal table named `ar_internal_metadata`.
To turn this off per connection, set `use_metadata_table` in your database
configuration. This is useful when working with a shared database and/or
database user that cannot create tables.
```yaml
development:
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册