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
16 changes: 16 additions & 0 deletions cmd/util/ignoreloader.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ type TomlConfig struct {
Sequences SequenceIgnoreConfig `toml:"sequences,omitempty"`
Privileges PrivilegeIgnoreConfig `toml:"privileges,omitempty"`
DefaultPrivileges DefaultPrivilegeIgnoreConfig `toml:"default_privileges,omitempty"`
Constraints ConstraintIgnoreConfig `toml:"constraints,omitempty"`
ConstraintsFK ConstraintFKIgnoreConfig `toml:"constraints_fk,omitempty"`
}
Comment on lines 36 to 41

// TableIgnoreConfig represents table-specific ignore configuration
Expand Down Expand Up @@ -80,6 +82,18 @@ 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"`
}

// ConstraintFKIgnoreConfig represents foreign key constraint-specific ignore configuration
// Patterns match constraint names, including optionally qualified names
type ConstraintFKIgnoreConfig 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 +127,8 @@ func LoadIgnoreFileWithStructureFromPath(filePath string) (*ir.IgnoreConfig, err
Sequences: tomlConfig.Sequences.Patterns,
Privileges: tomlConfig.Privileges.Patterns,
DefaultPrivileges: tomlConfig.DefaultPrivileges.Patterns,
Constraints: tomlConfig.Constraints.Patterns,
ConstraintsFK: tomlConfig.ConstraintsFK.Patterns,
}

return config, nil
Expand Down
2 changes: 1 addition & 1 deletion internal/diff/diff.go
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,7 @@ type viewDiff struct {
CommentChanged bool
OldComment string
NewComment string
OptionsChanged bool // View options (reloptions) changed
OptionsChanged bool // View options (reloptions) changed
AddedIndexes []*ir.Index // For materialized views
DroppedIndexes []*ir.Index // For materialized views
ModifiedIndexes []*IndexDiff // For materialized views
Expand Down
20 changes: 19 additions & 1 deletion ir/ignore.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ type IgnoreConfig struct {
Sequences []string `toml:"sequences,omitempty"`
Privileges []string `toml:"privileges,omitempty"`
DefaultPrivileges []string `toml:"default_privileges,omitempty"`
Constraints []string `toml:"constraints,omitempty"`
ConstraintsFK []string `toml:"constraints_fk,omitempty"`
}

// ShouldIgnoreTable checks if a table should be ignored based on the patterns
Expand Down Expand Up @@ -114,6 +116,22 @@ 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 +120 to +124
}
Comment on lines +119 to +125
Comment on lines +119 to +125

// ShouldIgnoreConstraintFK checks if a foreign key constraint should be ignored based on the patterns
func (c *IgnoreConfig) ShouldIgnoreConstraintFK(constraintName string) bool {
if c == nil {
return false
}
return c.shouldIgnore(constraintName, c.ConstraintsFK)
}

// 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 Expand Up @@ -162,4 +180,4 @@ func matchPattern(pattern, name string) bool {
return pattern == name
}
return matched
}
}
24 changes: 24 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 Expand Up @@ -499,6 +511,18 @@ func (i *Inspector) buildConstraints(ctx context.Context, schema *IR, targetSche

// Handle foreign key references
if cType == ConstraintTypeForeignKey {
// 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.ShouldIgnoreConstraintFK(qualifiedConstraintName) ||
i.ignoreConfig.ShouldIgnoreConstraintFK(constraintName) {
continue
}
}

if refSchema := i.safeInterfaceToString(constraint.ForeignTableSchema); refSchema != "" && refSchema != "<nil>" {
c.ReferencedSchema = refSchema
}
Expand Down