Skip to content

fix: INSTEAD OF triggers on views missing from dump (#287)#292

Merged
tianzhou merged 3 commits intomainfrom
fix/issue-287-instead-of-view-trigger
Feb 16, 2026
Merged

fix: INSTEAD OF triggers on views missing from dump (#287)#292
tianzhou merged 3 commits intomainfrom
fix/issue-287-instead-of-view-trigger

Conversation

@tianzhou
Copy link
Contributor

Summary

  • INSTEAD OF triggers on views were not being extracted during schema inspection because buildTriggers() only checked the Tables map, not the Views map
  • Added Triggers field to the View IR struct and updated the inspector to associate triggers with views when the relation is a view
  • Fixed the latent INSTEAD_OF formatting bug (should be INSTEAD OF with a space) in the TriggerTimingInsteadOf constant
  • Added proper schema normalization for view triggers during plan generation (prevents temp schema names leaking into plan output)
  • Separated view loading from trigger/policy loading in the inspector's concurrent query groups to prevent a race condition where buildTriggers could run before buildViews populated the Views map
  • Added DiffTypeViewTrigger type for proper directory placement in multi-file dump mode and trigger diffing for view modifications

Fixes #287

Test plan

  • Added diff test case testdata/diff/create_trigger/issue_287_instead_of_view_trigger/ with old.sql (view without trigger) and new.sql (view with INSTEAD OF trigger)
  • Diff test passes: PGSCHEMA_TEST_FILTER="create_trigger/issue_287" go test -v ./internal/diff -run TestDiffFromFiles
  • Integration test passes with idempotency: PGSCHEMA_TEST_FILTER="create_trigger/issue_287" go test -v ./cmd -run TestPlanAndApply
  • Full test suite passes: go test ./...

🤖 Generated with Claude Code

INSTEAD OF triggers on views were not being extracted during schema
inspection because buildTriggers() only checked the Tables map, not the
Views map. This also fixes the latent INSTEAD_OF formatting bug (should
be INSTEAD OF with a space) and adds proper schema normalization for
view triggers during plan generation.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings February 16, 2026 10:51
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

Fixes schema dumping/diffing gaps for INSTEAD OF triggers on views by carrying view triggers through the IR, inspector, diff engine, and dump formatter so they appear in dumps and migration plans.

Changes:

  • Extend IR + inspector to associate triggers with views (not just tables) and avoid a view/trigger load race.
  • Add view.trigger diff type and generate create/modify/drop SQL for view triggers (including correct INSTEAD OF formatting).
  • Add testdata coverage for issue #287 and normalize view-trigger schema references during plan generation.

Reviewed changes

Copilot reviewed 13 out of 13 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
ir/ir.go Adds View.Triggers and fixes INSTEAD OF timing string.
ir/inspector.go Ensures views load before triggers; stores triggers on either tables or views.
internal/diff/diff.go Adds DiffTypeViewTrigger and diffs view triggers as part of view modifications.
internal/diff/view.go Emits create/modify SQL for view triggers and computes trigger diffs between views.
internal/diff/trigger.go Adds helpers to create/drop view-trigger diffs.
internal/dump/formatter.go Places view.trigger diffs under views/ in multi-file dump mode.
cmd/plan/plan.go Normalizes schema references inside view triggers during plan generation.
testdata/diff/create_trigger/issue_287_instead_of_view_trigger/* Adds regression fixtures validating trigger diff/plan output.

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

tianzhou and others added 2 commits February 16, 2026 05:13
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- Normalize view triggers in normalizeView() for consistent dump output
- Sort diffViewTriggers output deterministically to avoid flaky diffs
- Move view trigger drops to early drop phase before function drops

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
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

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


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

@tianzhou tianzhou merged commit 2a8e6b1 into main Feb 16, 2026
7 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.

INSTEAD OF triggers on views are missing from dump

1 participant