Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multi-line column comments break annotated comment block #866

Open
mroach opened this issue Apr 5, 2021 · 1 comment
Open

Multi-line column comments break annotated comment block #866

mroach opened this issue Apr 5, 2021 · 1 comment

Comments

@mroach
Copy link

mroach commented Apr 5, 2021

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
@sato11
Copy link
Contributor

sato11 commented Jun 1, 2021

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants