Conversation
…rier) (#343) Track pg_class.reloptions for views and include WITH clause in generated DDL. This preserves security_invoker=true and other view options during plan/apply. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Greptile SummaryThis PR adds support for tracking and generating view Key changes:
Issues identified:
Confidence Score: 3/5
Flowchart%%{init: {'theme': 'neutral'}}%%
flowchart TD
A[View in pg_class] -->|c.reloptions| B[GetViewsForSchema query]
B -->|pq.Array scan| C[GetViewsForSchemaRow.Reloptions]
C --> D[Inspector.buildViews]
D -->|View.Options| E[IR View struct]
E --> F{Diff: viewsEqual?}
F -->|definition + options + materialized match| G[No change]
F -->|differs| H[viewDiff created]
H --> I{generateModifyViewsSQL}
I -->|optionsEqual + definitionsEqual| J[commentOnly / indexOnly / triggerOnly path]
I -->|options or definition changed| K[generateViewSQL]
K --> L{view.Materialized?}
L -->|yes| M[CREATE MATERIALIZED VIEW IF NOT EXISTS viewname WITH options AS ...]
L -->|no| N[CREATE OR REPLACE VIEW viewname WITH options AS ...]
Last reviewed commit: f11efce |
There was a problem hiding this comment.
Pull request overview
Adds end-to-end support for PostgreSQL view reloptions so that options like security_invoker / security_barrier are preserved during inspection, included in generated CREATE VIEW DDL, and considered during diffing.
Changes:
- Extend view inspection query to return
pg_class.reloptionsand store it in IR (View.Options). - Render view options via
CREATE ... VIEW ... WITH (...) AS ...when options are present. - Include view options in view equality / modify-view logic so option-only changes are detected.
Reviewed changes
Copilot reviewed 10 out of 10 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
ir/queries/queries.sql |
Adds c.reloptions to the GetViewsForSchema query output. |
ir/queries/queries.sql.go |
Plumbs reloptions into generated sqlc row struct + scan (pq.Array). |
ir/ir.go |
Adds View.Options to IR to represent view reloptions. |
ir/inspector.go |
Populates View.Options from inspected reloptions. |
internal/diff/view.go |
Compares options during diffs and renders WITH (...) in generated view DDL. |
testdata/diff/create_view/add_view/* |
Updates fixture SQL/plan outputs to include a security_invoker view. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Address review feedback: - Sort reloptions at ingestion (inspector) so comparison and DDL rendering are order-insensitive and deterministic - Deduplicate: viewsEqual now delegates to viewOptionsEqual Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 10 out of 10 changed files in this pull request and generated 1 comment.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Summary
pg_class.reloptionsfor views during schema inspectionWITH (...)clause in generatedCREATE VIEWDDL when options are presentsecurity_invoker,security_barrier, and any other view reloptionsFixes #343
Test plan
security_invokerview to existingcreate_view/add_viewtest casePGSCHEMA_TEST_FILTER="create_view/" go test -v ./internal/diff -run TestDiffFromFilesPGSCHEMA_TEST_FILTER="create_view/" go test -v ./cmd -run TestPlanAndApply🤖 Generated with Claude Code