-
Notifications
You must be signed in to change notification settings - Fork 1
Pick the test/install load mode server-side, and turn on ON_ERROR_STOP #63
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
jnasbyupgrade
merged 3 commits into
Postgres-Extensions:master
from
jnasbyupgrade:load-mode-without-if
Sep 3, 2026
+249
−158
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
97cd3e0
Pick the test/install load mode server-side, and turn on ON_ERROR_STOP
jnasbyupgrade bd1a7b1
Point create_extension_in_schema()'s comment at extension_installer.sql
jnasbyupgrade a068c29
Document the non-atomic check-then-create for the test role
jnasbyupgrade File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,71 +1,32 @@ | ||
| /* | ||
| * Creates a fresh, randomly named schema and installs count_nulls into it. | ||
| * Shared by test/install/load.sql (fresh/update modes, same psql session) | ||
| * and bin/test_existing's prepare-old (a separate invocation) - the | ||
| * creation logic is identical in both, so it lives here once. | ||
| */ | ||
| SET count_nulls.test_schema_version = :'version'; | ||
|
|
||
| /* | ||
| * Bridged through a GUC instead of referencing :'version' directly inside | ||
| * the DO block: psql doesn't interpolate variables inside dollar-quoted | ||
| * strings. | ||
| * Installs count_nulls at :version into a fresh, randomly named schema. | ||
| * Exists as a file only because bin/test_existing's prepare-old runs it | ||
| * standalone (psql -v version=<VERSION> -f); the work itself lives in | ||
| * test/helpers/extension_installer.sql. | ||
| * | ||
| * 'current' means install whatever the current default is, matching the | ||
| * sentinel bin/test_existing already uses; empty is a hard error so an | ||
| * unpropagated :version can't silently install 'current' instead. | ||
| * The install itself runs as a non-superuser (see | ||
| * test/helpers/use_test_user.sql), which is what proves count_nulls doesn't | ||
| * need superuser to install. Cleanup happens before that switch: a leftover | ||
| * schema can belong to any role, and only the connecting one is sure to be | ||
| * able to drop it. | ||
| */ | ||
| DO $$ | ||
| BEGIN | ||
| IF current_setting('count_nulls.test_schema_version') = '' THEN | ||
| RAISE EXCEPTION $msg$:version must be set explicitly, or 'current'$msg$; | ||
| END IF; | ||
| END | ||
| $$; | ||
| \i test/helpers/extension_installer.sql | ||
|
|
||
| /* | ||
| * A run that crashed before its own teardown leaves a schema nothing else | ||
| * knows the name of, so match the prefix (see the name generation below) | ||
| * and drop it here - before the test-user switch, since a leftover schema | ||
| * can belong to any role and only the connecting one is sure to be able to | ||
| * drop it. See find_test_schema.sql for how later sessions rediscover the | ||
| * name this creates. | ||
| * Always a fresh install here, never 'existing' - see the mode's no-op note | ||
| * on count_nulls_cleanup_test_schemas() itself. | ||
| */ | ||
| DO $$ | ||
| DECLARE | ||
| r record; | ||
| BEGIN | ||
| FOR r IN SELECT nspname FROM pg_namespace WHERE nspname LIKE 'count_nulls test schema %' LOOP | ||
| EXECUTE format('DROP SCHEMA %I CASCADE', r.nspname); | ||
| END LOOP; | ||
| END | ||
| $$; | ||
| SELECT pg_temp.count_nulls_cleanup_test_schemas('fresh'); | ||
|
|
||
| /* | ||
| * :count_nulls_load_mode must already be set by the caller (test/install/ | ||
| * load.sql, or bin/test_existing's -v on the command line) - this file | ||
| * installs count_nulls, so it can't know on its own whether that's | ||
| * genuinely a fresh/update run rather than 'existing'. | ||
| * :count_nulls_load_mode must already be set by the caller | ||
| * (bin/test_existing's -v on the command line - see the file header) - | ||
| * this file only installs, so it can't know on its own whether that's | ||
| * genuinely a fresh run rather than 'existing'. | ||
| */ | ||
| \i test/helpers/use_test_user.sql | ||
|
|
||
| /* | ||
| * Trailing space alone forces identifier quoting, so every run exercises | ||
| * %I-qualification rather than passing by luck of the random suffix. Must | ||
| * match the prefix cleanup matches on above. | ||
| */ | ||
| SELECT 'count_nulls test schema ' || substr(md5(random()::text), 1, 12) AS schema | ||
| \gset | ||
|
|
||
| CREATE SCHEMA :"schema"; | ||
|
|
||
| SELECT CASE WHEN :'version' = 'current' THEN '' ELSE format(' VERSION %L', :'version') END AS version_clause | ||
| SELECT pg_temp.count_nulls_install_extension(:'version') AS count_nulls_test_schema | ||
| \gset | ||
|
|
||
| /* | ||
| * WITH SCHEMA rather than arranging search_path first: this way a | ||
| * successful install proves the install script doesn't depend on | ||
| * unqualified name resolution, instead of hiding it behind a search_path | ||
| * that happened to suit. | ||
| */ | ||
| CREATE EXTENSION count_nulls WITH SCHEMA :"schema":version_clause; | ||
| -- vi: expandtab sw=2 ts=2 |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,78 @@ | ||
| /* | ||
| * Defines, but does not call, the functions that find-and-drop leftover test | ||
| * schemas and install count_nulls into a fresh one. Split from calling them, | ||
| * and from each other, so test/install/load.sql can decide server-side | ||
| * whether to install at all, and so every caller can run cleanup before | ||
| * switching to the test user (test/helpers/use_test_user.sql) while | ||
| * installing after - a leftover schema can belong to any role, and only the | ||
| * connecting one is sure to be able to drop it. | ||
| */ | ||
| CREATE OR REPLACE FUNCTION pg_temp.count_nulls_cleanup_test_schemas( | ||
| p_mode text | ||
| ) RETURNS void LANGUAGE plpgsql AS $body$ | ||
| DECLARE | ||
| r record; | ||
| BEGIN | ||
| /* | ||
| * 'existing' asserts against a schema a prior, separate prepare-old run | ||
| * left behind on purpose - dropping it here would destroy the very thing | ||
| * pg_upgrade is being tested against, so this mode must be a no-op. | ||
| */ | ||
| IF p_mode = 'existing' THEN | ||
| RETURN; | ||
| END IF; | ||
|
|
||
| /* | ||
| * A run that died before its own teardown leaves a schema nothing else | ||
| * knows the name of, so match the prefix (see | ||
| * count_nulls_install_extension()'s c_prefix below) and drop whatever's | ||
| * there. | ||
| */ | ||
| FOR r IN SELECT nspname FROM pg_namespace WHERE nspname LIKE 'count_nulls test schema %' LOOP | ||
| EXECUTE format('DROP SCHEMA %I CASCADE', r.nspname); | ||
| END LOOP; | ||
| END | ||
| $body$; | ||
|
|
||
| CREATE OR REPLACE FUNCTION pg_temp.count_nulls_install_extension( | ||
| p_version text | ||
| ) RETURNS name LANGUAGE plpgsql AS $body$ | ||
| DECLARE | ||
| /* | ||
| * The trailing space alone forces SQL identifier quoting, so every run | ||
| * exercises the suite's %I-qualification rather than passing by luck of | ||
| * which characters the random suffix drew. Must match the literal | ||
| * count_nulls_cleanup_test_schemas() matches on above. | ||
| */ | ||
| c_prefix CONSTANT text := 'count_nulls test schema '; | ||
| v_schema name; | ||
| BEGIN | ||
| /* | ||
| * 'current' means whatever the control file's default_version is, matching | ||
| * the sentinel bin/test_existing already uses. Empty is a hard error, so an | ||
| * unpropagated :version can't silently install 'current' instead. | ||
| */ | ||
| IF p_version = '' THEN | ||
| RAISE EXCEPTION $$p_version must be set explicitly, or 'current'$$; | ||
| END IF; | ||
|
|
||
| v_schema := c_prefix || substr(md5(random()::text), 1, 12); | ||
| EXECUTE format('CREATE SCHEMA %I', v_schema); | ||
|
|
||
| /* | ||
| * WITH SCHEMA rather than arranging search_path first: this way a | ||
| * successful install proves the install script doesn't depend on | ||
| * unqualified name resolution, instead of hiding it behind a search_path | ||
| * that happened to suit. | ||
| */ | ||
| EXECUTE format( | ||
| 'CREATE EXTENSION count_nulls WITH SCHEMA %I%s' | ||
| , v_schema | ||
| , CASE WHEN p_version = 'current' THEN '' ELSE format(' VERSION %L', p_version) END | ||
| ); | ||
|
|
||
| RETURN v_schema; | ||
| END | ||
| $body$; | ||
|
|
||
| -- vi: expandtab sw=2 ts=2 |
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
Oops, something went wrong.
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Stale pointer, in a comment this PR's own commit (
06bce4e) just edited: "shared with test/install/load.sql's own fresh/update installs via test/helpers/create_test_schema.sql (see that file for the full rationale)" is no longer true.test/install/load.sqldoesn't touchcreate_test_schema.sqlat all anymore — it\i'stest/helpers/extension_installer.sqldirectly (test/install/load.sql:26), and that's also where the shared cleanup/install logic and its rationale actually live now.create_test_schema.sql's own header already reflects this correctly: "the work itself lives intest/helpers/extension_installer.sql."This sentence predates this PR (it was flagged as stale in an earlier review round, when this file wasn't part of the diff yet), but
06bce4eadded two new sentences immediately after it in this same comment block without correcting the one that was already wrong — so it's now shipping inaccurate documentation as part of this PR's own change, not just inheriting it unmodified.Fix stale create_test_schema.sql pointer in bin/test_existing →
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Claude here — confirmed stale:
test/install/load.sql\i'stest/helpers/extension_installer.sqldirectly and doesn't referencecreate_test_schema.sqlanywhere. The comment now points attest/helpers/extension_installer.sqlas the shared install logic (and the rationale), and describescreate_test_schema.sqlas the thin wrapper that calls it, kept as a file only so this script can invoke it standalone; the twocount_nulls_load_modesentences are unchanged, since they were correct. Fixed in bd1a7b1.