Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions cmd/util/ignoreloader.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ type TomlConfig struct {
Sequences SequenceIgnoreConfig `toml:"sequences,omitempty"`
Privileges PrivilegeIgnoreConfig `toml:"privileges,omitempty"`
DefaultPrivileges DefaultPrivilegeIgnoreConfig `toml:"default_privileges,omitempty"`
Constraints ConstraintIgnoreConfig `toml:"constraints,omitempty"`
}
Comment on lines 36 to 40

// TableIgnoreConfig represents table-specific ignore configuration
Expand Down Expand Up @@ -80,6 +81,12 @@ type DefaultPrivilegeIgnoreConfig struct {
Patterns []string `toml:"patterns,omitempty"`
}

// ConstraintIgnoreConfig represents constraint-specific ignore configuration
// Patterns match constraint names, including optionally qualified names
type ConstraintIgnoreConfig struct {
Patterns []string `toml:"patterns,omitempty"`
}

// LoadIgnoreFileWithStructure loads the .pgschemaignore file using the structured TOML format
// and converts it to the simple IgnoreConfig structure
func LoadIgnoreFileWithStructure() (*ir.IgnoreConfig, error) {
Expand Down Expand Up @@ -113,6 +120,7 @@ func LoadIgnoreFileWithStructureFromPath(filePath string) (*ir.IgnoreConfig, err
Sequences: tomlConfig.Sequences.Patterns,
Privileges: tomlConfig.Privileges.Patterns,
DefaultPrivileges: tomlConfig.DefaultPrivileges.Patterns,
Constraints: tomlConfig.Constraints.Patterns,
}

return config, nil
Expand Down
9 changes: 9 additions & 0 deletions ir/ignore.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ type IgnoreConfig struct {
Sequences []string `toml:"sequences,omitempty"`
Privileges []string `toml:"privileges,omitempty"`
DefaultPrivileges []string `toml:"default_privileges,omitempty"`
Constraints []string `toml:"constraints,omitempty"`
}

// ShouldIgnoreTable checks if a table should be ignored based on the patterns
Expand Down Expand Up @@ -114,6 +115,14 @@ func (c *IgnoreConfig) ShouldIgnoreDefaultPrivilege(grantee string) bool {
return c.shouldIgnore(grantee, c.DefaultPrivileges)
}

// 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)
Comment on lines +119 to +123
}
Comment on lines +118 to +124
Comment on lines +118 to +124

// shouldIgnore checks if a name should be ignored based on the patterns
// Patterns support wildcards (*) and negation (!)
// Negation patterns (starting with !) take precedence over inclusion patterns
Expand Down
12 changes: 12 additions & 0 deletions ir/inspector.go
Original file line number Diff line number Diff line change
Expand Up @@ -447,6 +447,18 @@ func (i *Inspector) buildConstraints(ctx context.Context, schema *IR, targetSche
constraintType = constraint.ConstraintType.String
}

// Check if constraint should be ignored. Prefer a fully qualified
// identifier to avoid unintentionally ignoring same-named constraints
// on unrelated tables, while still supporting bare constraint-name
// matching for backwards compatibility.
if i.ignoreConfig != nil {
qualifiedConstraintName := fmt.Sprintf("%s.%s.%s", schemaName, tableName, constraintName)
if i.ignoreConfig.ShouldIgnoreConstraint(qualifiedConstraintName) ||
i.ignoreConfig.ShouldIgnoreConstraint(constraintName) {
Comment on lines +450 to +457
continue
}
}

// Extract column name from sql.NullString
columnName := ""
if constraint.ColumnName.Valid {
Expand Down