Skip to content

feat: add constraints in .pgschemaignore#430

Open
RicardoBorgesGO wants to merge 5 commits into
pgplex:mainfrom
RicardoBorgesGO:main
Open

feat: add constraints in .pgschemaignore#430
RicardoBorgesGO wants to merge 5 commits into
pgplex:mainfrom
RicardoBorgesGO:main

Conversation

@RicardoBorgesGO
Copy link
Copy Markdown

This PR a scenario where the system is separated into large modules, each module has a separate schema, but there are foreign keys between these schemas, making it impossible to use pgschema for migrations.

Issue #429

@greptile-apps
Copy link
Copy Markdown

greptile-apps Bot commented May 12, 2026

Greptile Summary

This PR adds a [constraints] section to .pgschemaignore, letting users exclude named constraints (typically cross-schema foreign keys) from pgschema's inspection and migration planning.

  • cmd/util/ignoreloader.go: New ConstraintsIgnoreConfig TOML type is added and its patterns are forwarded to ir.IgnoreConfig; the doc comment is a verbatim copy-paste from DefaultPrivilegeIgnoreConfig and incorrectly describes grantee role names.
  • ir/ignore.go: ShouldIgnoreConstraints (plural) breaks the ShouldIgnore[Singular] naming convention used by every other method in the file (ShouldIgnoreTable, ShouldIgnoreView, etc.).
  • ir/inspector.go: The ignore guard is correctly placed before the composite-constraint grouping loop, so all rows for a multi-column constraint are uniformly skipped; no test coverage is added for this new ignore category.

Confidence Score: 4/5

Safe to merge with minor polish; the core filtering logic is correct and consistent with existing patterns.

The ignore guard in buildConstraints is placed correctly and the end-to-end wiring from TOML to IgnoreConfig to inspector is sound. The issues found are a stale copy-pasted doc comment, a plural method name that breaks the established ShouldIgnore[Singular] convention, and no integration tests for the new section — none of these affect runtime correctness today.

cmd/util/ignoreloader.go needs its stale doc comment fixed; ir/ignore.go and ir/inspector.go need the method renamed from plural to singular to stay consistent with the rest of the codebase.

Important Files Changed

Filename Overview
cmd/util/ignoreloader.go Adds ConstraintsIgnoreConfig type and wires it into TOML parsing; the struct's doc comment is stale copy-paste and no tests are added for the new section.
ir/ignore.go Adds Constraints []string field to IgnoreConfig and a new ShouldIgnoreConstraints method; the method name is plural where every other method uses the singular form.
ir/inspector.go Adds a constraint-ignore check early in buildConstraints, correctly before group accumulation; consistent with how other object types are filtered.

Sequence Diagram

sequenceDiagram
    participant User
    participant ignoreloader as cmd/util/ignoreloader.go
    participant IgnoreConfig as ir/ignore.go (IgnoreConfig)
    participant Inspector as ir/inspector.go (Inspector)
    participant PG as PostgreSQL

    User->>ignoreloader: LoadIgnoreFileWithStructureFromPath()
    ignoreloader->>ignoreloader: toml.DecodeFile to TomlConfig Constraints
    ignoreloader->>IgnoreConfig: IgnoreConfig Constraints from tomlConfig.Constraints.Patterns

    Inspector->>PG: GetConstraintsForSchema(targetSchema)
    PG-->>Inspector: constraint rows
    loop each constraint row
        Inspector->>IgnoreConfig: ShouldIgnoreConstraints(constraintName)
        alt pattern matches
            IgnoreConfig-->>Inspector: true, skip row
        else no match
            IgnoreConfig-->>Inspector: false, process constraint
            Inspector->>Inspector: accumulate into constraintGroups
        end
    end
    Inspector->>Inspector: attach constraints to tables in IR
Loading

Reviews (1): Last reviewed commit: "🚀 add constraints in .pgschemaignore" | Re-trigger Greptile

Comment thread cmd/util/ignoreloader.go Outdated
Comment on lines +84 to +88
// ConstraintsIgnoreConfig represents default privilege-specific ignore configuration
// Patterns match on grantee role names
type ConstraintsIgnoreConfig struct {
Patterns []string `toml:"patterns,omitempty"`
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Stale copy-pasted comment on ConstraintsIgnoreConfig

The doc comment for this type was copied verbatim from DefaultPrivilegeIgnoreConfig and still describes grantee role names, which is unrelated to constraints. Any reader trying to understand what patterns should look like will be misled into thinking they should supply role names instead of constraint names.

Comment thread ir/ignore.go Outdated
Comment thread ir/inspector.go Outdated
Comment thread cmd/util/ignoreloader.go Outdated
Comment on lines +84 to +88
// ConstraintsIgnoreConfig represents default privilege-specific ignore configuration
// Patterns match on grantee role names
type ConstraintsIgnoreConfig struct {
Patterns []string `toml:"patterns,omitempty"`
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 No integration tests for the new constraints ignore section

Every other ignore category (tables, views, functions, sequences, privileges, default_privileges) has coverage in cmd/ignore_integration_test.go. A foreign-key scenario is the explicit motivation for this PR, yet there are no tests that verify a cross-schema FK is correctly filtered out of the dump/plan output. Without this, a regression (e.g., pattern not matching, scoping bug) would go undetected.

RicardoBorgesGO and others added 2 commits May 12, 2026 13:59
rename func ShouldIgnoreConstraints

Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com>
rename ShouldIgnoreConstraints

Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com>
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

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 constraints via .pgschemaignore to better support multi-module deployments where cross-schema foreign keys/constraints should not be managed by a given module’s migration runs (Issue #429).

Changes:

  • Added constraints patterns to ir.IgnoreConfig plus a ShouldIgnoreConstraint helper.
  • Extended .pgschemaignore structured TOML loader to parse a new [constraints] section.
  • Updated DB inspection to skip building constraints whose names match the ignore patterns.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 5 comments.

File Description
ir/inspector.go Skips building ignored constraints during DB inspection.
ir/ignore.go Adds constraints ignore patterns and ShouldIgnoreConstraint.
cmd/util/ignoreloader.go Adds TOML parsing/mapping for [constraints] section.

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

Comment thread cmd/util/ignoreloader.go Outdated
Comment thread ir/inspector.go Outdated
Comment on lines +450 to +452
// Check if constraint should be ignored
if i.ignoreConfig != nil && i.ignoreConfig.ShouldIgnoreConstraint(constraintName) {
continue
Comment thread cmd/util/ignoreloader.go
Comment on lines 36 to 40
Sequences SequenceIgnoreConfig `toml:"sequences,omitempty"`
Privileges PrivilegeIgnoreConfig `toml:"privileges,omitempty"`
DefaultPrivileges DefaultPrivilegeIgnoreConfig `toml:"default_privileges,omitempty"`
Constraints ConstraintsIgnoreConfig `toml:"constraints,omitempty"`
}
Comment thread ir/ignore.go
Comment on lines 23 to +27
Types []string `toml:"types,omitempty"`
Sequences []string `toml:"sequences,omitempty"`
Privileges []string `toml:"privileges,omitempty"`
DefaultPrivileges []string `toml:"default_privileges,omitempty"`
Constraints []string `toml:"constraints,omitempty"`
Comment thread ir/ignore.go
Comment on lines +119 to +123
func (c *IgnoreConfig) ShouldIgnoreConstraint(constraintName string) bool {
if c == nil {
return false
}
return c.shouldIgnore(constraintName, c.Constraints)
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

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 3 out of 3 changed files in this pull request and generated 3 comments.

Comment thread cmd/util/ignoreloader.go Outdated
Comment on lines +84 to +85
// ConstraintsIgnoreConfig represents default privilege-specific ignore configuration
// Patterns match on grantee role names
Comment thread cmd/util/ignoreloader.go
Comment on lines 28 to 40
// TomlConfig represents the TOML structure of the .pgschemaignore file
// This is used for parsing more complex configurations if needed in the future
type TomlConfig struct {
Tables TableIgnoreConfig `toml:"tables,omitempty"`
Views ViewIgnoreConfig `toml:"views,omitempty"`
Functions FunctionIgnoreConfig `toml:"functions,omitempty"`
Procedures ProcedureIgnoreConfig `toml:"procedures,omitempty"`
Types TypeIgnoreConfig `toml:"types,omitempty"`
Sequences SequenceIgnoreConfig `toml:"sequences,omitempty"`
Privileges PrivilegeIgnoreConfig `toml:"privileges,omitempty"`
DefaultPrivileges DefaultPrivilegeIgnoreConfig `toml:"default_privileges,omitempty"`
Constraints ConstraintsIgnoreConfig `toml:"constraints,omitempty"`
}
Comment thread ir/ignore.go
Comment on lines +118 to +124
// ShouldIgnoreConstraint checks if a constraint should be ignored based on the patterns
func (c *IgnoreConfig) ShouldIgnoreConstraint(constraintName string) bool {
if c == nil {
return false
}
return c.shouldIgnore(constraintName, c.Constraints)
}
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
@RicardoBorgesGO RicardoBorgesGO changed the title 🚀 add constraints in .pgschemaignore feat: add constraints in .pgschemaignore May 13, 2026
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