Fire the event trigger for DROP SCHEMA and DROP OWNED - #55
jnasbyupgrade wants to merge 3 commits into
Conversation
`DROP SCHEMA ... CASCADE` and `DROP OWNED BY` can drop an extension, but the trigger only fired for `DROP EXTENSION`. The registered SQL never ran and the leftover row in `extension_drop__commands` made every later `DROP EXTENSION` raise `XD001`. The trigger's `WHEN tag` list now includes both tags. The update script recreates the trigger, since `ALTER EVENT TRIGGER` cannot change `WHEN`. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
|
Important Review skippedAuto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Organization UI Review profile: ASSERTIVE Plan: Advanced Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
Claude finished @jnasbyupgrade's task in 30s —— View job Review of PR #55: fire the event trigger for DROP SCHEMA and DROP OWNEDI read the diff and the trigger and sanity-check code. I did not build the extension or run the test suite. The The change is small and consistent. The trigger Concern: the trigger now fires for ordinary users (not verified by running it)
Event triggers run with the privileges of the user who issued the command. So a non-superuser running There is a second, related effect. Any stale row in Suggestions:
Minor
|
Now that the trigger fires for every `DROP SCHEMA` and `DROP OWNED`, it must not read `extension_drop__commands` or run the sanity assert for drops that involve no extension: a non-superuser's ordinary drops failed with a permission error, and a stale row broke unrelated drops. The row variable is a `record` so the function compiles without access to the extension's schema. Adds tests for non-superuser and stale-row drops, and factors the shared post-drop assertions into a helper. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
|
Claude here. Addressing the review's non-superuser concern (confirmed by running it: a plain role's |
|
Claude finished @jnasbyupgrade's task in 21s —— View job Review of PR #55: fire the event trigger for DROP SCHEMA and DROP OWNEDI read the diff, including the trigger SQL, the update script and I found no bugs. The earlier review's two concerns are both handled in the current head:
The fresh-install and 0.1.1→stable paths are consistent:
Minor notes (no action required)
|
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
|
Claude here. Decisions needed from the maintainer:
|
|
Claude finished @jnasbyupgrade's task in 16s —— View job Review of PR #55: fire the event trigger for DROP SCHEMA and DROP OWNEDI read the full diff: the install and update SQL, README/HISTORY, and the three new tests plus the helper. I did not build the extension or run the tests. The I found no bugs.
Minor notes (no action required)
|
extension_drop's event trigger now fires forDROP SCHEMAandDROP OWNEDas well asDROP EXTENSION, so an extension dropped byDROP SCHEMA ... CASCADEorDROP OWNED BYruns its registered SQL and has its registration removed instead of leaving a stale row inextension_drop__commands(which makes every laterDROP EXTENSIONraiseXD001).These three are the only commands that can drop an extension. An extension has ordinary
pg_dependrows only on its schema and on any extension it requires, so it goes away viaDROP EXTENSION(including cascading to dependents),DROP SCHEMA ... CASCADE, orDROP OWNED, which walks the owner dependencies inshdepend. This doesn't depend on the PostgreSQL version. Corroboration on PG12 and PG17 with an unfilteredsql_droptrigger: only those three tags dropped an extension, andDROP ROLE,DROP TYPE/DROP FUNCTION ... CASCADEon a member, andDROP SCHEMAwithoutCASCADEall error out, whileREASSIGN OWNEDdrops nothing.Since the trigger now runs for every
DROP SCHEMAandDROP OWNED,extension_drop__event_trigger()returns immediately unless an extension is among the dropped objects. Unrelated drops therefore don't readextension_drop__commandsor run the sanity assert, so they work for non-superusers and are unaffected by a stale row. The row variable is arecordso the function compiles for a caller without access to the extension's schema.Behavior change: a plain role that drops a registered extension with
DROP SCHEMA ... CASCADEnow fails withpermission denied for table extension_drop__commands, asDROP EXTENSIONby such a role already does.ALTER EVENT TRIGGERcan't changeWHEN, soextension_drop--0.1.1--stable.sqldrops and recreates the trigger and replaces the function. Function properties (proacl,proconfig, source hash) andpg_event_trigger.evttagsare identical after a fresh install and after updating from 0.1.1, on PG12 and PG17.Tests:
drop_schema_cascadeanddrop_ownedfail without the widerWHENlist.unrelated_dropsguards the widening: it fails if the trigger fires for these commands without the early return.🤖 Generated with Claude Code