Fix uninstall_extension dropping prefix-named sibling extensions#314
Open
jnasbyupgrade wants to merge 1 commit into
Open
Fix uninstall_extension dropping prefix-named sibling extensions#314jnasbyupgrade wants to merge 1 commit into
jnasbyupgrade wants to merge 1 commit into
Conversation
a435f9e to
8a1df95
Compare
uninstall_extension() matched the functions to drop with LIKE patterns of
the forms <extname>%.control and <extname>%.sql. Because the % immediately
follows the name, the patterns also matched any other extension whose name
has <extname> as a prefix, so uninstalling 'foo' silently dropped the
registration of 'foo_bar'. Names may also contain '_' (a LIKE wildcard),
and uninstall_extension('') matched every extension's control function.
Match the control function by exact name and the script functions with an
anchored, metacharacter-escaped regular expression, delivered as a new
1.5.2 -> 1.5.3 upgrade script that replaces both uninstall_extension
overloads.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
8a1df95 to
0082d99
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
pgtle.uninstall_extension()located which extension registration functions todrop using
LIKEpatterns of the forms<extname>%.controland<extname>%.sql. Because the%immediately follows the extension name, thepatterns also matched the artifacts of any other extension whose name has
<extname>as a prefix. Uninstallingfootherefore silently dropped theregistration of
foo_baras well — no error, no warning. An extension name mayalso legally contain
_, which is itself aLIKEwildcard, widening theover-match further (e.g.
foo_baralso matchedfooXbar). The empty-stringcase is the degenerate extreme:
uninstall_extension('')matched%.controland attempted to drop every registered extension's control function.
Fix:
<extname>.control, so match it byequality instead of a pattern.
<extname>--<version>.sqland<extname>--<from>--<to>.sql. Since neither an extension name nor a versionmay contain
--, that separator is a reliable boundary. Match them with ananchored regular expression (
^<ext>--...\.sql$), regex-escaping the nameand version so any metacharacters they contain are treated literally.
Switching the script match from
LIKEto a regex also lets the two-arguninstall_extension(name, version)express "the version is one of the---delimited tokens" precisely. This matches the documented behavior("removes all update paths that use this extension version") and removes a
latent over-match where, e.g., version
1.1also matched a1.10updatescript via
LIKE '%1.1%'.The fix is delivered as a new
1.5.2 -> 1.5.3upgrade script that replacesboth
uninstall_extensionoverloads, so existing installs pick it up viaALTER EXTENSION pg_tle UPDATE.Behavior change:
uninstall_extension('')anduninstall_extension('', '')now report that the (empty-named) extension does not exist, and
uninstall_extension_if_exists('')returns false, instead of attempting todrop an unrelated extension's functions. The
pg_tle_functions_aclexpectedoutput is updated accordingly.
Testing: added a focused block to
pg_tle_managementcovering a prefix target(with an update path), a longer-named sibling, an underscore decoy, and the
two-arg control-drop path; all survive/are removed as expected. Verified the
1.5.2 -> 1.5.3upgrade path activates the fix on existing installs.By submitting this pull request, I confirm that my contribution is made under
the terms of the Apache 2.0 license.
🤖 Generated with Claude Code