Skip to content

#242 materialized view is dropped and fully rebuilt on any unrelated column change to a table it references - #247

Merged
nettrash merged 2 commits into
v1.0.27from
242-materialized-view-is-dropped-and-fully-rebuilt-on-any-unrelated-column-change-to-a-table-it-references
Sep 5, 2026
Merged

nettrash merged 2 commits into
v1.0.27from
242-materialized-view-is-dropped-and-fully-rebuilt-on-any-unrelated-column-change-to-a-table-it-references

Conversation

@nettrash

@nettrash nettrash commented Sep 5, 2026

Copy link
Copy Markdown
Owner

Closes #242

@nettrash nettrash added this to the v1.0.27 milestone Sep 5, 2026
@nettrash nettrash self-assigned this Sep 5, 2026
Copilot AI lite review requested due to automatic review settings September 5, 2026 19:34

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

The new type_differs predicate can miss alter-type cases (e.g., interval qualifiers/collation), potentially causing migrations to attempt ALTER COLUMN ... TYPE while dependent views still exist.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Pull request overview

This PR addresses #242 by making view-drop decisions column-aware (including materialized views) so that unrelated table changes (e.g., ADD COLUMN) no longer force unnecessary DROP MATERIALIZED VIEW + full rebuilds.

Changes:

  • Add View::column_relation to dumps (sourced from pg_depend on the view’s _RETURN rule) to track per-column dependencies.
  • Update Comparer::dependent_view_keys to drop views only when a referenced table is dropped/recreated or when a view reads a dropped/retyped column.
  • Add fixtures, Rust tests, and a CI assertion to prevent regressions where unread-column changes drag views along.
File summaries
File Description
app/src/comparer/core.rs Switch dependency detection from table-level to column-level for view dropping.
app/src/dump/core.rs Extend view dump SQL to include column_relation collected from pg_depend.
app/src/dump/view.rs Add optional column_relation field to the View dump model (excluded from view hash).
app/src/dump/table_column.rs Introduce type_differs helper for determining “retype” changes.
app/src/dump/table.rs Reuse type_differs for partition recreate gating to keep predicates aligned.
app/src/comparer/tests/core/view_column_dependencies.rs Add focused tests for “unread column change should not drop/rebuild views” behavior.
app/src/comparer/tests/core.rs Wire the new test module into the test suite.
data/test/schema_a.sql Add FROM fixture objects for issue #242 reproduction.
data/test/schema_b.sql Add TO fixture objects for issue #242 reproduction.
data/test/README.md Document the new #242 guard and why round-2 diffs can’t catch it.
.github/workflows/rust.yml Add a CI grep-based assertion against the round-1 script to catch over-eager view drops.
CHANGELOG Document the #242 fix and dump format change (optional field).
Review details
  • Files reviewed: 12/12 changed files
  • Comments generated: 1
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread app/src/dump/table_column.rs
Copilot AI review requested due to automatic review settings September 5, 2026 20:04

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🔵 Needs a closer look

There are a couple of small but concrete issues in the updated docs/CI check (including a regex that can match unintentionally) that should be corrected before approval.

Review details

Suppressed comments (2)

Previously missed (2) — in code that hasn't changed since the last review.

.github/workflows/rust.yml:201

  • The grep pattern uses test_schema.${v} in an ERE, where . is a wildcard; this can match unintended strings and make the CI check flaky. Escape the dot (and optionally anchor/require the trailing semicolon) so the match is exact.
    app/src/dump/table_column.rs:387
  • The doc comment /// Hash now sits on type_differs, but this method isn’t a hashing routine. This makes the generated docs misleading; rename this line to describe the predicate (or remove it) so it reflects what the method actually does.
  • Files reviewed: 12/12 changed files
  • Comments generated: 0 new
  • Review effort level: Lite

@nettrash
nettrash merged commit e976de2 into v1.0.27 Sep 5, 2026
17 checks passed
@nettrash
nettrash deleted the 242-materialized-view-is-dropped-and-fully-rebuilt-on-any-unrelated-column-change-to-a-table-it-references branch September 6, 2026 08:23
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