Skip to content

Restore sql/test_factory--0.5.0.sql to its true historical content - #41

Closed
jnasbyupgrade wants to merge 5 commits into
Postgres-Extensions:issue-14-cleanfrom
jnasbyupgrade:fix/restore-0.5.0-mess
Closed

Restore sql/test_factory--0.5.0.sql to its true historical content#41
jnasbyupgrade wants to merge 5 commits into
Postgres-Extensions:issue-14-cleanfrom
jnasbyupgrade:fix/restore-0.5.0-mess

Conversation

@jnasbyupgrade

Copy link
Copy Markdown
Collaborator

Summary

Stacked on #18 (issue-14-clean, pushed to this repo for that purpose) rather than a fork-to-fork PR.

Test plan

@coderabbitai

coderabbitai Bot commented Aug 11, 2026

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 323ac63d-d92b-4635-a41b-12081d1285d4

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@github-actions

Copy link
Copy Markdown

Code review

No issues found. Checked for bugs and CLAUDE.md compliance.

jnasbyupgrade and others added 2 commits August 11, 2026 17:21
test_factory 0.5.0 has been the released, real-world-installed version
since 2017 (confirmed: no tag for it in this repo, but the "Bump version to
0.5.0" commit is nine years old, and issue Postgres-Extensions#14 itself describes a live
production failure against it). Every edit to sql/test_factory.sql on
fix/issue-14-clean got silently baked into this file too, via pgxntool's
own auto-regeneration (it copies the base file to sql/{ext}--{version}.sql
whenever default_version matches) -- retroactively rewriting what "version
0.5.0" contains without ever bumping the version number, which is exactly
the anti-pattern pgxntool's own docs warn a released version's file should
never be subject to.

Restored to match upstream/master (verified byte-for-byte identical),
i.e. what 0.5.0 has always actually contained. The issue Postgres-Extensions#14 fix itself
stays intact in the base sql/test_factory.sql file, ready for whichever
new version number eventually ships it -- that decision is deliberately
not made here.

release_status in META.in.json/META.json is already "stable" in both
files; no change needed there.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
The real problem wasn't just that sql/test_factory--0.5.0.sql had drifted
-- it's that test_factory.control's default_version was pinned at '0.5.0'
(a real, already-released version) the whole time. Per ../ai/RELEASE.md's
`stable` pseudo-version convention: between releases, default_version
should sit at the literal string 'stable', so ordinary source edits
regenerate sql/<ext>--stable.sql (a disposable scratch file) and never
touch a frozen, already-shipped version's file. Left at a real version
number, every edit to sql/test_factory.sql kept silently corrupting
sql/test_factory--0.5.0.sql -- exactly what happened all session, and
what would happen again on the next source edit if left as-is.

Set default_version = 'stable' in both test_factory.control and
test_factory_pgtap.control (test_factory_pgtap.control's own
`superuser = false` addition has the identical problem, one version
number earlier). Regenerated sql/test_factory--stable.sql and
sql/test_factory_pgtap--stable.sql from the current source (confirmed
sql/test_factory--0.5.0.sql and sql/test_factory_pgtap--0.1.0.sql are
untouched by this regeneration). Added
sql/test_factory--0.5.0--stable.sql, the update script from the last
real release to `stable`, containing the same GRANT-if-missing logic as
the fresh-install fix -- required for `ALTER EXTENSION test_factory
UPDATE` to have anywhere to go at all.

test/install/load.sql's update-mode branch needed a real restructuring,
not just a version bump: CREATE EXTENSION test_factory VERSION '0.5.0'
(the FROM version, genuinely unfixed) cannot succeed as a non-superuser
-- that's the original bug, unrelated to versioning -- and extension
ownership can't be transferred (`ALTER EXTENSION ... OWNER TO` isn't
valid syntax, confirmed), so only the role that ran the original install
can ever run ALTER EXTENSION UPDATE on it. There's no reachable
"different non-superuser applies this later" scenario to test. Update
mode now runs entirely as the ambient role; only fresh mode switches to
test_factory_installer (which already fully covers the non-superuser
install path) -- moved the issue Postgres-Extensions#14 regression check into the fresh
branch specifically, since it was checking the wrong thing under update
mode's ambient (typically superuser) role.

Verified locally on PG12 and PG17: fresh and update modes both pass, and
default_version = 'stable' means `make` no longer touches
sql/test_factory--0.5.0.sql or sql/test_factory_pgtap--0.1.0.sql on any
future source edit.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
@jnasbyupgrade
jnasbyupgrade force-pushed the fix/restore-0.5.0-mess branch from c0ea0e8 to 3f3fa4a Compare August 11, 2026 22:22
jnasbyupgrade and others added 3 commits August 11, 2026 17:30
assert_version() compared installed extversion against `make -s
print-PGXNVERSION`, which pulls META.json's *distribution* version
(still the real semver, e.g. 0.5.0) -- unaffected by
test_factory.control's default_version, which this PR pins to the
literal 'stable' pseudo-version between releases. A bare CREATE
EXTENSION now installs at 'stable', so the two were guaranteed to
mismatch: confirmed via the pg-upgrade-test CI job failing with "test_factory
in '...' is 'stable', expected '0.5.0'".

Switched to `make -s print-EXTENSION_test_factory_VERSION` (from
pgxntool's generated control.mk, tracks default_version directly),
verified locally end-to-end: a fresh CREATE EXTENSION installs at
'stable', and bin/test_existing run-suite's own version check now
reports installed='stable' expected='stable' and passes.

Also picked up the ERRCODE fix in sql/test_factory--stable.sql
(regenerated after rebasing onto the latest fix/issue-14-clean).

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
sql/test_factory--stable.sql and sql/test_factory_pgtap--stable.sql are
permanently current, not a frozen release -- per ../ai/CLAUDE.md's
"Version-specific SQL files" section (referenced directly from
../ai/RELEASE.md), they'd be regenerated and re-diffed on every single
source edit for zero test-coverage value if tracked. Removed from git,
added sql/*--stable.sql to .gitignore. sql/test_factory--0.5.0--stable.sql
(the real update script) is unaffected and stays tracked -- confirmed via
git check-ignore.

Verified: rm'd both files, ran `make clean && make test` (fresh and
update modes) from that state -- both regenerate automatically and the
full suite still passes.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
…ong context

Opened with "CREATE ROLE never granted..." -- language carried over from
sql/test_factory.sql's own comment, where a CREATE ROLE statement exists
right above it. This file has no CREATE ROLE at all (test_factory__owner
already exists on any real 0.5.0 install), so that framing described an
event that never happens here, confusing about why role creation was even
being discussed. Rewrote it to stand on its own: the actual issue Postgres-Extensions#14 bug
(never getting SET/plain membership automatically) applies to an existing
install just as much as a fresh one, which is why this update script
exists at all.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Comment thread .gitignore
# and re-diffed on every source edit for zero test-coverage value if
# tracked. The update script *to* stable (sql/*--<last-release>--stable.sql)
# is not affected by this and must stay committed.
sql/*--stable.sql

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: this pattern also matches the update scripts the comment above it says are exempt.

The added comment states:

The update script to stable (sql/*--<last-release>--stable.sql) is not affected by this and must stay committed.

But in gitignore glob syntax * matches any run of characters except /, so sql/*--stable.sql also matches sql/test_factory--0.5.0--stable.sql (with * = test_factory--0.5.0) — the very file this PR adds. It's harmless right now only because that file is already tracked (git doesn't apply .gitignore to tracked paths), but the next release's analogous update script (e.g. sql/test_factory--0.6.0--stable.sql, or a future test_factory_pgtap one) would be silently skipped by git add, shipping a distribution with no upgrade path and no error anywhere.

A negation line after it fixes this — sql/*--*--stable.sql requires two separate ---delimited segments before stable.sql, so it matches only <ext>--<version>--stable.sql update scripts, not the single-segment <ext>--stable.sql files this rule is meant to ignore:

Suggested change
sql/*--stable.sql
sql/*--stable.sql
!sql/*--*--stable.sql

@@ -1,5 +1,5 @@
comment = 'A framework for managing test data'
default_version = '0.1.0'
default_version = 'stable'

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: default_version moves to 'stable' here, mirroring test_factory.control, but unlike test_factory.control (which gets sql/test_factory--0.5.0--stable.sql in this same PR), there's no corresponding sql/test_factory_pgtap--0.1.0--stable.sql anywhere in this diff.

PostgreSQL's ALTER EXTENSION ... UPDATE requires a literal sql/<extension>--<from>--<to>.sql script to move between two specific versions — there's no fuzzy/partial matching. Any existing test_factory_pgtap 0.1.0 install (the version that has shipped since this extension's only release) would fail ALTER EXTENSION test_factory_pgtap UPDATE with "no update path from version "0.1.0" to version "stable"".

This isn't caught by the test suite: test/install/load.sql's update-mode branch installs test_factory_pgtap fresh (at stable directly) rather than updating it from 0.1.0, so the missing path is never exercised.

Fix: add a sql/test_factory_pgtap--0.1.0--stable.sql script (can be a no-op, since no pgtap-side objects changed) mirroring what this PR already did for test_factory.

@jnasbyupgrade

Copy link
Copy Markdown
Collaborator Author

Superseded: the versioning-hygiene fix moved to #42 (merged, standalone against master). The remaining genuinely-needed content (the real GRANT-fix update script, and the load.sql update-mode role restructuring) has been folded directly into #18.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant