feat: warn about and skip statements that have no effect on the plan (#602, #603) - #621
Conversation
ALTER DEFAULT PRIVILEGES without IN SCHEMA is database-level state that the schema-scoped inspection never sees, so it yields an empty plan. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
…602, #603) Object OWNER TO and ALTER DEFAULT PRIVILEGES without IN SCHEMA set state that inspection never reads, so they produced a successful empty plan, indistinguishable from convergence. plan now reports each one on stderr and drops it before role validation and the plan database, where a global default ACL would otherwise persist on an external plan database and an unstubbed owner role would fail. Detection is a best-effort textual scan built on the existing comment/literal/dollar-quote skipping scanner. Removal blanks the statement in place so PostgreSQL error positions still map to the file. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
|
There was a problem hiding this comment.
Copilot review overview
🟡 Changes recommended
The scanner can alter valid E-string contents and misclassify or miss valid ownership statements.
Get a fresh assessment by requesting another Copilot review.
Review effort: Balanced
Findings: 1
Open (4)
What changed in this PR
Adds warnings and filtering for unsupported ownership changes and global default privileges.
Changes:
- Detects and removes no-effect SQL while preserving source offsets.
- Integrates warnings into plan/apply generation.
- Adds tests and unsupported-syntax documentation.
| File | Description |
|---|---|
internal/postgres/no_effect.go |
Implements detection and stripping. |
internal/postgres/no_effect_test.go |
Adds detector tests. |
internal/postgres/fk_refs.go |
Exposes code-span offsets. |
cmd/plan/plan.go |
Applies stripping during planning. |
cmd/plan/no_effect.go |
Formats warnings. |
cmd/plan/no_effect_integration_test.go |
Tests planning behavior. |
docs/syntax/unsupported.mdx |
Documents unsupported statements. |
docs/syntax/alter_default_privileges.mdx |
Documents IN SCHEMA requirement. |
💡 Configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
- Drop only the OWNER TO action when it shares an ALTER TABLE with other actions, so it no longer reaches the plan database; warn about the action rather than the whole statement. - Report ALTER INDEX ... OWNER TO. - Require the second keyword for two-word kinds, so ALTER FOREIGN DATA WRAPPER ... OWNER TO is left alone. - Treat backslash-escaped quotes in E'...' literals as part of the literal, so text inside one is never blanked. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>



Summary
Two statement kinds set state that pgschema's inspection never reads, so a schema file containing them produced a successful empty plan with no diagnostic:
ALTER <object> ... OWNER TO— ownership follows thepg_dump --no-ownermodel (Support object OWNER changes or diagnose ignored ownership intent #602)ALTER DEFAULT PRIVILEGESwithoutIN SCHEMA— a database-wide default ACL, not schema-level state (Diagnose unsupported global ALTER DEFAULT PRIVILEGES instead of returning an empty plan #603)plan(andapply, which goes throughGeneratePlan) now prints a warning per statement on stderr and drops it from the desired-state SQL:Why drop, not just warn
ALTER DEFAULT PRIVILEGESruns for real on the plan database. On an external plan database nothing cleans it up, so it would persist past the run.OWNER TOis not stubbed, so the statement fails in the plan database withrole "x" does not exist.Stripping happens right after include processing, before role validation and before the plan database.
How
postgres.StripNoEffectStatements, returns the findings plus the SQL without them. Adding another kind is one more case inclassifyNoEffect.walkSQLCode*,parseQuotedIdent, …);walkSQLCodeSpansis a small refactor that exposes byte offsets. String literals, comments and dollar-quoted bodies are skipped, so statements insideDOblocks or function bodies are not seen.OWNER TOcombined with other actions in oneALTER TABLEis warned about but kept.RENAME [COLUMN|CONSTRAINT|ATTRIBUTE] owner TO ...and objects namedownerare not misread.ALTER SCHEMA/DATABASE ... OWNER TOis left alone.Docs
Test plan
go test ./internal/postgres/— newTestStripNoEffectStatementstable testgo test ./cmd/plan/— newTestPlan_WarnsAboutNoEffectStatements(embedded Postgres; confirmed it fails without the fix)go test ./internal/diff/PGSCHEMA_TEST_FILTER="default_privilege/" go test ./cmd -run TestPlanAndApplygo test ./...left to CICloses #602
Closes #603
🤖 Generated with Claude Code