Skip to content

cat_tools 0.2.3: fix pg_class.relkind mapping and the pg_upgrade update path#42

Merged
jnasbyupgrade merged 2 commits into
Postgres-Extensions:masterfrom
jnasbyupgrade:reroll-023-fix
Jul 20, 2026
Merged

cat_tools 0.2.3: fix pg_class.relkind mapping and the pg_upgrade update path#42
jnasbyupgrade merged 2 commits into
Postgres-Extensions:masterfrom
jnasbyupgrade:reroll-023-fix

Conversation

@jnasbyupgrade

@jnasbyupgrade jnasbyupgrade commented Jul 18, 2026

Copy link
Copy Markdown
Contributor

Release cat_tools 0.2.3.

Correct the backwards pg_class.relkind mapping in relation__kind() and relation__relkind(). Per pg_class.h, 'c' is a composite type, 'f' a foreign table, and 'm' a materialized view; releases through 0.2.2 had these three reversed.

Fix binary pg_upgrade failing for databases that reached 0.2.2 via the 0.2.0->0.2.2 or 0.2.1->0.2.2 update scripts. Those scripts filtered omitted columns with != ANY instead of != ALL; on a multi-element list != ANY strips nothing, so catalog columns removed in newer PostgreSQL (relhasoids, relhaspkey) remained in _cat_tools.pg_class_v and made pg_upgrade to PG12+ fail. Rather than re-issue the already-published 0.2.0->0.2.2 and 0.2.1->0.2.2 scripts, the 0.2.2->0.2.3 update repairs such a database at runtime: it detects the broken build (a relhasoids column still present on _cat_tools.pg_class_v) and only then drops and recreates the public view chain (cat_tools.pg_class_v, cat_tools.column, cat_tools.pg_class()) with the corrected column list. A fresh 0.2.2 install already has correct views, so the rebuild is skipped entirely and its views -- and any objects depending on them -- are left untouched. Because the repair is DROP+CREATE without CASCADE, a database that IS repaired must have any user objects depending on those public views dropped first and recreated afterward, or the update aborts.

Consequently, to binary-pg_upgrade a cluster whose cat_tools reached 0.2.2 via those update paths to PostgreSQL 12+, first ALTER EXTENSION cat_tools UPDATE to 0.2.3 (or newer); this is documented in README.asc and HISTORY.asc.

Track the generated sql/cat_tools--0.2.3.sql.in install script -- the nontrivial 0.2.2->0.2.3 update warrants committing it for update-test coverage and provenance -- and update CLAUDE.md's SQL-file-tracking rule accordingly. Also adds a RELEASE.md and a test/build/upgrade.sql regression guard proving a fresh 0.2.2 install's dependent objects survive the update to 0.2.3.

Verified on PostgreSQL 12 and 17 via the new test/build/upgrade.sql (a fresh 0.2.2 install with dependent views updates to 0.2.3 with those views left in place), and by master's extension-update-test (PG10), which installs 0.2.0, updates to current (0.2.0->0.2.2->0.2.3, exercising the conditional repair on a genuinely broken build), plus the explicit 0.2.1->0.2.2 leg.

`relation__kind()` (relkind -> type) and `relation__relkind()` (type ->
relkind), as shipped through **0.2.2**, map the `pg_class.relkind` codes
`c`, `f`, and `m` **backwards**. Release a patch that fixes that.
@coderabbitai

coderabbitai Bot commented Jul 18, 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: bb7de046-b788-4872-9aaa-424cd06d478b

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
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

@jnasbyupgrade jnasbyupgrade changed the title Fix pg_upgrade update-path bug (omit_column != ANY -> != ALL; rebuild pg_class_v) cat_tools 0.2.3: fix pg_class.relkind mapping and the pg_upgrade update path Jul 19, 2026
@jnasbyupgrade
jnasbyupgrade force-pushed the reroll-023-fix branch 7 times, most recently from ae6c1e0 to 9f23c59 Compare July 20, 2026 19:46
jnasbyupgrade added a commit to jnasbyupgrade/cat_tools that referenced this pull request Jul 20, 2026
The extension-update-test PG10 leg already exercises the pre-0.2.2 update
scripts (0.2.0/0.2.1 -> 0.2.2). Add a third update-check that installs 0.2.0 on
PG10 (relhasoids present in _cat_tools.pg_class_v via the buggy 0.2.0--0.2.2
omit_column no-op) and updates to 0.2.3, which routes through 0.2.2--0.2.3 and
must fire the conditional rebuild that strips relhasoids. A psql assertion fails
loudly if relhasoids is still present after reaching 0.2.3, explicitly verifying
the rebuild on the real broken path. 0.2.3 is the furthest PG10 can reach
(0.2.3--0.3.0 needs PG12+). Complements the stronger 10->18 pg_upgrade bridge
leg and mirrors the relhasoids assertion going into the Postgres-Extensions#42 replication.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
jnasbyupgrade added a commit to jnasbyupgrade/cat_tools that referenced this pull request Jul 20, 2026
Match the concise 0.2.3 entry going into the Postgres-Extensions#42 replication for consistency
(most HISTORY entries are at most a paragraph). The detailed scoping of the
conditional view rebuild remains in the README caveat.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Correct the backwards pg_class.relkind mapping in relation__kind() and relation__relkind(). Per pg_class.h, 'c' is a composite type, 'f' a foreign table, and 'm' a materialized view; releases through 0.2.2 had these three reversed.

Fix binary pg_upgrade failing for databases that reached 0.2.2 via the 0.2.0->0.2.2 or 0.2.1->0.2.2 update scripts. Those scripts filtered omitted columns with `!= ANY` instead of `!= ALL`; on a multi-element list `!= ANY` strips nothing, so catalog columns removed in newer PostgreSQL (relhasoids, relhaspkey) remained in _cat_tools.pg_class_v and made pg_upgrade to PG12+ fail. Rather than re-issue the already-published 0.2.0->0.2.2 and 0.2.1->0.2.2 scripts, the 0.2.2->0.2.3 update repairs such a database at runtime: it detects the broken build (a relhasoids column still present on _cat_tools.pg_class_v) and only then drops and recreates the public view chain (cat_tools.pg_class_v, cat_tools.column, cat_tools.pg_class()) with the corrected column list. A fresh 0.2.2 install already has correct views, so the rebuild is skipped entirely and its views -- and any objects depending on them -- are left untouched. Because the repair is DROP+CREATE without CASCADE, a database that IS repaired must have any user objects depending on those public views dropped first and recreated afterward, or the update aborts.

Consequently, to binary-pg_upgrade a cluster whose cat_tools reached 0.2.2 via those update paths to PostgreSQL 12+, first ALTER EXTENSION cat_tools UPDATE to 0.2.3 (or newer); this is documented in README.asc and HISTORY.asc.

Track the generated sql/cat_tools--0.2.3.sql.in install script -- the nontrivial 0.2.2->0.2.3 update warrants committing it for update-test coverage and provenance -- and update CLAUDE.md's SQL-file-tracking rule accordingly. Also adds a RELEASE.md and a test/build/upgrade.sql regression guard proving a fresh 0.2.2 install's dependent objects survive the update to 0.2.3.

Verified on PostgreSQL 12 and 17 via the new test/build/upgrade.sql (a fresh 0.2.2 install with dependent views updates to 0.2.3 with those views left in place), and by master's extension-update-test (PG10), which installs 0.2.0, updates to current (0.2.0->0.2.2->0.2.3, exercising the conditional repair on a genuinely broken build), plus the explicit 0.2.1->0.2.2 leg.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
jnasbyupgrade added a commit to jnasbyupgrade/cat_tools that referenced this pull request Jul 20, 2026
…stgres-Extensions#42)

new_functions' HISTORY 0.2.3 entry references a README "Updating the extension"
section that did not exist here; the README instead carried an ad-hoc [NOTE] in
the Views section. Add the formal section VERBATIM from the Postgres-Extensions#42 reroll branch
(byte-identical, same placement after "=== Supported Versions") so the HISTORY
reference resolves and the two branches' READMEs match ahead of the Postgres-Extensions#16->master
merge. Remove the now-redundant Views [NOTE]: its content (rebuild scope +
drop-dependents-first caveat scoped to 0.2.0/0.2.1, fresh install unaffected) is
fully covered by the new section, which additionally documents the pg_upgrade
ordering.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
jnasbyupgrade added a commit to jnasbyupgrade/cat_tools that referenced this pull request Jul 20, 2026
…cktick identifiers)

Replace the plain-text 0.2.3 entry with Postgres-Extensions#42's exact version, which backticks
identifiers (`pg_class.relkind`, `relation__kind()`, `relhasoids`, `pg_class_v`,
...) per HISTORY.asc house style. The 0.2.3 block is now byte-identical between
new_functions and the Postgres-Extensions#42 reroll branch. 0.3.0 entry untouched.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@jnasbyupgrade
jnasbyupgrade merged commit 2146123 into Postgres-Extensions:master Jul 20, 2026
18 of 20 checks passed
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