Skip to content

Comments

fix: preserve constraints to ignored tables in multi-file dumps#171

Merged
tianzhou merged 1 commit intomainfrom
fk_ignore
Nov 24, 2025
Merged

fix: preserve constraints to ignored tables in multi-file dumps#171
tianzhou merged 1 commit intomainfrom
fk_ignore

Conversation

@tianzhou
Copy link
Contributor

Fix #167

Problem:
Foreign key constraints referencing ignored tables were being lost in multi-file dumps (--multi-file flag). Single-file dumps worked correctly.

Root Cause:
In internal/dump/formatter.go, two issues prevented constraints from being properly grouped with their tables in multi-file output:

  1. DiffTypeTableConstraint was missing from getGroupingName() switch statement, so constraints weren't grouped with their parent tables
  2. "table.constraint" was missing from getObjectDirectory() case statement, so constraints went to "misc" directory instead of "tables"

Solution:

  • Added DiffTypeTableConstraint to getGroupingName() to group constraints with their tables (line 252)
  • Added "table.constraint" to getObjectDirectory() case statement to route constraints to tables directory (line 246)
  • Added *ir.Constraint case to extractTableNameFromContext() to extract table name from constraint objects (line 335)

Copilot AI review requested due to automatic review settings November 24, 2025 16:41
Copy link
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

This PR fixes issue #167 where foreign key constraints referencing ignored tables were being lost in multi-file dumps. The fix addresses the root cause in the dump formatter by ensuring constraints are properly grouped with their parent tables.

Key Changes:

  • Added DiffTypeTableConstraint handling to formatter grouping logic to group constraints with tables
  • Added "table.constraint" case to route constraints to the tables directory instead of misc
  • Enhanced integration tests to verify FK constraints, triggers, and views on ignored tables work in both single-file and multi-file dumps

Reviewed changes

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

File Description
internal/dump/formatter.go Added constraint handling to getObjectDirectory(), getGroupingName(), and extractTableNameFromContext() to ensure constraints are grouped with their parent tables in multi-file dumps
cmd/ignore_integration_test.go Renamed and expanded test to comprehensively verify dependencies (FK constraints, triggers, views) on ignored tables work correctly in both single-file and multi-file dump modes

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

**Problem:**
Foreign key constraints referencing ignored tables were being lost in
multi-file dumps (--multi-file flag). Single-file dumps worked correctly.

**Root Cause:**
In internal/dump/formatter.go, two issues prevented constraints from being
properly grouped with their tables in multi-file output:

1. DiffTypeTableConstraint was missing from getGroupingName() switch
   statement, so constraints weren't grouped with their parent tables
2. "table.constraint" was missing from getObjectDirectory() case statement,
   so constraints went to "misc" directory instead of "tables"

**Solution:**
- Added DiffTypeTableConstraint to getGroupingName() to group constraints
  with their tables (line 252)
- Added "table.constraint" to getObjectDirectory() case statement to route
  constraints to tables directory (line 246)
- Added *ir.Constraint case to extractTableNameFromContext() to extract
  table name from constraint objects (line 335)

**Testing:**
- Added comprehensive test testDependenciesOnIgnoredTables() that verifies
  FK constraints, triggers, and views referencing ignored tables are
  preserved in both single-file and multi-file dumps
- Consolidated 5 redundant test functions into 1 comprehensive test
- Reduced test file from 1450 to 980 lines (32% reduction)
- All existing tests pass

**Documentation:**
- Updated docs/cli/ignore.mdx to document allowlist patterns and
  dependencies on ignored tables

Fixes #167

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
@tianzhou tianzhou merged commit 2c44365 into main Nov 24, 2025
2 checks passed
@tianzhou tianzhou deleted the fk_ignore branch December 5, 2025 15:44
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.

Foreign key constraints is ignored if it references tables from pgschemaignore in multi-file setup

1 participant