Skip to content

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

Open
OdenTakashi wants to merge 5 commits intomainfrom
support_printing_enum_type
Open

Support opt-in display of PostgreSQL enum types in annotations#324
OdenTakashi wants to merge 5 commits intomainfrom
support_printing_enum_type

Conversation

@OdenTakashi
Copy link
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

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.

1 participant