feat: add constraints section to .pgschemaignore (#429, #447)#452
Conversation
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>
|
Thank you so much for the quick turnaround on this! |
Greptile SummaryThis PR adds constraint-name ignore support to
Confidence Score: 4/5This is close, but the plan path can skip creating declared constraints.
cmd/plan/plan.go and ir/inspector.go need the desired-state filtering behavior clarified or changed. Important Files Changed
Reviews (1): Last reviewed commit: "feat: add constraints section to .pgsche..." | Re-trigger Greptile |
There was a problem hiding this comment.
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.IgnoreConfigwithConstraints+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.
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>
Summary
Adds a
[constraints]section to.pgschemaignorethat 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.This is one feature that addresses two related requests:
pgschema plandoes not flag them for drop. (closes)Implementation
Mirrors the existing per-object ignore pattern (the
[indexes]section from #441) end to end:ir/ignore.go—Constraints []stringfield +ShouldIgnoreConstraint(name)ir/inspector.go— skip ignored constraints at the single attach site in the constraint loopcmd/util/ignoreloader.go—ConstraintIgnoreConfigTOML struct + wiringdocs/cli/ignore.mdx— new## Constraintssection with use cases + a footgun warning (also backfilled the previously-missing[indexes]example)Testing
irunit tests —ShouldIgnoreConstraint+ nil-config coveragecmd/utilloader test — parses[constraints]patternscmd/TestIgnoreConstraintsintegration test (embedded PG): a manually-addedfk_products_categoryis excluded from both dump output and the plan (no spuriousDROP CONSTRAINT), while the managedproducts_pkeyis retainedDesign 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 totable.constraintqualified matching if preferred.🤖 Generated with Claude Code