Skip to content

PostgreSQL function inspector reads the right catalog columns, so schemas with functions migrate - #138

Merged
MelbourneDeveloper merged 162 commits into
mainfrom
fix/pg-function-inspector-ordinals
Nov 28, 2026
Merged

MelbourneDeveloper merged 162 commits into
mainfrom
fix/pg-function-inspector-ordinals

Conversation

@MelbourneDeveloper

Copy link
Copy Markdown
Collaborator

Problem

Issue #137: DataProviderMigrate migrate --provider postgres failed for every schema with a function in the inspected schema:

Error: schema integrity inspection failed: Reading as 'System.String' is not supported for fields having DataTypeName 'boolean'
Error: migration apply failed: Schema integrity verification failed before commit

The functions catalog query in PostgresSupportSchemaInspector selects owner_role (9), search_path_config (10) and revoke_public_execute (11); the reader used ordinals 10, 11 and 9.

Fix

The reader now uses 9, 10 and 11.

Test

Migrate_SchemaWithFunctionsPassesIntegrityInspectionAndRerunsClean runs the CLI on a schema with a secured function (owner, pinned search path, execute role, PUBLIC revoked) and a plain one (no owner, no search path, PUBLIC execute kept), asserts every inspected function field, and reruns to zero operations. It failed before the fix with schema integrity inspection failed and passes after.

Scope

The bug never reached main or a release: function ownership and search path exist only on refactor/deslop-ten-percent. This branch is main plus that branch plus the fix, so the PR carries that branch's commits as well.

The issue's "related gaps" (grant column lists, role passwords, CREATE SCHEMA) are not addressed here.

Refs #137 (kept open until the fix is verified on released binaries).

🤖 Generated with Claude Code

MelbourneDeveloper and others added 30 commits December 28, 2025 19:30
- Create Samples/ICD10AM folder structure for new microservice
- Add comprehensive SPEC.md with:
  - RAG search feature using MedEmbed-Large-v1 medical embedding model
  - Basic lookup with JSON and FHIR response formats
  - Mermaid ER diagram for database schema
  - API endpoint documentation
  - PostgreSQL with pgvector for vector similarity search
  - RLS (Row Level Security) via user impersonation
- Add icd10am-schema.yaml with DataProvider YAML migrations for:
  - ICD-10-AM chapters, blocks, categories, and codes
  - ACHI procedure blocks and codes
  - Embedding tables for vector storage
  - Coding standards and user search history
- Add Python import script (import_icd10am.py) to:
  - Parse IHACPA data files
  - Generate medical embeddings with MedEmbed
  - Bulk import into PostgreSQL
- Remove "Too Many Cooks" multi-agent section from CLAUDE.md

https://claude.ai/code/session_01Pxhuxx7gqh8RrTCEGJ2QU4
- Replace all SQL query files with LQL equivalents
- Add ICD10AM.Api.csproj with LQL transpilation support
- Add DataProvider.json configuration
- Add DatabaseSetup.cs and GlobalUsings.cs
- All queries now use pipeline syntax: filter, join, select, order_by

https://claude.ai/code/session_01Pxhuxx7gqh8RrTCEGJ2QU4
- Hierarchical browse: chapters, blocks, categories, codes
- Code lookup with JSON and FHIR format support
- ACHI procedure endpoints
- RAG search with embedding service integration
- Cosine similarity ranking for semantic search
- LQL transpilation enabled in csproj
- Updated DataProvider.json to use .generated.sql files

https://claude.ai/code/session_01Pxhuxx7gqh8RrTCEGJ2QU4
- Dockerfile using MedEmbed-Small-v0.1 (384 dims, ~500MB)
- FastAPI service with /embed and /embed/batch endpoints
- docker-compose.yml for easy deployment
- Health checks and resource limits configured
- Model downloaded at build time for fast startup

https://claude.ai/code/session_01Pxhuxx7gqh8RrTCEGJ2QU4
- ICD10AMApiFactory with seeded test data
- ChapterEndpointTests: hierarchical browse tests
- CodeLookupTests: code search and FHIR format tests
- AchiEndpointTests: procedure code tests
- HealthEndpointTests: health check tests
- Real database, zero mocking

https://claude.ai/code/session_01Pxhuxx7gqh8RrTCEGJ2QU4
- generate_sample_data.py creates test SQLite database
- Includes common ICD-10-AM codes (infectious, diabetes, cardiac, respiratory, etc.)
- Includes sample ACHI procedures (angiography, appendicectomy, hip replacement, etc.)
- Note: Full ICD-10-AM data requires licensing from IHACPA

https://claude.ai/code/session_01Pxhuxx7gqh8RrTCEGJ2QU4
- Update SPEC.md with IHACPA licensing requirements
- Add .gitignore for generated files, databases, Python cache
- Note: Full ICD-10-AM data requires purchase from IHACPA

https://claude.ai/code/session_01Pxhuxx7gqh8RrTCEGJ2QU4
BREAKING: No more licensed IHACPA data!

- Add import_icd10cm.py that downloads FREE data from CMS.gov
- Successfully imports 71,704 diagnosis codes
- 19 chapters, 1,910 blocks, 1,910 categories
- Update SPEC.md to document free data sources
- Remove licensing requirements (CMS data is public domain)

Data sources:
- Primary: https://www.cms.gov/medicare/coding-billing/icd-10-codes
- Mirror: GitHub JSON gist for faster downloads

https://claude.ai/code/session_01Pxhuxx7gqh8RrTCEGJ2QU4
- Fixed syntax error in try/except blocks around IHACPA download
- Added CDC ICD-10-CM as fallback when IHACPA returns 503 errors
- Uses free US Government CDC data (74,260 codes) which shares
  WHO ICD-10 base with Australian ICD-10-AM
- Script now successfully imports codes when IHACPA is unavailable

https://claude.ai/code/session_01Pxhuxx7gqh8RrTCEGJ2QU4
- Renamed folder from ICD10AM to ICD10CM (honest about data source)
- Simplified import script - CDC data only, no fallback bullshit
- 74,260 ICD-10-CM codes from CDC (public domain)
- Clean database schema with icd10cm_ table prefix

https://claude.ai/code/session_01Pxhuxx7gqh8RrTCEGJ2QU4
- Fix DI registration for Func<HttpClient> embedding service
- Fix DatabaseSetup to skip initialization if tables exist (for tests)
- Remove unsupported 'unique' property from schema indexes
- Remove SearchCodes/SearchAchiCodes LQL files (LIKE not supported)
- Implement manual SQL search endpoints in Program.cs
- Disable AOT in LqlCli.SQLite to avoid missing ILCompiler packages
- Update GlobalUsings to remove unused Search result types
- Disable NuGet audit in Directory.Build.props for proxy issues

https://claude.ai/code/session_01Pxhuxx7gqh8RrTCEGJ2QU4
- generate_embeddings.py: Populates icd10cm_code_embedding table
  using MedEmbed-small-v0.1 model (384 dimensions)
- embedding_service.py: Runtime service for encoding user queries
- SPEC.md: Document the 3-step setup process:
  1. Import codes (import_icd10cm.py)
  2. Generate embeddings (generate_embeddings.py)
  3. Start embedding service (embedding_service.py)

https://claude.ai/code/session_01Pxhuxx7gqh8RrTCEGJ2QU4
Updated LQL query to reference icd10cm_code_embedding and icd10cm_code
tables where the 74,260 embeddings are stored. Added icd10cm_code and
icd10cm_code_embedding table definitions to schema and DataProvider.json.

30 E2E tests passing, RAG semantic search working with MedEmbed model.

https://claude.ai/code/session_01Pxhuxx7gqh8RrTCEGJ2QU4
Replaced Python embedding service with native C# ONNX Runtime:
- Added Microsoft.ML.OnnxRuntime and BERTTokenizers NuGet packages
- EncodeWithOnnx helper performs tokenization and mean pooling
- Updated SPEC.md with download instructions for ONNX model
- Model (127MB) excluded from git - download with optimum-cli

30 E2E tests passing, RAG search works without any Python dependency.

https://claude.ai/code/session_01Pxhuxx7gqh8RrTCEGJ2QU4
The BERTTokenizers library requires vocabulary files in a Vocabularies
directory. These files are needed for tokenizing query text before
encoding with the ONNX model.

https://claude.ai/code/session_01Pxhuxx7gqh8RrTCEGJ2QU4
Documents how to:
- Setup database and generate embeddings (one-time Python)
- Export ONNX model for C# runtime
- Run the API
- Run E2E tests
- Troubleshoot common issues

https://claude.ai/code/session_01Pxhuxx7gqh8RrTCEGJ2QU4
MelbourneDeveloper and others added 27 commits October 14, 2026 10:11
Bumps [follow-redirects](https://github.com/follow-redirects/follow-redirects) from 1.16.0 to 1.16.1.
- [Release notes](https://github.com/follow-redirects/follow-redirects/releases)
- [Commits](follow-redirects/follow-redirects@v1.16.0...v1.16.1)

---
updated-dependencies:
- dependency-name: follow-redirects
  dependency-version: 1.16.1
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>
Bumps [markdown-it](https://github.com/markdown-it/markdown-it) from 14.2.0 to 14.3.3.
- [Changelog](https://github.com/markdown-it/markdown-it/blob/14.3.3/CHANGELOG.md)
- [Commits](markdown-it/markdown-it@14.2.0...14.3.3)

---
updated-dependencies:
- dependency-name: markdown-it
  dependency-version: 14.3.3
  dependency-type: direct:development
...

Signed-off-by: dependabot[bot] <support@github.com>
Bumps [markdown-it](https://github.com/markdown-it/markdown-it) from 14.3.2 to 14.3.3.
- [Changelog](https://github.com/markdown-it/markdown-it/blob/14.3.3/CHANGELOG.md)
- [Commits](markdown-it/markdown-it@14.3.2...14.3.3)

---
updated-dependencies:
- dependency-name: markdown-it
  dependency-version: 14.3.3
  dependency-type: direct:development
...

Signed-off-by: dependabot[bot] <support@github.com>
Bumps [undici](https://github.com/nodejs/undici) from 7.30.0 to 7.30.1.
- [Release notes](https://github.com/nodejs/undici/releases)
- [Commits](nodejs/undici@v7.30.0...v7.30.1)

---
updated-dependencies:
- dependency-name: undici
  dependency-version: 7.30.1
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>
Bumps [rustls](https://github.com/rustls/rustls) from 0.23.37 to 0.23.46.
- [Release notes](https://github.com/rustls/rustls/releases)
- [Changelog](https://github.com/rustls/rustls/blob/main/CHANGELOG.md)
- [Commits](rustls/rustls@v/0.23.37...v/0.23.46)

---
updated-dependencies:
- dependency-name: rustls
  dependency-version: 0.23.46
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>
…t/rustls-0.23.46' into refactor/deslop-ten-percent
…xtension/js-yaml-3.15.2' into refactor/deslop-ten-percent
…xtension/undici-7.30.1' into refactor/deslop-ten-percent
…ebsite-Eleventy/markdown-it-14.3.3' into refactor/deslop-ten-percent
…brace-expansion-1.1.21' into refactor/deslop-ten-percent
…follow-redirects-1.16.1' into refactor/deslop-ten-percent
…liquidjs-10.30.0' into refactor/deslop-ten-percent
…markdown-it-14.3.3' into refactor/deslop-ten-percent
…cute from the columns the query selects (#137)

The functions catalog query selects owner_role (9), search_path_config (10)
and revoke_public_execute (11), but the reader used 10, 11 and 9, so any
schema with a function failed integrity inspection with "Reading as
'System.String' is not supported for fields having DataTypeName 'boolean'".

Adds a CLI regression test that migrates a schema with a secured and a plain
function, inspects every function field, and reruns to zero operations.
… partial-index predicate is replaced (#103)

A new column's CHECK is created inline by AddColumn, so the diff no longer
also emits ADD CONSTRAINT for it, which failed on the duplicate name.

An existing index whose filter differs from the desired one is now dropped
and re-created, compared with the integrity verifier's own SQL equality, so
the migration converges instead of failing verification with 'filter
drifted'. That drop is marked as a replacement and is not destructive.
Without a global.json the build picked SDK 11.0.100 on the CI image, where
Nimblesite.Sync.Http.Tests fails in the Blazor static web assets targets.
…Chromium

ubuntu-latest now resolves to 26.04, where the pinned Playwright fails with
'Playwright does not support chromium on ubuntu26.04-x64'.
…lyzer)

The Rust coverage gate (98%) was one line short after a toolchain update;
this exercises the nested-pipeline branch of function-call collection that
had no test.
@MelbourneDeveloper
MelbourneDeveloper merged commit b6b7acd into main Nov 28, 2026
11 checks passed
@MelbourneDeveloper
MelbourneDeveloper deleted the fix/pg-function-inspector-ordinals branch November 28, 2026 10:14
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.

2 participants