mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Rename active_record_internal_metadatas
to ar_internal_metadata
for those who already migrated to Rails 5.0.0 beta
This commit is contained in:
parent
a374af8b57
commit
407e0ab5e5
2 changed files with 28 additions and 0 deletions
|
@ -14,6 +14,10 @@ module ActiveRecord
|
|||
"#{table_name_prefix}#{ActiveRecord::Base.internal_metadata_table_name}#{table_name_suffix}"
|
||||
end
|
||||
|
||||
def original_table_name
|
||||
"#{table_name_prefix}active_record_internal_metadatas#{table_name_suffix}"
|
||||
end
|
||||
|
||||
def []=(key, value)
|
||||
first_or_initialize(key: key).update_attributes!(value: value)
|
||||
end
|
||||
|
@ -26,8 +30,17 @@ module ActiveRecord
|
|||
ActiveSupport::Deprecation.silence { connection.table_exists?(table_name) }
|
||||
end
|
||||
|
||||
def original_table_exists?
|
||||
# This method will be removed in Rails 5.1
|
||||
# Since it is only necessary when `active_record_internal_metadatas` could exist
|
||||
ActiveSupport::Deprecation.silence { connection.table_exists?(original_table_name) }
|
||||
end
|
||||
|
||||
# Creates an internal metadata table with columns +key+ and +value+
|
||||
def create_table
|
||||
if original_table_exists?
|
||||
connection.rename_table(original_table_name, table_name)
|
||||
end
|
||||
unless table_exists?
|
||||
key_options = connection.internal_string_options_for_primary_key
|
||||
|
||||
|
|
|
@ -426,6 +426,21 @@ class MigrationTest < ActiveRecord::TestCase
|
|||
ENV["RACK_ENV"] = original_rack_env
|
||||
end
|
||||
|
||||
def test_rename_internal_metadata_table
|
||||
original_internal_metadata_table_name = ActiveRecord::Base.internal_metadata_table_name
|
||||
|
||||
ActiveRecord::Base.internal_metadata_table_name = "active_record_internal_metadatas"
|
||||
Reminder.reset_table_name
|
||||
|
||||
ActiveRecord::Base.internal_metadata_table_name = original_internal_metadata_table_name
|
||||
Reminder.reset_table_name
|
||||
|
||||
assert_equal "ar_internal_metadata", ActiveRecord::InternalMetadata.table_name
|
||||
ensure
|
||||
ActiveRecord::Base.internal_metadata_table_name = original_internal_metadata_table_name
|
||||
Reminder.reset_table_name
|
||||
end
|
||||
|
||||
def test_proper_table_name_on_migration
|
||||
reminder_class = new_isolated_reminder_class
|
||||
migration = ActiveRecord::Migration.new
|
||||
|
|
Loading…
Reference in a new issue