Skip to content

fix(db): restore orphan migration versions for Supabase Preview#952

Merged
BigSimmo merged 23 commits into
mainfrom
cursor/supabase-preview-migration-drift-7850
Jul 20, 2026
Merged

fix(db): restore orphan migration versions for Supabase Preview#952
BigSimmo merged 23 commits into
mainfrom
cursor/supabase-preview-migration-drift-7850

Conversation

@BigSimmo

@BigSimmo BigSimmo commented Jul 20, 2026

Copy link
Copy Markdown
Owner

Summary

  • Restores orphaned historical migration versions required by Supabase Preview so preview validation no longer fails when remote schema_migrations contains versions that were renamed or removed locally.
  • Adds intentional no-op placeholder migrations (select 1;) for the missing historical versions while keeping the real schema and ACL changes in the existing replacement migrations.
  • Adds/updates migration-history validation so preview drift is detected clearly and the expected placeholder files are enforced by tests.
  • Documents the Preview failure mode and troubleshooting path for orphaned migration-history versions.

Verification

  • Targeted tests covering migration placeholder enforcement and migration-history validation passed
  • Preview migration-history/drift checks passed
  • Relevant CI/job validation for this change passed
  • No application runtime, UI, or answer-generation behavior changed
  • No production migration was executed by this PR

Risk and rollout

  • Risk: low — this change is limited to Supabase Preview migration-history reconciliation, related validation, and documentation.
  • Rollback: revert this PR to remove the placeholder migrations and related validation/docs changes.
  • Provider or production effects: none
  • Data or schema impact: no new durable schema change; placeholder migrations are intentional no-ops only

Clinical Governance Preflight

  • This change does not alter clinical answer generation, clinical decision-support behavior, or source-ranking logic.
  • This change does not alter citation requirements, source verification, provenance, or clinical-content governance.
  • This change does not alter privacy controls, patient-data handling, authentication, authorization, or document-access behavior.
  • Any Supabase service-role credentials used by migration-history diagnostics remain CI/server-side only and are not exposed to clients.
  • This change does not alter the configured Supabase project/target or perform a production database migration.
  • The added historical migration files are intentional no-op placeholders (select 1;) used only to reconcile Preview migration history; the durable schema/ACL changes already exist in their replacement migrations.
  • No SaMD/TGA assessment is required because this change has no clinical decision-support impact.

Notes

  • This PR fixes Supabase Preview failures caused by orphaned historical migration versions present remotely but missing from the local migration set.
  • The placeholder migration files are intentionally retained to preserve migration-history continuity for Preview environments.

Hosted Preview fails when schema_migrations still records versions that
were renamed or renumbered away locally. Add no-op historical placeholders
for those orphan versions, plus an offline guard and live history check.

Co-authored-by: BigSimmo <BigSimmo@users.noreply.github.com>
@supabase

supabase Bot commented Jul 20, 2026

Copy link
Copy Markdown

Updates to Preview Branch (cursor/supabase-preview-migration-drift-7850) ↗︎

Deployments Status Updated
Database Mon, 20 Jul 2026 08:50:40 UTC
Services Mon, 20 Jul 2026 08:50:40 UTC
APIs Mon, 20 Jul 2026 08:50:40 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 Mon, 20 Jul 2026 08:50:42 UTC
Migrations Mon, 20 Jul 2026 08:50:44 UTC
Seeding Mon, 20 Jul 2026 08:50:45 UTC
Edge Functions Mon, 20 Jul 2026 08:50:46 UTC

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

@coderabbitai

coderabbitai Bot commented Jul 20, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

Adds a Supabase migration-history alignment check, historical no-op placeholders, validation, live-drift integration, and reconciliation guidance. Separately, PR policy parsing now combines duplicate Markdown sections and recognizes canonical and legacy governance checklist evidence.

Changes

Migration history alignment

Layer / File(s) Summary
Migration history comparison
scripts/check-migration-history-alignment.ts
Discovers local migration versions, fetches remote schema_migrations versions, reports differences, and fails when remote versions are missing locally.
Historical placeholders and validation
supabase/migrations/*_historical_version_placeholder.sql, tests/migration-history-placeholders.test.ts, tests/supabase-schema.test.ts
Adds six no-op historical migrations, verifies known orphan versions, and allowlists their repeated migration stem.
Workflow integration and guidance
package.json, .github/workflows/live-drift.yml, docs/supabase-migration-reconciliation.md
Exposes the alignment command, runs it in live drift checks, and documents reconciliation procedures.

PR policy section parsing

Layer / File(s) Summary
Governance evidence collection
scripts/pr-policy.mjs, .github/workflows/ci.yml
Combines duplicate Markdown sections, recognizes canonical and legacy governance evidence, updates policy synchronization, and expands self-tests.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Sequence Diagram(s)

sequenceDiagram
  participant live_drift_job
  participant check_migration_history
  participant local_migrations
  participant Supabase_REST_Data_API
  live_drift_job->>check_migration_history: run alignment check
  check_migration_history->>local_migrations: read local version prefixes
  check_migration_history->>Supabase_REST_Data_API: fetch schema_migrations versions
  Supabase_REST_Data_API-->>check_migration_history: return remote versions
  check_migration_history-->>live_drift_job: report alignment or fail on remote-only versions
Loading

Possibly related PRs

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Title check ✅ Passed The title is concise and accurately describes the main change: restoring orphan migration versions for Supabase Preview.
Description check ✅ Passed The description follows the template well and covers summary, verification, risk/rollback, clinical governance, and notes.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch cursor/supabase-preview-migration-drift-7850

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

@github-actions

github-actions Bot commented Jul 20, 2026

Copy link
Copy Markdown

CI triage

CI failed on this PR. Automated classification of the 2 failed job(s):

  • Static PR checksneeds investigation: inspect the failing step and uploaded diagnostics; rerun only after classifying the cause.
  • PR requiredneeds investigation: inspect the failing step and uploaded diagnostics; rerun only after classifying the cause.

Compared with main CI run #3919 (cancelled).

Classification is evidence routing, not permission to ignore a failure. Exact quarantined Playwright identities remain governed by the flake ledger.

Unit coverage rejected the six no-op preview-alignment placeholders
because duplicate stems must be explicitly allowlisted.

Co-authored-by: BigSimmo <BigSimmo@users.noreply.github.com>
@cursor
cursor Bot marked this pull request as ready for review July 20, 2026 04:59
…ew-migration-drift-7850

Co-authored-by: BigSimmo <BigSimmo@users.noreply.github.com>
@cursor
cursor Bot enabled auto-merge (squash) July 20, 2026 04:59
@BigSimmo

Copy link
Copy Markdown
Owner Author

@cursoragent please resolve the failing CI policy check

@cursor

cursor Bot commented Jul 20, 2026

Copy link
Copy Markdown

You need to increase your spend limit or enable usage-based billing to run background agents. Go to Cursor

@BigSimmo

Copy link
Copy Markdown
Owner Author

@code rabbit please resolve the failing CI policy check

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@scripts/check-migration-history-alignment.ts`:
- Around line 33-54: Update fetchRemoteVersions to fail closed when the
schema_migrations request is unsuccessful: add a bounded timeout to the fetch
operation, and throw an error containing the HTTP status and bounded response
text instead of warning and returning null. Preserve the successful RemoteRow[]
response path so the check either compares history or clearly fails.
🪄 Autofix (Beta)

✅ Autofix completed


ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: ff331208-94dc-43ad-8f0d-399fbea8f850

📥 Commits

Reviewing files that changed from the base of the PR and between 2296c45 and e787e5b.

📒 Files selected for processing (12)
  • .github/workflows/live-drift.yml
  • docs/supabase-migration-reconciliation.md
  • package.json
  • scripts/check-migration-history-alignment.ts
  • supabase/migrations/20260713110000_historical_version_placeholder.sql
  • supabase/migrations/20260713120000_historical_version_placeholder.sql
  • supabase/migrations/20260713121000_historical_version_placeholder.sql
  • supabase/migrations/20260713122000_historical_version_placeholder.sql
  • supabase/migrations/20260717133000_historical_version_placeholder.sql
  • supabase/migrations/20260718223000_historical_version_placeholder.sql
  • tests/migration-history-placeholders.test.ts
  • tests/supabase-schema.test.ts

Comment thread scripts/check-migration-history-alignment.ts Outdated
@coderabbitai

coderabbitai Bot commented Jul 20, 2026

Copy link
Copy Markdown
Contributor

Note

Autofix is a beta feature. Expect some limitations and changes as we gather feedback and continue to improve it.

Fixes Applied Successfully

Fixed 1 file(s) based on 1 unresolved review comment.

Files modified:

  • scripts/check-migration-history-alignment.ts

Commit: 10ebcfecdbdcd4f5092784be8ee41df2dccfc873

The changes have been pushed to the cursor/supabase-preview-migration-drift-7850 branch.

Time taken: 2m 24s

@BigSimmo

Copy link
Copy Markdown
Owner Author

@coderabbitai please resolve failing CI policy test

@coderabbitai

coderabbitai Bot commented Jul 20, 2026

Copy link
Copy Markdown
Contributor

CI fix PR created: #974

Follow #974 for fix progress and CI status. If CI still fails, re-run the fix-ci command to try again.

Note: Fixing CI failures is a beta feature and may encounter errors. Expect some limitations and changes as we gather feedback and continue to improve it.

Note: If your CI is configured to only run on PRs targeting specific branches (e.g., main), it may not trigger on the fix PR. You can merge the fix into your branch and CI will validate on the original PR.

6 failing check(s)
  • GitHub Actions: CI / PR required
  • GitHub Actions: CI / 1_PR required.txt
  • GitHub Actions: CI / Static PR checks
  • GitHub Actions: CI / 3_Static PR checks.txt
  • GitHub Actions: CI / Migration replay
  • GitHub Actions: CI / 6_Migration replay.txt
1 file(s) modified
  • scripts/pr-policy.mjs
View agent analysis
Prettier reformatted the file. This is a purely formatting fix (no semantic change), which resolves the format:check failure. Let me verify the diff is only whitespace/formatting, not semantic.

Now let's look at the migration files and history alignment check, since those relate to "Migration replay" and "pr-required" job failures.

Good, PR `#952`. Let me get the actual failed run logs via gh api for the real error messages.

This confirms current run (29728913523) for "CI" is still in progress. Let's get the exact failure logs for the "Static PR checks" job (id 88308485094), which is confirmed as the real failing job.

All other files pass prettier (SQL files aren't covered by prettier config, expected — not part of `prettier --check .`). The only formatting issue was `scripts/pr-policy.mjs`, now fixed.

This is a pure formatting fix (line-wrapping over the 100-char print width), no semantic change — exactly what `format:check` requires.

**Summary of fix:**

The only genuine CI failure (confirmed via live GitHub Actions check-run data for the PR) was `npm run format:check` failing on `scripts/pr-policy.mjs` — Prettier flagged two array-literal lines that exceeded the configured print width. I ran `prettier --write` on that single file to reformat those two lines (pure whitespace/line-wrap changes, no logic changes).

This resolves the "Static PR checks" job, which was blocking the "PR required" gate (both listed as failing checks). The "Migration replay" job was still `in_progress` on the live run at the time of investigation (not actually failed) — I statically reviewed the new placeholder migration SQL files, the updated `check-migration-history-alignment.ts` script, and the `supabase-schema.test.ts` duplicate-stem allowlist, and found no syntax or structural issues that would cause a replay failure; the six new `select 1;` no-op placeholder files are syntactically valid and don't collide with any existing migration version numbers.

Fixed 1 file(s) based on 1 unresolved review comment.

Co-authored-by: CodeRabbit <noreply@coderabbit.ai>
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
@BigSimmo

Copy link
Copy Markdown
Owner Author

@coderabbitai please can you resolve the branch conflicts for me

@coderabbitai

coderabbitai Bot commented Jul 20, 2026

Copy link
Copy Markdown
Contributor

Merge conflicts resolved successfully!

Resolved 1 conflict file(s). Commit: 8db411e2b3e12bb465f8b5a733ce48256c3fb6c3 pushed to cursor/supabase-preview-migration-drift-7850.

14 file operation(s)
  • .github/workflows/ci.yml (update)
  • .github/workflows/live-drift.yml (update)
  • docs/supabase-migration-reconciliation.md (update)
  • package.json (update)
  • scripts/check-migration-history-alignment.ts (update)
  • scripts/pr-policy.mjs (update)
  • supabase/migrations/20260713110000_historical_version_placeholder.sql (update)
  • supabase/migrations/20260713120000_historical_version_placeholder.sql (update)
  • supabase/migrations/20260713121000_historical_version_placeholder.sql (update)
  • supabase/migrations/20260713122000_historical_version_placeholder.sql (update)
  • supabase/migrations/20260717133000_historical_version_placeholder.sql (update)
  • supabase/migrations/20260718223000_historical_version_placeholder.sql (update)
  • tests/migration-history-placeholders.test.ts (update)
  • tests/supabase-schema.test.ts (update)
View agent analysis

Resolved conflicts in:
- PR_POLICY_BODY.md (delete-modify)

Co-authored-by: CodeRabbit <noreply@coderabbit.ai>
@BigSimmo

Copy link
Copy Markdown
Owner Author

@claude Please can you resolve the failing PR policy CI for me

@BigSimmo

Copy link
Copy Markdown
Owner Author

@coderabbitai please generate a copy and paste message to update and enable this to pass PR policy CI

@coderabbitai

coderabbitai Bot commented Jul 20, 2026

Copy link
Copy Markdown
Contributor

Tip

For best results, initiate chat on the files or code changes.

@BigSimmo, paste the following into the PR description (or replace the <!-- GOVERNANCE_PREFLIGHT --> marker in PR_POLICY_BODY.md), then re-run the PR Policy workflow:

## Clinical Governance Preflight

- [x] This change does not alter clinical answer generation, clinical decision-support behavior, or source-ranking logic.
- [x] This change does not alter citation requirements, source verification, provenance, or clinical-content governance.
- [x] This change does not alter privacy controls, patient-data handling, authentication, authorization, or document-access behavior.
- [x] Any Supabase service-role credentials used by the migration-history diagnostic remain CI/server-side only and are not exposed to clients.
- [x] This change does not alter the configured Supabase project/target or perform a production database migration.
- [x] The added historical migration files are intentional no-op placeholders (`select 1;`) used only to reconcile Preview migration history; the durable schema/ACL changes already exist in their replacement migrations.
- [x] No SaMD/TGA assessment is required because this change has no clinical decision-support impact.

This addresses the failure mode where the unfilled governance marker was expanded into unchecked policy items.

@BigSimmo

Copy link
Copy Markdown
Owner Author

@coderabbitai please generate a copy and paste message to update and enable this to pass PR policy CI

@coderabbitai

coderabbitai Bot commented Jul 20, 2026

Copy link
Copy Markdown
Contributor

Tip

For best results, initiate chat on the files or code changes.

@BigSimmo, replace the <!-- GOVERNANCE_PREFLIGHT --> marker in PR_POLICY_BODY.md (or paste this into the PR description) and rerun the PR Policy workflow:

## Clinical Governance Preflight

- [x] This change does not alter clinical answer generation, clinical decision-support behavior, or source-ranking logic.
- [x] This change does not alter citation requirements, source verification, provenance, or clinical-content governance.
- [x] This change does not alter privacy controls, patient-data handling, authentication, authorization, or document-access behavior.
- [x] Any Supabase service-role credentials used by the migration-history diagnostic remain CI/server-side only and are not exposed to clients.
- [x] This change does not alter the configured Supabase project/target or perform a production database migration.
- [x] The added historical migration files are intentional no-op placeholders (`select 1;`) used only to reconcile Preview migration history; the durable schema/ACL changes already exist in their replacement migrations.
- [x] No SaMD/TGA assessment is required because this change has no clinical decision-support impact.

This replaces the unfilled marker that was being expanded into unchecked governance items, which caused the PR Policy checks to fail.

@BigSimmo
BigSimmo enabled auto-merge (squash) July 20, 2026 07:41
auto-merge was automatically disabled July 20, 2026 07:57

Head branch was pushed to by a user without write access

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In @.github/workflows/ci.yml:
- Around line 95-102: Update the governance sync logic around
collectSatisfiedGovernanceItems to extract the Clinical Governance Preflight
content with the duplicate-aware section(existingBody, "Clinical Governance
Preflight") helper instead of the first-match govMatch regex. Export that helper
if necessary, then pass the combined section content to
collectSatisfiedGovernanceItems so evidence from every duplicate section is
preserved.
🪄 Autofix (Beta)

❌ Autofix failed (check again to retry)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: b43004af-53bc-43c8-bf90-8944c192b012

📥 Commits

Reviewing files that changed from the base of the PR and between 2811dc2 and 8c9def0.

📒 Files selected for processing (2)
  • .github/workflows/ci.yml
  • scripts/pr-policy.mjs

Comment thread .github/workflows/ci.yml Outdated
@BigSimmo

Copy link
Copy Markdown
Owner Author

@coderabbitai please resolve the merge conflicts for me

@coderabbitai

coderabbitai Bot commented Jul 20, 2026

Copy link
Copy Markdown
Contributor

Note

Autofix is a beta feature. Expect some limitations and changes as we gather feedback and continue to improve it.

Autofix skipped. No unresolved CodeRabbit review comments with fix instructions found.

coderabbitai Bot and others added 2 commits July 20, 2026 08:12
Resolved conflicts in:
- scripts/pr-policy.mjs (content)

Co-authored-by: CodeRabbit <noreply@coderabbit.ai>
@BigSimmo
BigSimmo enabled auto-merge (squash) July 20, 2026 08:13
@BigSimmo

Copy link
Copy Markdown
Owner Author

@cursoragent Please can you resolve this

CI / Static PR checks (pull_request)Failing after 58s

@cursor

cursor Bot commented Jul 20, 2026

Copy link
Copy Markdown

You need to increase your spend limit or enable usage-based billing to run background agents. Go to Cursor

@BigSimmo

Copy link
Copy Markdown
Owner Author

@claude Please resolve the failing CI testing here

@BigSimmo

Copy link
Copy Markdown
Owner Author

@coderabbitai please ensure that all CI testing is passing

coderabbitai Bot and others added 2 commits July 20, 2026 16:49
…ation replay (#974)

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
@BigSimmo
BigSimmo merged commit 306ca49 into main Jul 20, 2026
18 checks passed
@BigSimmo
BigSimmo deleted the cursor/supabase-preview-migration-drift-7850 branch July 20, 2026 08:53
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.

3 participants