I’d like to insert COMMENT, which is part of SQL the command, in my migration files.
As far as I know, I can add COMMENT to each table and column.
I can’t remember a plugin name that lets me to write as follows:
t.string :name, :comment => "A user's fullname"
t.string :label, :comment => "name of color"
t.text :value, :comment => "self intro"
t.integer :position, :comment => "1 is left, 2 is right"
And that statement magically is translated into SQL, which is like
create table test (
name varchar(255) not null COMMENT 'blahblah',
label varchar(255) null COMMENT 'hahaha'
text varchar(255) not null,
position int(11)
);
Does anybody know the plug in name?
- I’m not looking for Annotate Models plugins by Dave Thomas. What I mean by comments is inside MySQL queries.
I don’t know of any plugin that will accomplish what you’re asking for. You might be able to hack in what you want by looking at
ActiveRecord::ConnectionAdapters::ColumnDefinition. (Seeactive_record/connection_adapters/abstract/schema_definitions.rb.)As you can see the
Structdefines the various column options (like:limitand:default.) You could extended that struct with a:commentand then modify#to_sqlto generate the required SQL. You would also need to modifyTableDefinition#columnto set the:commentattribute.The following has been tested and works (for MySQL):