aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record
diff options
context:
space:
mode:
authorschneems <richard.schneeman@gmail.com>2016-01-21 11:21:20 -0600
committerschneems <richard.schneeman@gmail.com>2016-01-21 13:19:33 -0600
commit8897e05ea31186bfa2a05fd9658b2dc5a5d6264a (patch)
treef1be6f169008fdb05788bd96746565b73981a947 /activerecord/lib/active_record
parent9a99c7cef533e985e67af5de0e65a39f452b7db9 (diff)
downloadrails-8897e05ea31186bfa2a05fd9658b2dc5a5d6264a.tar.gz
rails-8897e05ea31186bfa2a05fd9658b2dc5a5d6264a.tar.bz2
rails-8897e05ea31186bfa2a05fd9658b2dc5a5d6264a.zip
[close #23009] Limit key length
Mysql has a weird bug where it cannot index a string column of utf8mb4 if it is over a certain character limit. To get compatibility with msql we can add a limit to the key column. 191 characters is a very long key, it seems reasonable to limit across all adapters since using a longer key wouldn't be supported in mysql. Thanks to @kamipo for the original PR and the test refactoring. Conversation: https://github.com/rails/rails/pull/23009#issuecomment-171416629
Diffstat (limited to 'activerecord/lib/active_record')
-rw-r--r--activerecord/lib/active_record/internal_metadata.rb9
1 files changed, 7 insertions, 2 deletions
diff --git a/activerecord/lib/active_record/internal_metadata.rb b/activerecord/lib/active_record/internal_metadata.rb
index e5c6e5c885..10fee4dca2 100644
--- a/activerecord/lib/active_record/internal_metadata.rb
+++ b/activerecord/lib/active_record/internal_metadata.rb
@@ -5,6 +5,10 @@ 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 # :nodoc:
+ # Keys in mysql are limited to 191 characters, due to this no adapter can
+ # use a longer key
+ KEY_LIMIT = 191
+
class << self
def primary_key
"key"
@@ -34,10 +38,11 @@ module ActiveRecord
def create_table
unless table_exists?
connection.create_table(table_name, id: false) do |t|
- t.column :key, :string
+ t.column :key, :string, null: false, limit: KEY_LIMIT
t.column :value, :string
- t.timestamps
t.index :key, unique: true, name: index_name
+
+ t.timestamps
end
end
end