Repository navigation
fix(schema/postgres): correct index column order, INCLUDE/expression keys, partitioned indexes and key flags (#620) - #622
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
Claude finished @ajitpratap0's task in 23s —— View job Review of PR #622 (fix for #620, PostgreSQL index and key metadata)I read the diff of Verdict: The change is correct and well scoped. I have no blocking concerns. What looks good
Minor points (non-blocking)
Performance and security
|
…keys, partitioned-parent indexes, FK referenced schema and catalog-based key flags (#620) The PostgreSQL loader misreported several things: - index columns came back in table (attnum) order, not index key order; - INCLUDE columns were treated as key columns; - expression keys were dropped, so expression-only indexes vanished; - partitioned parents (relkind 'p') reported no indexes; - columns in several UNIQUE constraints were emitted more than once and any composite-UNIQUE member was flagged IsUnique; - PK/UNIQUE flags came from information_schema views, which hide constraints from non-owner roles, so a SELECT-only role saw every flag as false; - foreign keys lost the referenced table's schema. Indexes now unnest pg_index.indkey WITH ORDINALITY: the first indnkeyatts entries are key columns in index order (expression keys rendered with pg_get_indexdef), the rest are INCLUDE columns. Key flags come from pg_constraint, aggregated per column. Foreign keys join pg_namespace for the referenced relation. API (additive): db.Index.IncludeColumns and db.ForeignKey.RefSchema. Index.Columns now holds key columns only and may contain expression text. IsUnique is set only for a single-column UNIQUE constraint, matching MySQL's COLUMN_KEY = 'UNI'. The MySQL and SQLite loaders are unchanged; their new fields stay zero. Tests: TestPostgresLoader_IndexAndKeyMetadata covers the issue fixture through Load and LoadTable, plus a SELECT-only role that must see the same schema as the owner. A MariaDB testcontainer variant (TestMariaDBLoader) shares assertions with the MySQL tests. Docker is not available locally, so testcontainers tests skip here. The PostgreSQL tests were run against a throwaway local PostgreSQL 17 server and failed before / pass after the fix. The MariaDB variant was NOT run locally. Fixes #620 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01UZSk1292jPc8ipDboNxeve
a708511 to
0aeaa50
Compare
|
Claude finished @ajitpratap0's task in 21s —— View job Review of PR #622 (PostgreSQL index and key metadata, fixes #620)I read the diff of Verdict: The change is correct and well scoped. I found no blocking issues. Correctness
Minor points (non-blocking)
Performance and security
No files changed. |
|
Merge train (batch 3): rebased onto main (0aeaa50). The adversarial + security pass (Opus) found no issues. It confirmed the catalog queries remain parameterized ( |
Summary
#620 schema/postgres: loader misreports index columns and key flags (column order, INCLUDE, expression and partitioned indexes, read-only roles)
This fixes #620 in the PostgreSQL schema loader. It now reads index entries from pg_index.indkey in key order. Only the first indnkeyatts entries are key columns, and the new additive Index.IncludeColumns field holds the INCLUDE columns. Expression keys are reported as pg_get_indexdef text, and indexes on partitioned parents (relkind 'p') are now listed. PK/UNIQUE column flags now come from pg_constraint, aggregated per column. Each column appears once, IsUnique is set only for a single-column UNIQUE, and a SELECT-only role sees the same schema as the owner. Foreign keys now carry the referenced schema in the new additive ForeignKey.RefSchema field. To verify, the new tests were run against a live PostgreSQL 17.11: they reproduce every symptom in the issue on the parent loader and pass on HEAD. The full race gate, go vet and golangci-lint are clean. Deferred as out of scope, with sound reasons: RefSchema for the MySQL and SQLite loaders, IsUnique from non-constraint UNIQUE indexes (behaviour unchanged), invalid and partial index predicates, and expression/INCLUDE handling for MySQL and SQLite. The new TestMariaDBLoader variant has not been run locally (no Docker) and will first run in CI.
Commits (1), one implementation commit per issue plus test-only follow-ups:
4 files changed, 317 insertions(+), 60 deletions(-)Test Plan
CGO_ENABLED=1 go test -race -timeout 300s $(go list ./... | grep -v /cbinding)),go vet,golangci-lint, re-ran the reproduction cases on HEAD, and confirmed the new tests fail on the parent commit.benchstat -count=6before/after on the same machine.#620 evidence (validator)
#620 race gate: PASS. Ran CGO_ENABLED=1 go test -race -timeout 300s $(go list ./... | grep -v /cbinding) on HEAD a708511 and it exited 0. All 44 packages are ok and none failed, including pkg/schema, pkg/schema/mysql, pkg/schema/postgres and pkg/schema/sqlite. Docker is not available, so the testcontainers tests skip in this gate. To cover them, I copied HEAD into the scratchpad, pointed the test helper at a throwaway local PostgreSQL 17.11 server, and ran go test -race on pkg/schema/postgres there. It passed, including all 6 subtests of TestPostgresLoader_IndexAndKeyMetadata.
Breaking Changes
IncludeColumns []string(PostgreSQL INCLUDE columns, nil otherwise). pkg/schema/db.ForeignKey gainsRefSchema string, set by the PostgreSQL loader and empty for MySQL and SQLite. Observable PostgreSQL loader changes:No signatures change.
Notes
gosqlx formatsilently corrupts many expressions; switch the CLI to pkg/formatter #599-schema/postgres: loader misreports index columns and key flags (column order, INCLUDE, expression and partitioned indexes, read-only roles) #620); later PRs in the train are rebased onto this one after it merges.main.Fixes #620
Follow-up to #566
🤖 Generated with Claude Code
https://claude.ai/code/session_01UZSk1292jPc8ipDboNxeve