fix: add foreign-table coverage to pg_advisor and pg_describe_table#18
fix: add foreign-table coverage to pg_advisor and pg_describe_table#18HighviewOne wants to merge 2 commits into
Conversation
Closes #10. pg_advisor.tables_without_primary_key filtered relkind IN ('r','p') and silently missed foreign tables (relkind='f'). A foreign table without a defined PK is the same design-drift signal as a heap table -- the PK is not enforced by the FDW but it communicates schema intent. Expand to relkind IN ('r','p','f'). pg_describe_table already had the 'foreign_table' branch in its CASE expression but no fixture exercised it, leaving that branch untested. Fixture additions (fixtures.ts): - setupFdwFixture(): best-effort self-referential postgres_fdw setup that parses DATABASE_URL and creates a SERVER, USER MAPPING, and foreign table remote_users pointing back at the same cluster. Returns false when postgres_fdw is unavailable so dependent tests skip gracefully. - fdwFixtureAvailable(): exported flag read by tests to skip FDW assertions. - setupFixtures() calls setupFdwFixture() at the end; teardownFixtures() drops the cluster-level SERVER (schema CASCADE handles the foreign table). New tests: - pg_advisor: remote_users (no defined PK) appears in tables_without_primary_key - pg_describe_table: remote_users has kind='foreign_table' with columns - pg_list_tables: assertion updated to include remote_users when FDW is available 88 integration tests pass (87 existing + 1 new).
|
Review punch list for this PR. Item 1 is the blocker; the FDW fixture work itself is solid (best-effort setup, OPTIONS values escaped, cluster-level SERVER cleaned up in teardown) and the pg_describe_table foreign-table test is a good add.
🤖 Generated with Claude Code |
PostgreSQL forbids PRIMARY KEY (and UNIQUE) constraints on foreign tables
entirely, so including relkind='f' in tables_without_primary_key produced
permanently unresolvable findings with no remediation path.
- admin.ts: drop 'f' from relkind IN ('r', 'p', 'f'); add comment
explaining the exclusion; update tool description accordingly
- admin.integration.test.ts: flip assertion -- remote_users (foreign
table) must NOT appear in tables_without_primary_key
- fixtures.ts: add console.error on FDW statement failure so skips are
debuggable; omit password option entirely for trust-auth setups
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
|
Addressed all review points. Blocker resolved:
|
Closes #10.
What
Two gaps in foreign-table (
relkind='f') coverage:pg_advisor.tables_without_primary_keyfilteredrelkind IN ('r', 'p')and silently skipped foreign tables. A foreign table without a defined PK is the same design-drift signal — the constraint isn't enforced by the FDW but it communicates schema intent.pg_describe_tablealready had the'foreign_table'branch in itsCASEexpression but no fixture exercised it, leaving that branch untested.Changes
src/tools/admin.tsrelkind IN ('r', 'p')→relkind IN ('r', 'p', 'f')inpg_advisorsrc/integration/fixtures.tssetupFdwFixture(): best-effort self-referential postgres_fdw setup. ParsesDATABASE_URL, creates aSERVER,USER MAPPING, andremote_usersforeign table pointing back at the same cluster. Returnsfalsewhen postgres_fdw is unavailable so dependent assertions skip gracefully.fdwFixtureAvailable(): exported flag read by testssetupFixtures()callssetupFdwFixture()at the end;teardownFixtures()drops the cluster-levelSERVER(schemaCASCADEhandles the foreign table itself)Integration tests
pg_advisor:remote_users(no defined PK) appears intables_without_primary_keypg_describe_table:remote_usershaskind='foreign_table'with correct columnspg_list_tables: hardcoded name list updated to includeremote_userswhen FDW is availableAll 88 integration tests pass (87 existing + 1 new
pg_describe_tabletest). FDW-dependent assertions skip cleanly whenpostgres_fdwis unavailable.🤖 Generated with Claude Code