Skip to content

Add support for indexes section in .pgschemaignore#441

Merged
tianzhou merged 1 commit into
pgplex:mainfrom
guillaume86:probe/ignore-indexes
May 30, 2026
Merged

Add support for indexes section in .pgschemaignore#441
tianzhou merged 1 commit into
pgplex:mainfrom
guillaume86:probe/ignore-indexes

Conversation

@guillaume86
Copy link
Copy Markdown
Contributor

@guillaume86 guillaume86 commented May 23, 2026

Summary

  • Adds an [indexes] section to .pgschemaignore so users can keep indexes that exist in the live database but are not declared in their schema .sql files. Without this, manually-added indexes (perf hotfixes, ad-hoc operational fixes) are flagged for drop by pgschema plan.
  • IgnoreConfig.Indexes + ShouldIgnoreIndex(name) mirror the existing per-object pattern.
  • Inspector.buildIndexes skips ignored index names before they enter the IR, so they don't appear in dump and don't show up as drift in plan.

Fixes #406

Test plan

  • Added TestIgnoreIndexes (in cmd/ignore_integration_test.go) reproducing the exact Add support for indexes to .pgschemaignore #406 scenario: a manual_perf_idx exists on a managed table, the desired schema doesn't declare it, the ignore config lists manual_*. Asserts the dump excludes it and the plan does not reference it.
  • Extended TestIgnoreConfig_AllObjectTypes and TestIgnoreConfig_NilConfig to cover indexes.
  • Extended TestLoadIgnoreFileFromPath_ValidTOML to round-trip the new [indexes] section.
  • Full suite green locally on PG 17 (go test ./... — ~7 min).

Run just the new test:

go test -v ./cmd -run TestIgnoreIndexes

🤖 Generated with Claude Code


Note (2026-05-23): pgproj (a downstream DACFX-shaped fork at https://github.com/guillaume86/pgproj) has adopted a hard-fork posture and will continue independently. This contribution remains open without expectation of merge; happy to address review feedback if a maintainer engages.

Adds a new [indexes] section to .pgschemaignore that lets users
preserve indexes which exist in the database but are not declared
in their .sql files. Without this, manually-added indexes (e.g.
perf hotfixes) are flagged for drop by `pgschema plan`.

Mirrors the existing per-object pattern: `Indexes []string` on
`IgnoreConfig` with `ShouldIgnoreIndex(name)`, an
`IndexIgnoreConfig` struct on `TomlConfig`, and a filter in
`Inspector.buildIndexes` that skips ignored index names before
they enter the IR.

Fixes pgplex#406

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@greptile-apps
Copy link
Copy Markdown

greptile-apps Bot commented May 23, 2026

Greptile Summary

This PR adds ignore support for database indexes. The main changes are:

  • Adds an [indexes] section to .pgschemaignore parsing.
  • Adds IgnoreConfig.Indexes and ShouldIgnoreIndex.
  • Skips ignored indexes during database inspection.
  • Adds tests for loader parsing, nil handling, and dump/plan behavior.

Confidence Score: 5/5

This looks safe to merge.

  • No blocking issues found in the changed code.
  • The new index ignore path follows the existing object ignore pattern.
  • Constraint-backed indexes remain handled by the existing constraint flow.

Reviews (1): Last reviewed commit: "Add support for indexes section in .pgsc..." | Re-trigger Greptile

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

This PR extends pgschema’s ignore configuration so users can exempt specific indexes from inspection/diffing, preventing pgschema plan from proposing drops for operationally-created indexes that aren’t declared in desired-state SQL.

Changes:

  • Added [indexes] support to .pgschemaignore via IgnoreConfig.Indexes + ShouldIgnoreIndex.
  • Updated ignore-file TOML loader to parse the new indexes section into ir.IgnoreConfig.
  • Updated inspector index discovery to skip ignored index names, and added unit + integration coverage for the #406 scenario.

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated no comments.

Show a summary per file
File Description
ir/inspector.go Skips indexes during inspection when they match ignore patterns, keeping them out of IR/dump/plan.
ir/ignore.go Adds Indexes patterns and ShouldIgnoreIndex helper to mirror existing ignore APIs.
ir/ignore_test.go Extends ignore unit tests to cover indexes and nil-config behavior.
cmd/util/ignoreloader.go Extends .pgschemaignore TOML structure parsing to include [indexes] patterns = [...].
cmd/util/ignoreloader_test.go Verifies the loader round-trips the new [indexes] section into IgnoreConfig.Indexes.
cmd/ignore_integration_test.go Adds an integration test reproducing #406 to ensure ignored live-only indexes don’t appear in dump/plan.

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

Copy link
Copy Markdown
Contributor

@tianzhou tianzhou left a comment

Choose a reason for hiding this comment

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

LGTM. Thanks for the contribution.

@tianzhou tianzhou merged commit 8dc3100 into pgplex:main May 30, 2026
2 checks passed
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.

Add support for indexes to .pgschemaignore

3 participants