Skip to content

Schema change: tested on PostgreSQL 12 to 18, and a row count fix for 12 and 13 - #4

Merged
swsarancodes merged 1 commit into
mainfrom
fix/schema-change-versions
Oct 24, 2026
Merged

swsarancodes merged 1 commit into
mainfrom
fix/schema-change-versions

Conversation

@swsarancodes

Copy link
Copy Markdown
Owner

What changed

The schema change compiler says it is written for PostgreSQL 12 or newer, but had only been tested on 16. This runs the real-PostgreSQL checks (scripts/schema-change-pg16.ts, 14 sections) against 12, 13, 14, 15, 16, 17 and 18 and fixes what that showed.

One product bug. Before PostgreSQL 14, pg_class.reltuples is 0, not -1, for a table nobody has analyzed, so it read as an empty table. On 12 and 13 a large never-analyzed table was reported as 0 rows and the health report's "never analyzed" finding did not appear. On those versions, 0 on a table whose file is not empty is now treated as unknown (row-estimate.ts, used by catalog.ts, facts.ts and health.ts). Behaviour on 14 and later is unchanged.

Everything else that failed was the test script assuming PostgreSQL 16 (SQL-body functions need 14, DROP DATABASE ... WITH (FORCE) needs 13, gen_random_uuid() is built in from 13, PostgreSQL 18 stores NOT NULL as a constraint of its own, the statistics views lag before 15). The script was made version-aware; those changes are in the local script, not in this diff.

How it was checked

  • All 14 sections pass on 12, 13, 14, 15, 16, 17 and 18 (real servers, one container per version).
  • New unit test for the helper; the repo suite passes (1,721 tests) and both type-checks are clean.

Reviewer notes

  • scripts/schema-change-pg16.ts and scripts/lib/ are still not in the repository, so the version matrix itself is not reproducible from this branch yet.
  • Not tested: tables over 1 GB, replicas.

… of 0 has an unknown row count

PostgreSQL 14 stores -1 in pg_class.reltuples for a table nobody has analyzed; 12 and 13 store 0, which read as an empty table. The catalog, the facts and the health report now treat 0 on a table whose file is not empty as unknown on those versions, so a large never-analyzed table is no longer reported as empty and the 'never analyzed' finding appears.
@swsarancodes
swsarancodes merged commit efcfcd1 into main Oct 24, 2026
1 check failed
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