Skip to content

feat: add constraints section to .pgschemaignore (#429, #447)#452

Merged
tianzhou merged 2 commits into
mainfrom
feat/ignore-constraints-section
Jun 9, 2026
Merged

feat: add constraints section to .pgschemaignore (#429, #447)#452
tianzhou merged 2 commits into
mainfrom
feat/ignore-constraints-section

Conversation

@tianzhou

@tianzhou tianzhou commented Jun 9, 2026

Copy link
Copy Markdown
Contributor

Summary

Adds a [constraints] section to .pgschemaignore that matches table constraints by name (glob). Ignored constraints are filtered at the inspector, so they are excluded from dump, plan generation, and drift detection alike — pgschema neither creates, drops, nor reports them.

[constraints]
patterns = ["fk_*", "!fk_core_*"]

This is one feature that addresses two related requests:

Implementation

Mirrors the existing per-object ignore pattern (the [indexes] section from #441) end to end:

  • ir/ignore.goConstraints []string field + ShouldIgnoreConstraint(name)
  • ir/inspector.go — skip ignored constraints at the single attach site in the constraint loop
  • cmd/util/ignoreloader.goConstraintIgnoreConfig TOML struct + wiring
  • docs/cli/ignore.mdx — new ## Constraints section with use cases + a footgun warning (also backfilled the previously-missing [indexes] example)

Testing

  • ir unit tests — ShouldIgnoreConstraint + nil-config coverage
  • cmd/util loader test — parses [constraints] patterns
  • cmd/TestIgnoreConstraints integration test (embedded PG): a manually-added fk_products_category is excluded from both dump output and the plan (no spurious DROP CONSTRAINT), while the managed products_pkey is retained

Design note

Matching is by bare constraint name (consistent with how [indexes]/[sequences] match), which is not globally unique across tables. Documented with a warning about broad patterns. Happy to switch to table.constraint qualified matching if preferred.

🤖 Generated with Claude Code

Adds a new [constraints] section to .pgschemaignore that matches table
constraints by name (glob). Ignored constraints are filtered at the
inspector, so they are excluded from dump, plan generation, and drift
detection alike — pgschema neither creates, drops, nor reports them.

Use cases:
- Out-of-band constraints, e.g. disabled during an AWS DMS migration and
  re-added manually afterward, that plan should not flag for drop (#447).
- Cross-schema foreign keys: ignore them to bootstrap each schema
  independently, then drop the ignore once all tables exist (#429).

Mirrors the existing per-object pattern (Indexes, #441): Constraints
[]string on IgnoreConfig with ShouldIgnoreConstraint(name), a
ConstraintIgnoreConfig struct on TomlConfig, and a filter in the
inspector's constraint attach loop.

Fixes #447

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings June 9, 2026 02:43
@JackRyanTR

Copy link
Copy Markdown

Thank you so much for the quick turnaround on this!

@greptile-apps

greptile-apps Bot commented Jun 9, 2026

Copy link
Copy Markdown

Greptile Summary

This PR adds constraint-name ignore support to .pgschemaignore. The main changes are:

  • A new [constraints] section is parsed from ignore files.
  • IgnoreConfig can match constraint names with existing glob and negation behavior.
  • The inspector skips matching table constraints during IR construction.
  • Tests and docs cover constraint ignores for dump and plan output.

Confidence Score: 4/5

This is close, but the plan path can skip creating declared constraints.

  • Constraint filtering works for hiding unmanaged live objects.
  • The same filter is applied to desired-state inspection.
  • Matching constraints declared in the schema file can be removed before diffing.

cmd/plan/plan.go and ir/inspector.go need the desired-state filtering behavior clarified or changed.

Important Files Changed

Filename Overview
ir/inspector.go Adds the table-constraint filtering point used by both current and desired inspections.
cmd/plan/plan.go Passes the loaded ignore config into both sides of plan generation.
cmd/util/ignoreloader.go Wires [constraints].patterns into the shared ignore config.

Reviews (1): Last reviewed commit: "feat: add constraints section to .pgsche..." | Re-trigger Greptile

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Adds support for ignoring table constraints by name via a new [constraints] section in .pgschemaignore, integrating it into IR inspection so ignored constraints are excluded from dump output, plan generation, and drift detection.

Changes:

  • Extend ir.IgnoreConfig with Constraints + ShouldIgnoreConstraint(name) pattern matching.
  • Filter ignored constraints during IR inspection (Inspector.buildConstraints) so they never enter the IR.
  • Wire TOML loading, update CLI docs, and add unit + loader + integration test coverage.

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
ir/inspector.go Skips attaching ignored constraints into table IR.
ir/ignore.go Adds Constraints patterns and ShouldIgnoreConstraint.
ir/ignore_test.go Extends ignore unit tests to cover constraints and nil-config behavior.
cmd/util/ignoreloader.go Adds [constraints] TOML section parsing and wiring into ir.IgnoreConfig.
cmd/util/ignoreloader_test.go Validates [constraints] parsing in loader tests.
cmd/ignore_integration_test.go Adds embedded-Postgres integration test asserting ignored constraints are excluded from dump and plan output.
docs/cli/ignore.mdx Documents the new [constraints] section and adds missing [indexes] example.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread ir/inspector.go Outdated
Move the ShouldIgnoreConstraint check into the initial constraint loop,
before getConstraintColumnPosition runs per column, so ignored
constraints no longer incur N+1 DB queries that are immediately
discarded. The attach-time check is removed since ignored constraints
now never enter constraintGroups.

Addresses Copilot review feedback on #452.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 7 out of 7 changed files in this pull request and generated no new comments.

@tianzhou tianzhou merged commit 0abf597 into main Jun 9, 2026
2 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.

3 participants