Add comments to your tables columns
I’ve been looking for a way to add default comments on models attributes for ages!
By default, Rails adds comments to some attributes like id
(not null, primary key
for instance.)
But now, I can add my own. For example, I can specify the unit for a duration column. It’s like Yard documentation for methods, but for attributes.
These default comments are defined in your schema.rb
, so gems like annotate will pick them up. No need to worry about overwrite anymore.
See this lil’ in seconds
above, that’s me, adding extra documentation to my tables column so my teamates don’t have to guess the unit.
Here’s how to do that in a migration adding a new column:
I can also add a default comment to an existing attribute:
Passing a hash containing :from
and :to
will make this change reversible in migrations.
Go and document those attributes!
Cheers,
Rémi - @remi@ruby.social