Comment your tables' columns from your migration files
Here’s a nifty TIL.
I’ve been looking for a way to add default comments on models attributes for ages! These default comments are picked up by gems like annotate, so no need to worry about overwrite.
By default, Rails adds comments to some attributes like id
(see not null, primary key
above).
But now, I can add my own. For example, I can specify the unit for a duration.
Here’s how to do that in a migration:
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.