aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorYasuo Honda <yasuo.honda@gmail.com>2016-01-27 03:30:37 +0000
committerYasuo Honda <yasuo.honda@gmail.com>2016-02-01 15:52:30 +0000
commit407e0ab5e5cddf6a8b6b278b12f50772d13b4d86 (patch)
treebcfed37756a84aa34a707e135677a8c28da4834f
parenta374af8b5788506acc28b755c0cde62ee89fa9d3 (diff)
downloadrails-407e0ab5e5cddf6a8b6b278b12f50772d13b4d86.tar.gz
rails-407e0ab5e5cddf6a8b6b278b12f50772d13b4d86.tar.bz2
rails-407e0ab5e5cddf6a8b6b278b12f50772d13b4d86.zip
Rename `active_record_internal_metadatas` to `ar_internal_metadata`
for those who already migrated to Rails 5.0.0 beta
-rw-r--r--activerecord/lib/active_record/internal_metadata.rb13
-rw-r--r--activerecord/test/cases/migration_test.rb15
2 files changed, 28 insertions, 0 deletions
diff --git a/activerecord/lib/active_record/internal_metadata.rb b/activerecord/lib/active_record/internal_metadata.rb
index cb4b1fc47c..81db96bffd 100644
--- a/activerecord/lib/active_record/internal_metadata.rb
+++ b/activerecord/lib/active_record/internal_metadata.rb
@@ -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
diff --git a/activerecord/test/cases/migration_test.rb b/activerecord/test/cases/migration_test.rb
index e292ae5fe5..9b4394377f 100644
--- a/activerecord/test/cases/migration_test.rb
+++ b/activerecord/test/cases/migration_test.rb
@@ -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