fix(plugin-postgresql): gate version-dependent system catalogs (#1240)#1241
Merged
Conversation
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.
Summary
Issue #1240: TablePro 0.40.2 fails to connect to old PostgreSQL servers with
ERROR: relation "pg_matviews" does not exist. This PR introduces aPostgreSQLCapabilitiesmodel derived fromPQserverVersionand routes every version-dependent SQL site through it.Audit (the immediate bug was the tip of the iceberg)
pg_matviewsfetchTablespg_foreign_tablefetchTablesattidentityfetchColumns/fetchAllColumns/fetchTableDDLattgeneratedarray_position()fetchIndexespg_sequencesfetchDependentSequencesdatlocprovider/daticulocale/datlocalefetchTemplate1Defaults,createDatabaseFormSpec,createDatabaseOnly #1 and #2 were caught by the original report — the rest were latent regressions that would have surfaced as soon as the PG < 10 user clicked on a table.
Changes
New
Plugins/PostgreSQLDriverPlugin/PostgreSQLCapabilities.swift— single source of truth, each flag documents its minimum PG version inline:LibPQPluginConnection.swift— caches the numeric value fromPQserverVersion(connection)alongside the existing display string; newserverVersionNumber() -> Int32accessor.PostgreSQLPluginDriver.swift— addsvar capabilitiescomputed from the connection; rewrites:fetchTablesUNION pieces are appended only when the catalog exists.fetchIndexesusesORDER BY array_position(...)only when supported, falls back toORDER BY a.attnum(deterministic ordering, may not match index logical order on PG <9.5).fetchTableDDLbuilds the identity / generatedCASEclauses conditionally; theatthasdefguard adapts.fetchDependentSequencesshort-circuits whenpg_sequencesis unavailable (DDL still generates, just without sequence details).fetchTemplate1Defaults,createDatabaseFormSpec, and theCREATE DATABASEbuilder now consultcapabilities.hasDatabaseICULocale/hasDatabaseLocaleinstead of the local ad-hocparsedServerMajorVersion()(now deleted).PostgreSQLPluginDriver+Columns.swift—fetchColumnsandfetchAllColumnssubstituteNULL::textforattidentity/attgeneratedprojections when the columns don't exist, so the row shape stays stable andmapPgColumnRowneeds no change.What stays unchanged
pg_collation.collprovider(PG 10+) call infetchCollations()is wrapped indo/catchthat returns empty arrays, so PG <10 still falls back cleanly. Left as-is to keep the diff focused.Test plan
Notes
Bundled plugin — ships in the next app release. No registry republish per
feedback_no_registry_for_builtins.