annotate_models
annotate_models copied to clipboard
Multi-line column comments break annotated comment block
Multi-line column comments are allowed. For example:
t.boolean :handled, null: false, comment: <<~EOF
If the event instance was handled in accordance with the schedules.event_{type,data}.
For example, if a Sidekiq job were enqueued, it's considered handled.
EOF
t.jsonb :handler_data, null: true, comment: "Any data to identify the handling, e.g Sidekiq job ID"
When annotating the models:
- The lines after the first are not commented-out
- The table of fields becomes very wide to the point where it's not usable.
# Table name: schedule_instances
#
# id :bigint not null, primary key
# handled(If the event instance was handled in accordance with the schedules.event_{type,data}.
For example, if a Sidekiq job were enqueued, it's considered handled.
) :boolean default(FALSE), not null
# handler_data(Any data to identify the handling, e.g Sidekiq job ID) :jsonb
Possible changes
- Figure out the table column width by the longest line e.g.
column_name_with_comment.lines.map(&:length).max - Comment-out all lines
Another option may be for multi-line comments, long comments, or perhaps all comments, it might be nice to just put them on a new line and indent it. For example:
# Table name: schedule_instances
#
# id :bigint not null, primary key
# handled :boolean default(FALSE), not null
# If the event instance was handled in accordance with the schedules.event_{type,data}.
# For example, if a Sidekiq job were enqueued, it's considered handled.
# handler_data :jsonb
# Any data to identify the handling, e.g Sidekiq job ID
Commands
- Create a multi-line comment on a column
- Annotate models
Version
- annotate version: 3.1.1
- rails version 6.1
- ruby version 2.7
#779 seems to have fixed this already and it's just not released yet 😢
The HEAD version does work, while it crams the comment in a single line which makes the table look unbalanced. It would be like this in the case presented above:
# Table name: schedule_instances
#
# id :bigint not null, primary key
# handled(If the event instance was handled in accordance with the schedules.event_{type,data}.\nFor example, if a Sidekiq job were enqueued, it's considered handled.) :boolean default(FALSE), not null
# handler_data(Any data to identify the handling, e.g Sidekiq job ID) :jsonb
And I would prefer @mroach's suggestion to the current implementation.