Skip to content

fix(db): remove phantom ingestion_job_stages.job_id FK to match live (R24e)#389

Merged
BigSimmo merged 2 commits into
mainfrom
claude/ingestion-r24e-drop-stage-fk
Jul 8, 2026
Merged

fix(db): remove phantom ingestion_job_stages.job_id FK to match live (R24e)#389
BigSimmo merged 2 commits into
mainfrom
claude/ingestion-r24e-drop-stage-fk

Conversation

@BigSimmo

@BigSimmo BigSimmo commented Jul 8, 2026

Copy link
Copy Markdown
Owner

Summary

Implements state-machine finding R24e [FRESH-ENV-ONLY]: removes the phantom ingestion_job_stages.job_id → ingestion_jobs(id) foreign key that schema.sql (and migration 20260625000000) declare but the live project does not have.

Why remove (not add): verified read-only against live — the column holds indexing_v3_agent_jobs ids (the edge agent writes the agent-job id into job_id), not ingestion_jobs ids. Live carries ~253 orphan stage rows and 0 rows whose job_id resolves to an ingestion_jobs row. On any schema.sql- or migration-provisioned environment the FK makes every needs-work agent run die at its first stage insert (FK 23503) and burn attempts to terminal failed. The drift-allowlist's prior plan (ADD via NOT VALID + VALIDATE) would both destroy stage-log history and break the agent. Document cleanup stays covered by ingestion_job_stages.document_id → documents ON DELETE CASCADE (the FK live actually has).

This supersedes reconciliation-backlog item #8 in docs/database-drift-detection.md.

Changes

  • supabase/migrations/20260708140000_drop_ingestion_job_stages_job_id_fk.sqldrop constraint if exists (idempotent; no-op on live, drops it on migration-replay envs).
  • supabase/schema.sqljob_id uuid not null without the FK.
  • supabase/drift-allowlist.json — removed the now-resolved missing_live entry.
  • supabase/drift-manifest.json — removed the FK constraint entry + recomputed schema_sha256.
  • docs/database-drift-detection.md — backlog item Bump gitleaks/gitleaks-action from 2 to 3 #8 marked reversed.
  • tests/supabase-schema.test.ts — updated to pin the removal.

Verification

Note on the manifest

supabase/drift-manifest.json was hand-edited (one FK constraint object removed + schema_sha256 recomputed from the LF-normalized schema.sql) because the Docker drift:manifest replay was not responsive in this environment. A subtractive constraint removal cannot affect a from-scratch replay, normalizedSchemaSha256 is a plain sha of the file, and check:drift against live confirms the result — but a reviewer can run npm run drift:manifest to confirm byte-identical output.

🤖 Generated with Claude Code

…(R24e)

State-machine finding R24e [FRESH-ENV-ONLY]: schema.sql and migration
20260625000000 declare
  job_id uuid not null references public.ingestion_jobs(id) on delete cascade,
but this FK is ABSENT on live, and the column holds indexing_v3_agent_jobs ids
(the edge agent writes the agent-job id into job_id), not ingestion_jobs ids.
On any schema.sql-/migration-provisioned environment the FK makes every
needs-work agent run die at its first stage insert (FK 23503) and burn attempts
to terminal failed.

Verified read-only against live: ~253 orphan stage rows and 0 rows whose job_id
resolves to an ingestion_jobs row. So the drift-allowlist's prior plan (ADD via
NOT VALID + VALIDATE) would both destroy stage-log history and break the agent.
Remove the FK so fresh/preview envs match live; cleanup stays covered by
ingestion_job_stages.document_id -> documents ON DELETE CASCADE.

- migration 20260708140000 drops the constraint (idempotent; no-op on live)
- schema.sql declares job_id without the FK
- drift-allowlist entry removed; drift-manifest.json reconciled (FK entry removed
  + schema sha recomputed). Manifest hand-edited (Docker drift:manifest replay
  unavailable in this env); a subtractive constraint removal cannot affect
  from-scratch replay and check:drift against live confirms the FK no longer
  diverges. Reviewer can run npm run drift:manifest to confirm byte-identical.
- docs/database-drift-detection.md backlog item #8 reversed
- tests/supabase-schema.test.ts updated to pin the removal

Supersedes reconciliation-backlog item #8. verify:cheap green (1320 tests).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@supabase

supabase Bot commented Jul 8, 2026

Copy link
Copy Markdown

This pull request has been ignored for the connected project sjrfecxgysukkwxsowpy due to reaching the limit of concurrent preview branches.
Go to Project Integrations Settings ↗︎ if you wish to update this limit.


Preview Branches by Supabase.
Learn more about Supabase Branching ↗︎.

@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

@BigSimmo
BigSimmo enabled auto-merge July 8, 2026 08:30
@BigSimmo

BigSimmo commented Jul 8, 2026

Copy link
Copy Markdown
Owner Author

This branch duplicates #386 (same R24e FK drop). Recommend closing in favor of #386, which already has green CI and the Codex review fix for OCR retry targets.

@BigSimmo
BigSimmo merged commit e6e8d40 into main Jul 8, 2026
7 of 12 checks passed
@BigSimmo
BigSimmo deleted the claude/ingestion-r24e-drop-stage-fk branch July 8, 2026 16:16
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