diff options
Diffstat (limited to 'activerecord')
-rwxr-xr-x | activerecord/lib/active_record/connection_adapters/mysql_adapter.rb | 17 | ||||
-rw-r--r-- | activerecord/test/cases/schema_dumper_test.rb | 12 | ||||
-rw-r--r-- | activerecord/test/schema/schema.rb | 11 |
3 files changed, 40 insertions, 0 deletions
diff --git a/activerecord/lib/active_record/connection_adapters/mysql_adapter.rb b/activerecord/lib/active_record/connection_adapters/mysql_adapter.rb index c37bfd3e81..6432c3cfee 100755 --- a/activerecord/lib/active_record/connection_adapters/mysql_adapter.rb +++ b/activerecord/lib/active_record/connection_adapters/mysql_adapter.rb @@ -112,6 +112,23 @@ module ActiveRecord super end + def extract_limit(sql_type) + if sql_type =~ /blob|text/i + case sql_type + when /tiny/i + 255 + when /medium/i + 16777215 + when /long/i + 2147483647 # mysql only allows 2^31-1, not 2^32-1, somewhat inconsistently with the tiny/medium/normal cases + else + super # we could return 65535 here, but we leave it undecorated by default + end + else + super + end + end + # MySQL misreports NOT NULL column default when none is given. # We can't detect this for columns which may have a legitimate '' # default (string) but we can for others (integer, datetime, boolean, diff --git a/activerecord/test/cases/schema_dumper_test.rb b/activerecord/test/cases/schema_dumper_test.rb index 8413fce3fa..d96bd62e56 100644 --- a/activerecord/test/cases/schema_dumper_test.rb +++ b/activerecord/test/cases/schema_dumper_test.rb @@ -115,6 +115,18 @@ if ActiveRecord::Base.connection.respond_to?(:tables) assert_not_nil(match, "nonstandardpk table not found") assert_match %r(:primary_key => "movieid"), match[1], "non-standard primary key not preserved" end + + def test_schema_dump_includes_length_for_mysql_blob_and_text_fields + output = standard_dump + assert_match %r{t.binary\s+"tiny_blob",\s+:limit => 255$}, output + assert_match %r{t.binary\s+"normal_blob"$}, output + assert_match %r{t.binary\s+"medium_blob",\s+:limit => 16777215$}, output + assert_match %r{t.binary\s+"long_blob",\s+:limit => 2147483647$}, output + assert_match %r{t.text\s+"tiny_text",\s+:limit => 255$}, output + assert_match %r{t.text\s+"normal_text"$}, output + assert_match %r{t.text\s+"medium_text",\s+:limit => 16777215$}, output + assert_match %r{t.text\s+"long_text",\s+:limit => 2147483647$}, output + end end def test_schema_dump_includes_decimal_options diff --git a/activerecord/test/schema/schema.rb b/activerecord/test/schema/schema.rb index 45da902088..33aa6e2ea4 100644 --- a/activerecord/test/schema/schema.rb +++ b/activerecord/test/schema/schema.rb @@ -25,6 +25,17 @@ ActiveRecord::Schema.define do t.binary :data end + create_table :binary_fields, :force => true do |t| + t.binary :tiny_blob, :limit => 255 + t.binary :normal_blob, :limit => 65535 + t.binary :medium_blob, :limit => 16777215 + t.binary :long_blob, :limit => 2147483647 + t.text :tiny_text, :limit => 255 + t.text :normal_text, :limit => 65535 + t.text :medium_text, :limit => 16777215 + t.text :long_text, :limit => 2147483647 + end + create_table :booleantests, :force => true do |t| t.integer :value end |