Skip to content

[~] Add CheckConstraintFormatter and SQL wrapper#5

Merged
boserh merged 1 commit intoboserh:mainfrom
marikrebega:check-constraints
Jan 23, 2026
Merged

[~] Add CheckConstraintFormatter and SQL wrapper#5
boserh merged 1 commit intoboserh:mainfrom
marikrebega:check-constraints

Conversation

@marikrebega
Copy link
Contributor

This PR introduces support for annotating models with database Check Constraints and improves the formatting logic for long SQL expressions.

Changes:

  • Added CheckConstraintFormatter to extract and display check constraints in model annotations.
  • Extracted shared wrapping logic into Annotato::WrapHelper to reduce duplication between index and check constraint formatting.
  • Added specs for CheckConstraintFormatter and updated existing specs.

Example output:

# == Annotato Schema Info
# Table: users
#
# Columns:
#  id     :bigint  not null, primary key
#  status :integer default("draft"), not null, enum
#
# Enums:
#  status: {
#    draft (0),
#    published (1)
#  }
#
# Indexes:
#  index_users_on_email (email) unique
#
# Triggers:
#  audit_trigger_row
#
# Check Constraints:
#  chk_valid_status
#    (((((status)::text = 'deleted'::text) AND
#    (deleted_at IS NOT NULL)) OR (((status)::text <> 'deleted'::text) AND
#    (deleted_at IS NULL) AND (active = true))))

@boserh boserh merged commit de98a11 into boserh:main Jan 23, 2026
4 checks passed
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