fix(db): remove phantom ingestion_job_stages.job_id FK to match live (R24e)#389
Merged
Conversation
…(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>
|
This pull request has been ignored for the connected project Preview Branches by Supabase. |
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
BigSimmo
enabled auto-merge
July 8, 2026 08:30
Copilot stopped work on behalf of
BigSimmo due to an error
July 8, 2026 08:43
Owner
Author
This was referenced Jul 8, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Implements state-machine finding R24e [FRESH-ENV-ONLY]: removes the phantom
ingestion_job_stages.job_id → ingestion_jobs(id)foreign key thatschema.sql(and migration20260625000000) declare but the live project does not have.Why remove (not add): verified read-only against live — the column holds
indexing_v3_agent_jobsids (the edge agent writes the agent-job id intojob_id), notingestion_jobsids. Live carries ~253 orphan stage rows and 0 rows whosejob_idresolves to aningestion_jobsrow. On anyschema.sql- or migration-provisioned environment the FK makes every needs-work agent run die at its first stage insert (FK23503) and burn attempts to terminalfailed. The drift-allowlist's prior plan (ADD viaNOT VALID + VALIDATE) would both destroy stage-log history and break the agent. Document cleanup stays covered byingestion_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.sql—drop constraint if exists(idempotent; no-op on live, drops it on migration-replay envs).supabase/schema.sql—job_id uuid not nullwithout the FK.supabase/drift-allowlist.json— removed the now-resolvedmissing_liveentry.supabase/drift-manifest.json— removed the FK constraint entry + recomputedschema_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
npm run verify:cheap— green (offline drift-detection freshness/parity test + schema test both pass).npm run check:driftagainst live — theingestion_job_stages_job_id_fkeydivergence is gone (appears in neither the drift nor the stale-allowlist list). The remainingcheck:driftred is pre-existing and unrelated: thecomplete_ingestion_job/fail_or_retry/refresh_import_batch_status/cleanup_*entries are PR fix(ingestion): R1/R2 fences + R7/R9/R23 RPC hardening + R24e stage-FK removal #380 (merged, not yet applied to live) — they resolve when the operator applies fix(ingestion): R1/R2 fences + R7/R9/R23 RPC hardening + R24e stage-FK removal #380.Note on the manifest
supabase/drift-manifest.jsonwas hand-edited (one FK constraint object removed +schema_sha256recomputed from the LF-normalizedschema.sql) because the Dockerdrift:manifestreplay was not responsive in this environment. A subtractive constraint removal cannot affect a from-scratch replay,normalizedSchemaSha256is a plain sha of the file, andcheck:driftagainst live confirms the result — but a reviewer can runnpm run drift:manifestto confirm byte-identical output.🤖 Generated with Claude Code