Skip to content

Support opt-in display of PostgreSQL enum types in annotations#324

Merged
drwl merged 6 commits into
mainfrom
support_printing_enum_type
May 8, 2026
Merged

Support opt-in display of PostgreSQL enum types in annotations#324
drwl merged 6 commits into
mainfrom
support_printing_enum_type

Conversation

@OdenTakashi
Copy link
Copy Markdown
Collaborator

@OdenTakashi OdenTakashi commented Mar 23, 2026

Summary

This change adds an opt-in show_enums option for PostgreSQL model annotations.

When enabled, it:

  • adds an enum_type: attribute to enum columns
  • adds an Enums section below the schema
  • lists only the enum types used by the table

This feature is supported only for PostgreSQL and is safely skipped for MySQL and SQLite.

connection.enum_types was introduced in Rails 7.0 (rails/rails#41469) and may return either a String or an Array depending on the Rails version (rails/rails#54141). This gem handles both formats.

Return type Rails versions
String (string_agg) Rails 7.0 - 8.0.1
Array (array_agg) Rails 7.2.3+, 8.0.2+

Example

Output follows the format proposed in #176.

# == Schema Information
#
# Table name: orders
#
#  id      :bigint           not null, primary key
#  status  :enum             not null, enum_type: order_status
#  billing :enum             enum_type: billing_method
#
# Enums
#
#  billing_method  agency_bill, direct_bill_to_insured
#  order_status    pending, shipped, delivered
#

Configuration

# .annotaterb.yml
show_enums: true

refs: #176 , #309

Copy link
Copy Markdown
Owner

@drwl drwl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you very much for adding this and sorry it took so long to review.

I know after this gets released we can close some issues 👍

@drwl drwl merged commit c6d0a87 into main May 8, 2026
50 checks passed
@drwl drwl deleted the support_printing_enum_type branch May 8, 2026 23:12
@OdenTakashi
Copy link
Copy Markdown
Collaborator Author

No worries at all — thank you for the review!

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

Successfully merging this pull request may close these issues.

2 participants