module ActiveRecord
  module ConnectionAdapters
#    class ColumnDefinition
#      attr_accessor :comment
#      def to_commented_sql
#        self.comment ? "#{to_sql} COMMENT '#{self.comment}'" : to_sql
#      end
#      alias to_s :to_commented_sql
#    end
    class ColumnDefinition
      attr_accessor :comment
      alias :_orig_to_sql :to_sql
      def to_commented_sql
        self.comment ? "#{_orig_to_sql} COMMENT '#{self.comment}'" : _orig_to_sql
      end
      alias to_sql :to_commented_sql
    end

    class TableDefinition
      alias :_orig_column :column
      def column(name, type, options = {})
        _orig_column(name, type, options)
        if comment = options[:comment]
          column = @columns.find { |col| col.name == name }
          pos = @columns.index(column)
          @columns[pos].comment = comment
        end
        self
      end
    end
  end
end

