2008-03-04 [長年日記]

_ [rails][mysql] Migration で MySQL の BINARY 属性を指定できるようにする

メモメモ。しかしこれ、本体にパッチあてるとしたら、実質 +3-1 で済むような気が。

Index: activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb
===================================================================
--- activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb	(revision 8979)
+++ activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb	(working copy)
@@ -280,6 +280,10 @@
       end
 
       def add_column_options!(sql, options) #:nodoc:
+        if Base.configurations[RAILS_ENV]["adpater"] == "mysql" &&
+          (options[:binary] || (options[:column] && options[:column].binary))
+          sql << " BINARY"
+        end
         sql << " DEFAULT #{quote(options[:default], options[:column])}" if options_include_default?(options)
         sql << " NOT NULL" if options[:null] == false
       end
Index: activerecord/lib/active_record/connection_adapters/abstract/schema_definitions.rb
===================================================================
--- activerecord/lib/active_record/connection_adapters/abstract/schema_definitions.rb	(revision 8979)
+++ activerecord/lib/active_record/connection_adapters/abstract/schema_definitions.rb	(working copy)
@@ -249,7 +249,7 @@
     class IndexDefinition < Struct.new(:table, :name, :unique, :columns) #:nodoc:
     end
 
-    class ColumnDefinition < Struct.new(:base, :name, :type, :limit, :precision, :scale, :default, :null) #:nodoc:
+    class ColumnDefinition < Struct.new(:base, :name, :type, :limit, :precision, :scale, :binary, :default, :null) #:nodoc:
       
       def sql_type
         base.type_to_sql(type.to_sym, limit, precision, scale) rescue type
@@ -425,6 +425,7 @@
         column.scale = options[:scale]
         column.default = options[:default]
         column.null = options[:null]
+        column.binary = options[:binary]
         @columns << column unless @columns.include? column
         self
       end

誰かテスト書いてねじ込んでー。

[]

«前の日記(2008-02-29) 最新 次の日記(2008-03-13)»