Skip to content

fix(db): align schema.sql corrector body with the applied migration 20260831100000 - #2493

Merged
BigSimmo merged 1 commit into
mainfrom
claude/clinical-corrector-mirror
Sep 1, 2026
Merged

fix(db): align schema.sql corrector body with the applied migration 20260831100000#2493
BigSimmo merged 1 commit into
mainfrom
claude/clinical-corrector-mirror

Conversation

@BigSimmo

@BigSimmo BigSimmo commented Sep 1, 2026

Copy link
Copy Markdown
Owner

Summary

  • Align the public.correct_clinical_query_terms(text,real) body in supabase/schema.sql with the already-applied migration 20260831100000, adding the one line the mirror was missing.
  • Regenerate supabase/drift-manifest.json from the corrected schema.sql.

This closes the sole unexpected finding on the failing live-drift run. No migration is added, no live database object is changed, and no retrieval or ranking code is touched.

The problem

live-drift run 33484535655 (2026-09-01, on main at d3074946a) failed with exactly one unexpected finding:

! [functions] mismatch public.correct_clinical_query_terms(text,real) ::
  def_hash: manifest="e2356565197b3d4c13f1b3d7a624696b" live="2ebaf978b69f3de0c47d9d0924419c74"

This is a mirror gap, not a live-database problem. Migration 20260831100000 (merged in PR #2477) redefined the function with a duplicated and length(canonical) between 4 and 40 predicate in the canonical branch of its UNION, and supabase/schema.sql was never updated to match — it remained byte-identical to the earlier 20260828000000 form. The drift manifest is generated by replaying schema.sql into the pinned supabase/postgres:17.6.1.127 image, so the manifest and live disagreed even though live is exactly what the applied migration created.

Same failure class as the original #316 root cause, where SET work_mem was absent from schema.sql. The gap in CI that let it through is already tracked as #QCNE6N.

Why codify live rather than fix live

Auto-deploy is ON: merging a migration applies it to the production clinical database within seconds. A migration to remove the duplicate would push a change to a live clinical-search function purely to tidy cosmetic text. The mirror is what is wrong, so the mirror is what this PR corrects.

The duplicated line is obviously accidental and it would be reasonable to drop it from both live and the mirror the next time this function is changed for a real reason. That is deliberately not bundled here.

Evidence

The decisive proof, obtained offline with no live database access. After the schema.sql edit, npm run drift:manifest regenerated the manifest and reported, for signature public.correct_clinical_query_terms(text,real):

def_hash  : 2ebaf978b69f3de0c47d9d0924419c74
live      : 2ebaf978b69f3de0c47d9d0924419c74
MATCH     : True

That is byte-for-byte the live hash the failing run reported, which confirms the diagnosis is complete: the duplicated line is the whole of the divergence, and nothing else in live is unexplained.

Regenerating the manifest moved exactly one snapshot entry — that function's def_hash — plus the expected generated_at, schema_sha256 and replay_seconds metadata. Every other object across 96 functions, 43 tables, 222 indexes, 53 policies, 207 constraints, 26 triggers, 1 view, 6 extensions and 2 storage buckets hashed identically to the committed manifest.

Tests. npm run test:focused was run first and is reported here as no coverage, not as a pass: Vitest's related selector works on the module import graph, and .sql/.json data files are read at runtime rather than imported, so it found no test files and exited 0. The covering suites were therefore discovered by grep and run explicitly:

Test Files  18 passed (18)
      Tests  310 passed (310)

That set includes drift-detection, supabase-schema, migration-history-guards, migration-history-alignment, search-health-index-coverage, function-grants, hosted-migration-role-guard, live-drift-workflow, owner-scope-guard, retrieval-access-scope and the RAG source-pin contract test rag-imputation-contract. The check:function-grants: FAIL lines in that run's stdout are that suite's own negative fixtures, which feed deliberately-bad SQL to prove the guard fires.

Formatting. .sql has no Prettier parser and supabase/drift-manifest.json is listed in .prettierignore, so neither changed file is within Prettier's remit. prettier --check over the exact file set in this commit reports All matched files use Prettier code style!.

Not run, by design. npm run check:drift reads the live database and was deliberately not run; no Supabase, OpenAI, Railway or other provider-backed command was executed at any point. GitHub remains the authority on whether the alarm actually clears — the post-merge live-drift run is the real gate.

RAG impact: no retrieval behaviour change — supabase/schema.sql is being aligned to the already-applied migration 20260831100000; the only textual difference is a duplicated, byte-identical AND predicate, which is a boolean no-op. No migration, no live change, and no ranking or retrieval surface is edited.

The equivalence was re-proved rather than inherited. The duplicated conjunct sits in a pure and chain (where enabled and owner_id is null and P and P and lower(canonical) % tok), and length(canonical) between 4 and 40 is immutable and side-effect free, so P and P is P and the result set is unchanged. A duplicated predicate can in principle lower the planner's row estimate and change the chosen plan, but it cannot change the rows returned, because both the inner order by … limit 32 and the outer order by … limit 1 are deterministic over the selected tuples. In any case this PR changes no live object, so live execution is not affected at all.

Clinical Governance Preflight

  • Source-backed claims still require linked source verification before clinical use
  • No patient-identifiable document workflow was introduced or expanded without explicit governance approval
  • Supabase target remains Clinical KB Database (sjrfecxgysukkwxsowpy)
  • Service-role keys and private document access remain server-only
  • Demo/synthetic content remains clearly separated from real clinical sources
  • Source metadata, review status, and outdated/unknown-source behavior remain conservative
  • Deployment classification/TGA SaMD impact was checked when clinical decision-support behavior changed

No clinical decision-support behaviour changes in this PR: it edits a mirror file and a generated manifest so that they describe the function the production database is already running.

🤖 Generated with Claude Code


Note

Low Risk
Mirror and generated manifest only; production DB behavior is unchanged and the SQL edit is a redundant predicate with no semantic effect.

Overview
Fixes live-drift by making supabase/schema.sql match the production definition of public.correct_clinical_query_terms(text,real) from migration 20260831100000, which the mirror had not picked up.

The only body change is a duplicate and length(canonical) between 4 and 40 in the rag_aliases branch of the function’s UNION—a logical no-op that already exists on the live database. No new migration and no change to live objects; retrieval and ranking code are untouched.

supabase/drift-manifest.json was regenerated (schema_sha256, def_hash for that function, metadata timestamps) so replayed schema matches live hashes again.

Reviewed by Cursor Bugbot for commit 80f72bb. Configure here.

…0260831100000

live-drift has been red since 2026-08-25 and its sole unexpected finding on the
2026-09-01 run was a def_hash mismatch on
public.correct_clinical_query_terms(text,real): manifest e2356565 vs live
2ebaf978.

The cause is a mirror gap, not a live-database problem. Migration
20260831100000 (PR #2477) redefined the function with a duplicated
`and length(canonical) between 4 and 40` predicate in the canonical UNION
branch, and supabase/schema.sql was never updated to match — it was still
byte-identical to the earlier 20260828000000 form. The drift manifest is
generated by replaying schema.sql into the pinned Postgres image, so the
manifest and live disagreed even though live is exactly what the applied
migration created.

Codify live rather than write a migration: auto-deploy is ON, and a migration
would push a change to a live clinical-search function in production for a
cosmetic reason.

Proven offline, with no live access: after this edit the regenerated manifest
reports def_hash 2ebaf978b69f3de0c47d9d0924419c74 for that signature — exactly
the live value the failing run reported. Regeneration moved that one entry and
nothing else across 96 functions, 43 tables, 222 indexes, 53 policies, 207
constraints and 26 triggers.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Sep 1, 2026

Copy link
Copy Markdown
Contributor

Important

  • 🔍 Trigger review

This repository does not receive automatic reviews because it has fewer than 10 stars.

⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Team

Run ID: f4e996b9-490e-4c2a-ba6f-de1a70ef0292


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@cursor

cursor Bot commented Sep 1, 2026

Copy link
Copy Markdown
Contributor

Bugbot couldn't run - usage limit reached

Bugbot is counted against Cursor usage for this user or team, and this run hit a usage or spend limit.

A user or team admin can review and increase usage limits in the Cursor dashboard.

(requestId: serverGenReqId_3465687c-929b-4fef-a9e4-6e1375b1c481)

@supabase

supabase Bot commented Sep 1, 2026

Copy link
Copy Markdown

Updates to Preview Branch (claude/clinical-corrector-mirror) ↗︎

Deployments Status Updated
Database Tue, 01 Sep 2026 09:01:15 UTC
Services Tue, 01 Sep 2026 09:01:15 UTC
APIs Tue, 01 Sep 2026 09:01:15 UTC

Tasks are run on every commit but only new migration files are pushed.
Close and reopen this PR if you want to apply changes from existing seed or migration files.

Tasks Status Updated
Configurations Tue, 01 Sep 2026 09:01:23 UTC
Migrations Tue, 01 Sep 2026 09:03:02 UTC
Seeding Tue, 01 Sep 2026 09:03:07 UTC
Edge Functions Tue, 01 Sep 2026 09:03:09 UTC

View logs for this Workflow Run ↗︎.
Learn more about Supabase for Git ↗︎.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 1, 2026

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review Completed 2026-09-01T09:03:02.465370Z 80f72bb PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@BigSimmo
BigSimmo enabled auto-merge (squash) September 1, 2026 09:04
@BigSimmo
BigSimmo merged commit be7946d into main Sep 1, 2026
33 of 34 checks passed
@BigSimmo
BigSimmo deleted the claude/clinical-corrector-mirror branch September 1, 2026 09:09
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