aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib
diff options
context:
space:
mode:
Diffstat (limited to 'activerecord/lib')
-rw-r--r--activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb30
-rw-r--r--activerecord/lib/active_record/connection_adapters/mysql/schema_definitions.rb4
-rw-r--r--activerecord/lib/active_record/connection_adapters/mysql/schema_dumper.rb8
3 files changed, 31 insertions, 11 deletions
diff --git a/activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb b/activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb
index f710ec10fc..e9365cf8d0 100644
--- a/activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb
+++ b/activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb
@@ -134,6 +134,7 @@ module ActiveRecord
time: { name: "time" },
date: { name: "date" },
binary: { name: "blob" },
+ blob: { name: "blob" },
boolean: { name: "tinyint", limit: 1 },
bigint: { name: "bigint" },
json: { name: "json" },
@@ -679,12 +680,18 @@ module ActiveRecord
# Maps logical Rails types to MySQL-specific data types.
def type_to_sql(type, limit = nil, precision = nil, scale = nil, unsigned = nil)
sql = case type.to_s
- when 'binary'
- binary_to_sql(limit)
when 'integer'
integer_to_sql(limit)
when 'text'
text_to_sql(limit)
+ when 'blob'
+ binary_to_sql(limit)
+ when 'binary'
+ if (0..0xfff) === limit
+ "varbinary(#{limit})"
+ else
+ binary_to_sql(limit)
+ end
else
super(type, limit, precision, scale)
end
@@ -997,15 +1004,6 @@ module ActiveRecord
MySQL::TableDefinition.new(native_database_types, name, temporary, options, as)
end
- def binary_to_sql(limit) # :nodoc:
- case limit
- when 0..0xfff; "varbinary(#{limit})"
- when nil; "blob"
- when 0x1000..0xffffffff; "blob(#{limit})"
- else raise(ActiveRecordError, "No binary type has byte length #{limit}")
- end
- end
-
def integer_to_sql(limit) # :nodoc:
case limit
when 1; 'tinyint'
@@ -1028,6 +1026,16 @@ module ActiveRecord
end
end
+ def binary_to_sql(limit) # :nodoc:
+ case limit
+ when 0..0xff; 'tinyblob'
+ when nil, 0x100..0xffff; 'blob'
+ when 0x10000..0xffffff; 'mediumblob'
+ when 0x1000000..0xffffffff; 'longblob'
+ else raise(ActiveRecordError, "No binary type has byte length #{limit}")
+ end
+ end
+
class MysqlJson < Type::Internal::AbstractJson # :nodoc:
def changed_in_place?(raw_old_value, new_value)
# Normalization is required because MySQL JSON data format includes
diff --git a/activerecord/lib/active_record/connection_adapters/mysql/schema_definitions.rb b/activerecord/lib/active_record/connection_adapters/mysql/schema_definitions.rb
index bcf397cd77..29e8c73d46 100644
--- a/activerecord/lib/active_record/connection_adapters/mysql/schema_definitions.rb
+++ b/activerecord/lib/active_record/connection_adapters/mysql/schema_definitions.rb
@@ -7,6 +7,10 @@ module ActiveRecord
super
end
+ def blob(*args, **options)
+ args.each { |name| column(name, :blob, options) }
+ end
+
def json(*args, **options)
args.each { |name| column(name, :json, options) }
end
diff --git a/activerecord/lib/active_record/connection_adapters/mysql/schema_dumper.rb b/activerecord/lib/active_record/connection_adapters/mysql/schema_dumper.rb
index 6448b8b5e2..3c48d0554e 100644
--- a/activerecord/lib/active_record/connection_adapters/mysql/schema_dumper.rb
+++ b/activerecord/lib/active_record/connection_adapters/mysql/schema_dumper.rb
@@ -27,6 +27,14 @@ module ActiveRecord
private
+ def schema_type(column)
+ if column.sql_type == 'tinyblob'
+ 'blob'
+ else
+ super
+ end
+ end
+
def schema_limit(column)
super unless column.type == :boolean
end