annotate_models icon indicating copy to clipboard operation
annotate_models copied to clipboard

Multi-line column comments break annotated comment block

Open mroach opened this issue 5 years ago • 1 comments

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:

  1. The lines after the first are not commented-out
  2. 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

  1. Figure out the table column width by the longest line e.g. column_name_with_comment.lines.map(&:length).max
  2. 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

  1. Create a multi-line comment on a column
  2. Annotate models

Version

  • annotate version: 3.1.1
  • rails version 6.1
  • ruby version 2.7

mroach avatar Apr 05 '21 10:04 mroach

#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.

sato11 avatar Jun 01 '21 06:06 sato11