Skip to content

fix(ci): auto-resync preview branch DB on migration/seed push + reset on reuse#1553

Merged
timothyfroehlich merged 2 commits into
mainfrom
fix/preview-auto-resync-on-push
Jun 17, 2026
Merged

fix(ci): auto-resync preview branch DB on migration/seed push + reset on reuse#1553
timothyfroehlich merged 2 commits into
mainfrom
fix/preview-auto-resync-on-push

Conversation

@timothyfroehlich

Copy link
Copy Markdown
Owner

Problem

Previews could serve stale schema and seed data. Surfaced on #1388 (Machine Settings PR): a pushed migration looked "not applied" and changed seed data wasn't reflected.

Two root causes, both confirmed in the #1388 run logs:

  1. /preview reused a live Supabase branch without resetting it. drizzle-kit migrate is journaled (skips already-applied migrations, so a regenerated migration never re-applies) and the seed scripts are skip-if-exists (⏭️ admin@test.com already exists). So re-running /preview on a still-living branch was a near no-op for changed migrations/seed.
  2. Pushes never re-ran migrate/seed at all. preview-control.yaml is issue_comment-only — only a manual /preview comment ran the DB setup. Every later push triggered Vercel's own build (new code) against the old branch DB.

It's structural, not #1388-specific: any PR that re-runs /preview on a live branch, or pushes a migration without re-commenting, hits it.

Fix

  • preview-sync.yaml (new): on pull_request synchronize, path-filtered to drizzle/** + supabase/seed*, re-sync an already-active preview branch. Exits 0 when no pr-<N> branch exists → preserves the zero-cost "no preview by default" model. Shares preview-control's per-PR concurrency group so a resync and a manual /preview never mutate the branch DB concurrently.
  • preview-migrate-seed.sh (new): the migrate+seed sequence extracted into one shared script used by both the /preview path and the push-resync path, so they can't drift again. PREVIEW_RESET=1 resets before migrate.
  • preview-create.sh: sets PREVIEW_RESET=1 on the reuse path, so a manual /preview restart on a live branch now applies changes too.
  • reset-preview-db.mjs: now also clears seeded auth.users (seed-users is skip-if-exists and the profile-creation trigger only fires on INSERT, so a public-schema-only reset left broken login state), plus a PROD_PROJECT_REF guard that refuses to run against the production project.

Trigger model

First /preview creates the branch + sets TTL. Subsequent migration/seed pushes auto-resync it (reset → migrate → seed). Code-only pushes leave it alone (and preserve manual test data). Reaper still tears it down on TTL/close.

Verification

Follow-up for #1388

#1388 added node supabase/seed-machine-settings.mjs inline in preview-create.sh. After this merges, that line should move into preview-migrate-seed.sh's PR-specific seed section (there's a commented example showing the file-existence-guarded pattern). The merge will conflict on that block — resolve by relocating the line.

🤖 Generated with Claude Code

… on reuse

Previews served stale schema/seed because `/preview` only ran migrate+seed at
comment time and reused a live Supabase branch without resetting it. drizzle
migrate skips already-journaled migrations and the seed scripts skip existing
rows, so a regenerated migration looked "not applied" and changed seed data
never updated (PR #1388). Later pushes never re-ran migrate/seed at all.

- Add preview-sync.yaml: on `pull_request` synchronize, path-filtered to
  drizzle/** + supabase/seed*, re-sync an already-active branch. Exits 0 when no
  `pr-<N>` branch exists, preserving the zero-cost "no preview by default" model.
- Extract the migrate+seed sequence into the shared preview-migrate-seed.sh so
  the `/preview` and push-resync paths can never drift; PREVIEW_RESET=1 resets
  before migrate when reusing a live branch.
- preview-create.sh resets on the reuse path (manual restart now applies changes).
- reset-preview-db.mjs also clears seeded auth.users (seed-users is skip-if-exists
  and the profile trigger only fires on INSERT, so a public-schema-only reset left
  broken login state) + a PROD_PROJECT_REF safety guard.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings June 16, 2026 15:32
@vercel

vercel Bot commented Jun 16, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
pin-point Ready Ready Preview, Comment Jun 17, 2026 3:06am

Request Review

Copilot AI 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.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@timothyfroehlich timothyfroehlich merged commit 3404a21 into main Jun 17, 2026
21 checks passed
@timothyfroehlich timothyfroehlich deleted the fix/preview-auto-resync-on-push branch June 17, 2026 03:26
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