Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I don't know of any plugin that will accomplish what you're asking for. You <em>might</em> be able to hack in what you want by looking at <code>ActiveRecord::ConnectionAdapters::ColumnDefinition</code>. (See <code>active_record/connection_adapters/abstract/schema_definitions.rb</code>.)</p> <p>As you can see the <code>Struct</code> defines the various column options (like <code>:limit</code> and <code>:default</code>.) You could extended that struct with a <code>:comment</code> and then modify <code>#to_sql</code> to generate the required SQL. You would also need to modify <code>TableDefinition#column</code> to set the <code>:comment</code> attribute.</p> <p>The following has been tested and works (for MySQL):</p> <pre><code>module ActiveRecord module ConnectionAdapters class ColumnDefinition attr_accessor :comment def to_sql_with_comment column_sql = to_sql_without_comment return column_sql if comment.nil? "#{column_sql} COMMENT '#{base.quote_string(comment)}'" end alias_method_chain :to_sql, :comment end class TableDefinition # Completely replaces (and duplicates the existing code, but there's # no place to really hook into the middle of this.) def column(name, type, options = {}) column = self[name] || ColumnDefinition.new(@base, name, type) if options[:limit] column.limit = options[:limit] elsif native[type.to_sym].is_a?(Hash) column.limit = native[type.to_sym][:limit] end column.precision = options[:precision] column.scale = options[:scale] column.default = options[:default] column.null = options[:null] column.comment = options[:comment] @columns &lt;&lt; column unless @columns.include? column self end end end end </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload